No instance for (Action Commands) arising from a do statement
- Neelam_DwivediOP 1
The code copied from https://docs.daml.com/daml/intro/3_Data.html under the section titled Contract Keys throws this compilation error at the statement:
archiveCmd accountCid
Here is the full code:
module Main where
import Daml.Script
import DA.Assert (assertEq)data Bank = Bank with
party : Party
address: Text
telephone : Text
deriving (Eq, Show)template Account
with
accountant : Party
owner : Party
number : Text
bank : Bank
where
signatory accountantdata Cash = Cash with
currency : Text
amount : Decimal
deriving (Eq, Show)template CashBalance
with
accountant : Party
cash : Cash
account : ContractId Account
where
signatory accountantsetup: Script()
setup = script do
accountant ← allocateParty “Bob”
owner ← allocateParty “Alice”
bank_party ← allocateParty “Bank”
let
bank = Bank with
party = bank_party
address = “High Street”
telephone = “012 3456 789”
cash = Cash with
currency = “USD”
amount = 100.0accountCid <- submit accountant do createCmd Account with accountant owner bank number = "ABC123" balanceCid <- submit accountant do createCmd CashBalance with accountant cash account = accountCid -- Now the accountant updates the telephone number for the bank on the account Some account <- queryContractId accountant accountCid new_account <- submit accountant do archiveCmd accountCid createCmd account with bank = account.bank with telephone = "098 7654 321" pure () -- The `account` field on the balance now refers to the archived -- contract, so this will fail. Some balance <- queryContractId accountant balanceCid optAccount <- queryContractId accountant balance.account assertEq optAccount None
I made just one little change at the end where I replaced
optAccount === None
with
assertEq optAccount None
Here is the complete error message:
No instance for (Action Commands) arising from a do statement
• In a stmt of a ‘do’ block: archiveCmd accountCid
In the second argument of ‘submit’, namely
‘do archiveCmd accountCid
createCmd
(setField
@“bank”
((setField
@“telephone” (“098 7654 321”) (getField @“bank” account)))
account)
pure ()’
In a stmt of a ‘do’ block:Will really appreciate some hints in what could I be doing wrong!
- Gary_Verhaegen 1
One little change compared to what? Where does the code come from? It’s pretty hard to read as it stands, would you mind reposting it in-between triple quotes?
- cocreature
Hi @Neelam_Dwivedi, this happens if you do not enable
ApplicativeDo. To fix it, add the following to the very top of your file (abovemodule).{-# LANGUAGE ApplicativeDo #-}You can find more info on this in the daml script documentation.
- Neelam_Dwivedi 1
cocreature:{-# LANGUAGE ApplicativeDo #-}Sorry about that @Gary_Verhaegen! Re-pasted the code I copied from Docs.
data Bank = Bank with party : Party address: Text telephone : Text deriving (Eq, Show) template Account with accountant : Party owner : Party number : Text bank : Bank where signatory accountant data Cash = Cash with currency : Text amount : Decimal deriving (Eq, Show) template CashBalance with accountant : Party cash : Cash account : ContractId Account where signatory accountant id_ref_test = do accountant <- allocateParty "Bob" owner <- allocateParty "Alice" bank_party <- allocateParty "Bank" let bank = Bank with party = bank_party address = "High Street" telephone = "012 3456 789" cash = Cash with currency = "USD" amount = 100.0 accountCid <- submit accountant do createCmd Account with accountant owner bank number = "ABC123" balanceCid <- submit accountant do createCmd CashBalance with accountant cash account = accountCid -- Now the accountant updates the telephone number for the bank on the account Some account <- queryContractId accountant accountCid new_account <- submit accountant do archiveCmd accountCid createCmd account with bank = account.bank with telephone = "098 7654 321" pure () -- The `account` field on the balance now refers to the archived -- contract, so this will fail. Some balance <- queryContractId accountant balanceCid optAccount <- queryContractId accountant balance.account optAccount === None - Neelam_Dwivedi
Thanks @cocreature !! This works!