0

I have this program which uses the guessGame example, in the testnet, which gets stuck at "Waiting for script to have a UTxO of at least 1 lovelace" when executing "guess":

   main=  do
      handlers <- testnetHandlers
      let walletid= fromJust $ decode $ "\"17abbab9d64a5e1f8b267da9eda630d5de9c969c\""
      Core.runPAB def handlers $ do
           liftIO  getChar
    
           cid  <- activateContract (Wallet walletid) Lock
           liftIO $ print ("ACTIVATED",cid)
           r <- callEndpointOnInstance'  cid "lock" LockParams{secretWord="42", amount= Ada.adaValueOf $ fromIntegral 10} -- ,lockIndex=0}
           liftIO $ print ("RRRR=",r) 
           liftIO getChar
           cid  <-  activateContract  (Wallet walletid)   Guess
           callEndpointOnInstance  cid "guess" GuessParams{guessWord="42"}
    
      liftIO getChar

testnetHandlers :: MonadIO m => m (EffectHandlers (Builtin GuessGameContracts) (AppEnv GuessGameContracts))
testnetHandlers= liftIO $ do
    config' <- decodeFileThrow "pab-config.yml"
    let config= config' { nodeServerConfig   = (nodeServerConfig  config') { mscPassphrase = Just "pab123456789"}}
    def <-  defaultConfig
    (trace , switchboard) <- setupTrace_ def "pab"

    let ccaTrace = convertLog PrettyObject trace

    return $ appEffectHandlers BeamSqliteBackend config (toPABMsg ccaTrace) handleBuiltin
    where
    toPABMsg = LM.convertLog LM.PABMsg

lock and guess, from the classical example, taken from the plutus examples:

lock :: AsContractError e => Promise () GameSchema e ()
lock = endpoint @"lock" @LockParams $ \(LockParams secret amt) -> do
    logInfo @Haskell.String $ "Pay " <> Haskell.show amt <> " to the script"
    let tx         = Constraints.mustPayToTheScript (hashString secret) amt
    logInfo @Haskell.String "SUBMITTING"
    ledgerTx <- submitTxConstraints gameInstance tx
    logInfo @Haskell.String $ "TRANSACTION=" <>  Haskell.show ledgerTx
    void $ awaitTxConfirmed $ getCardanoTxId ledgerTx
    logInfo @Haskell.String $ "Paid " 

-- | The "guess" contract endpoint. See note [Contract endpoints]
guess :: AsContractError e => Promise () GameSchema e ()
guess = endpoint @"guess" @GuessParams $ \(GuessParams theGuess) -> do
    -- Wait for script to have a UTxO of a least 1 lovelace
    logInfo @Haskell.String "Waiting for script to have a UTxO of at least 1 lovelace"
    utxos <- fundsAtAddressGeq gameAddress (Ada.lovelaceValueOf 1)
    logInfo @Haskell.String "MORE THAN 1 lOVELACE"

    let redeemer = clearString theGuess
        tx       = collectFromScript utxos redeemer

    -- Log a message saying if the secret word was correctly guessed
    let hashedSecretWord = findSecretWordValue utxos
        isCorrectSecretWord = fmap (`isGoodGuess` redeemer) hashedSecretWord == Just True
    if isCorrectSecretWord
        then logWarn @Haskell.String "Correct secret word! Submitting the transaction"
        else logWarn @Haskell.String "Incorrect secret word, but still submiting the transaction"

    -- This is only for test purposes to have a possible failing transaction.
    -- In a real use-case, we would not submit the transaction if the guess is
    -- wrong.
    logInfo @Haskell.String "Submitting transaction to guess the secret word"
    void (submitTxConstraintsSpending gameInstance utxos tx)

I take care to deploy the cardano node, the cardano wallet and the chain index following the README and wait for the synchronization of all of them.

The execution log after synchronization:

