I was reviewing the code from https://github.com/input-output-hk/plutus-pioneer-program/blob/main/code/week05/src/Week05/NFT.hs and I don't understand why this section does not cause a compile error.
utxos <- utxosAt $ npAddress np
case Map.keys utxos of
[] -> Contract.logError @String "no utxo found"
oref : _ -> do
utxosAt :: forall w s e. AsContractError e => Address -> Contract w s e (Map TxOutRef ChainIndexTxOut)
keys :: Map k v -> [k]
My expectation is that the variable utxos has type Contract w s e (Map TxOutRef ChainIndexTxOut). This should cause an error on Map.keys utxos
, but it doesn't.
Edit: My code:
getNFT :: Wallet -> Value
getNFT w = do
utxos <- utxosAt $ mockWalletAddress w
case getValue utxos of
Just v -> v
Nothing -> Ada.lovelaceValueOf 1000000
The type of getValue is getValue :: Map.Map TxOutRef ChainIndexTxOut -> Maybe Value
The errors I am getting are:
error:
• Couldn't match expected type ‘Value’
with actual type ‘Contract w0 s0 e0 b0’
• In a stmt of a 'do' block: utxos <- utxosAt $ mockWalletAddress w
In the expression:
do utxos <- utxosAt $ mockWalletAddress w
case getValue utxos of
Just v -> v
Nothing -> lovelaceValueOf 1000000
In an equation for ‘getNFT’:
getNFT w
= do utxos <- utxosAt $ mockWalletAddress w
case getValue utxos of
Just v -> v
Nothing -> lovelaceValueOf 1000000
|
179 | utxos <- utxosAt $ mockWalletAddress w
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compilation Error, Line 181, Column 27 (jump)
error:
• Couldn't match expected type ‘Contract w0 s0 e0 b0’
with actual type ‘Value’
• In the expression: v
In a case alternative: Just v -> v
In a stmt of a 'do' block:
case getValue utxos of
Just v -> v
Nothing -> lovelaceValueOf 1000000
|
181 | Just v -> v
| ^
Compilation Error, Line 182, Column 28 (jump)
error:
• Couldn't match expected type ‘Contract w0 s0 e0 b0’
with actual type ‘Value’
• In the expression: lovelaceValueOf 1000000
In a case alternative: Nothing -> lovelaceValueOf 1000000
In a stmt of a 'do' block:
case getValue utxos of
Just v -> v
Nothing -> lovelaceValueOf 1000000
|
182 | Nothing -> Ada.lovelaceValueOf 1000000
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^