I'm a have problem unlocking the smart contracts of the homework of week 02.
The Plutus code:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TemplateHaskell #-}
module Homework1 where
import qualified Plutus.V2.Ledger.Api as PlutusV2
import PlutusTx (compile)
import qualified PlutusTx.Prelude (Bool, (&&),BuiltinData, True)
import Utilities (wrap, writeValidatorToFile, writeDataToFile)
import Prelude (IO)
---------------------------------------------------------------------------------------------------
----------------------------------- ON-CHAIN / VALIDATOR ------------------------------------------
{-# INLINABLE mkValidator #-}
-- This should validate if and only if the two Booleans in the redeemer are True!
mkValidator :: () -> (PlutusTx.Prelude.Bool, PlutusTx.Prelude.Bool) -> PlutusV2.ScriptContext -> PlutusTx.Prelude.Bool
mkValidator _ (x,y) _ = (x && y)
wrappedVal :: PlutusTx.Prelude.BuiltinData -> PlutusTx.Prelude.BuiltinData -> PlutusTx.Prelude.BuiltinData -> ()
wrappedVal = wrap mkValidator
validator :: PlutusV2.Validator
validator = PlutusV2.mkValidatorScript $$(PlutusTx.compile [|| wrappedVal ||])
saveHM :: IO ()
saveHM = writeValidatorToFile "./Homework1.plutus" validator
The cardano-cli script:
cardano-cli transaction build \
--babbage-era \
--testnet-magic 2 \
--tx-in "$txin" \
--tx-in-script-file "$assets/Homework1.plutus" \
--tx-in-inline-datum-present \
--tx-in-redeemer-file "$assets/redeemer-success.json" \
--tx-in-collateral "$collateral" \
--change-address "$(cat "$keypath/$name.addr")" \
--protocol-params-file "$pp" \
--out-file "$body"
# Sign the transaction
cardano-cli transaction sign \
--tx-body-file "$body" \
--signing-key-file "$keypath/$name.skey" \
--testnet-magic 2 \
--out-file "$tx"
# Submit the transaction
cardano-cli transaction submit \
--testnet-magic 2 \
--tx-file "$tx"
And the redeemer that I generated using the writeDataToFile function of the utilities module. Both values are the serialization of the tuple (True,True)so the smart contract should be unlocking the funds:
{"constructor":0,"fields":[{"constructor":1,"fields":[]},{"constructor":1,"fields":[]}]}
The above raises me this problem when building the transanction:
Command failed: transaction build Error: The following scripts have execution
failures:
the script for transaction input 0 (in the order of the TxIds) failed with:
The Plutus script evaluation failed: An error has occurred: User error:
The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.
Caused by: [
(builtin unConstrData)
(con data #a24b636f6e7374727563746f7200466669656c647380)
]
Script debugging logs:
Command failed: transaction submit Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (AlonzoInBabbageUtxoPredFailure (ValueNotConservedUTxO (MaryValue 0 (fromList [])) (MaryValue 4799493069 (fromList []))))),UtxowFailure (UtxoFailure (AlonzoInBabbageUtxoPredFailure (BadInputsUTxO (fromList [TxIn (TxId {_unTxId = SafeHash "18af21838e2ae7b1f078caca222b5f1c992aeb08e38ccbade289458bc97e8225"}) (TxIx 1)]))))])
Thank you for your responses in forehand!
The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'. Caused by: (unConstrData (B #1f0beb8844aa576b2b11b1671924ce8d1f5b1aa23eb2e19bb22a42b43fc75a0d)) : []
but the UTxO1f0beb8844aa576b2b11b1671924ce8d1f5b1aa23eb2e19bb22a42b43fc75a0d
is my wallet UTxO and is present in selections and collateral. any idea?