[pab:Info:1] [2022-06-14 16:22:21.61 UTC] Initialising contract Lock with ID c6cf990e-60d5-4ab2-94f5-0a75488802d4
("ACTIVATED",ContractInstanceId {unContractInstanceId = c6cf990e-60d5-4ab2-94f5-0a75488802d4})
("RRRR=",Nothing)
[pab:Info:1] [2022-06-14 16:22:21.72 UTC] Activated instance c6cf990e-60d5-4ab2-94f5-0a75488802d4 on W17abbab
WALLET EFFECT
[pab:Info:437] [2022-06-14 16:22:21.74 UTC] c6cf990e-60d5-4ab2-94f5-0a75488802d4: "Pay Value (Map [(,Map [(\"\",10000000)])]) to the script"
[pab:Info:437] [2022-06-14 16:22:21.74 UTC] c6cf990e-60d5-4ab2-94f5-0a75488802d4: "SUBMITTING"
Current block: 122. Current slot: 60854525
[pab:Info:437] [2022-06-14 16:22:22.15 UTC] c6cf990e-60d5-4ab2-94f5-0a75488802d4: "TRANSACTION=Left (SomeTx (ShelleyTx ShelleyBasedEraAlonzo (ValidatedTx {body = TxBodyConstr TxBodyRaw {_inputs = fromList [TxIn (TxId {_unTxId = SafeHash \"c88ab928f018531bdbd4e9886c53a8ba3986ca1ba6d71417fe0587b224db684b\"}) 1], _collateral = fromList [], _outputs = StrictSeq {fromStrict = fromList [(Addr Testnet (ScriptHashObj (ScriptHash \"4049d3f75593d7e36c04850190de091b9991bdcb9a02c7d9dc179d18\")) StakeRefNull,Value 10000000 (fromList []),SJust (SafeHash \"8892969abcbfc6b2817ea5a4e7caa145250c0763f9fbc62a390d77250b8e052c\")),(Addr Testnet (KeyHashObj (KeyHash \"1b15d711002d503c10033a973f6d12d175ba189de3858ad349bbd743\")) (StakeRefBase (KeyHashObj (KeyHash \"f6a72252b983302efc04f18a027c8b8f3ab0bb66a25d9025c38b4004\"))),Value 123153964 (fromList []),SNothing)]}, _certs = StrictSeq {fromStrict = fromList []}, _wdrls = Wdrl {unWdrl = fromList []}, _txfee = Coin 171397, _vldt = ValidityInterval {invalidBefore = SNothing, invalidHereafter = SNothing}, _update = SNothing, _reqSignerHashes = fromList [], _mint = Value 0 (fromList []), _scriptIntegrityHash = SJust (SafeHash \"9f362284f78523c6369a621a8f7d0f7a0a2f4772a2aa19529d98b08e7de678f6\"), _adHash = SNothing, _txnetworkid = SNothing}, wits = TxWitnessRaw {_txwitsVKey = fromList [WitVKey' {wvkKey' = VKey (VerKeyEd25519DSIGN \"51acbacf352c47c5967a9abadf9dc358c74266c8661786f1618327364034f100\"), wvkSig' = SignedDSIGN (SigEd25519DSIGN \"caa571cc2ff486114dab6babb17c3df4b93d34d52c6b20a9b8ea8f78080337e994ec38d01b0942d4903be22696d41b8f2e720835e7b08f074602807c36643a03\"), wvkKeyHash = KeyHash \"5fe846b9af92c98e933a16e19ba809b052ebb3394af95fc499d4f936\", wvkBytes = \"\\130X Q\\172\\186\\207\\&5,G\\197\\150z\\154\\186\\223\\157\\195X\\199Bf\\200f\\ETB\\134\\241a\\131'6@4\\241\\NULX@\\202\\165q\\204/\\244\\134\\DC1M\\171k\\171\\177|=\\244\\185=4\\213,k \\169\\184\\234\\143x\\b\\ETX7\\233\\148\\236\\&8\\208\\ESC\\tB\\212\\144;\\226&\\150\\212\\ESC\\143.r\\b5\\231\\176\\143\\aF\\STX\\128|6d:\\ETX\"}], _txwitsBoot = fromList [], _txscripts = fromList [], _txdats = TxDatsRaw (fromList [(SafeHash \"8892969abcbfc6b2817ea5a4e7caa145250c0763f9fbc62a390d77250b8e052c\",DataConstr B \"sG\\\\\\180\\nV\\142\\141\\168\\160E\\206\\209\\DLE\\DC3~\\NAK\\159\\137\\n\\196\\218\\136;k\\ETB\\220e\\ESC:\\128I\")]), _txrdmrs = RedeemersRaw (fromList [])}, isValid = IsValid True, auxiliaryData = SNothing})) AlonzoEraInCardanoMode)"
Current block: 123. Current slot: 60854571
[pab:Info:437] [2022-06-14 16:23:07.36 UTC] c6cf990e-60d5-4ab2-94f5-0a75488802d4: "Paid "

[pab:Info:1] [2022-06-14 16:23:22.78 UTC] Initialising contract Guess with ID ff4ff5e3-2381-42a3-a3b3-04d47640dedc
[pab:Info:1] [2022-06-14 16:23:22.79 UTC] Activated instance ff4ff5e3-2381-42a3-a3b3-04d47640dedc on W17abbab
[pab:Info:943] [2022-06-14 16:23:22.79 UTC] ff4ff5e3-2381-42a3-a3b3-04d47640dedc: "Waiting for script to have a UTxO of at least 1 lovelace"
Current block: 124. Current slot: 60854605
Current block: 125. Current slot: 60854620
Current block: 126. Current slot: 60854777
Current block: 127. Current slot: 60854845
Current block: 128. Current slot: 60854868
1
  • Shouldn‘t you lock funds before guessing ? In main you activate the contract and then immediately guess.
    – Jey
    Jun 30 at 10:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.