Reputation: 768
Okay am new to DAML and have extensive Java programming experience. Now, I have a question. In Java, 'Class A' has 'Class B', and like this, A can use 'state' of 'Class B'. I want to do something like this in DAML too.
If I think template as a class, 'contract id' is an instance of it, and the 'state' of the template (the things we declare in 'with') should be accessible in another template when passed in as a parameter, but I get compilation errors in the code I wrote.
One way to proceed is to send 'party' as a parameter instead of contract ID, and then try to access the party in contract, but I wanted to check if/ what is wrong with this!
Thanks in advance!
First template
daml 1.2
module RFP where
template RFP
with
requestorCEO: Party
where
signatory requestorCEO
Second template
daml 1.2
module InternalComm where
import RFP
template InternalComm
with
-- RFP is sent in as a parameter to this template.
rfpContractID: ContractId RFP
where
-- Here with this, I'm trying to say that the CEO who would be approving
-- an RFP is the signatory for internal communications too. It is the
-- below line that fails with compilation error.
signatory rfpContractID.requestorCEO
This is the actual error message I get for aforementioned problem. Any thoughts would be greatly appreciated!
No instance for (DA.Internal.Record.HasField
"requestorCEO" (ContractId RFP) a0)
Upvotes: 0
Views: 202
Reputation: 768
This is how it worked - just remove ContractId from whole of the template.
module InternalComm where
import RFP
template InternalComm
with
-- ContractId to be removed from below line, and compilation error is resolved.
-- rfpContractID: ContractId RFP
rfpContractID: RFP
where
signatory rfpContractID.requestorCEO
Upvotes: 0
Reputation: 9250
In DAML the RFP template gives you a type RFP
on which you can project out the fields (just like Java), and a type ContractId RFP
which is more like a pointer to the contract on the ledger. You can "dereference" the ContractId
to get the RFP
using the function fetch
. However, that function runs in an Update
, so can't be called from a signatory
. I suspect you need to change InternalComm
to take a RFP
without the ContractId
wrapper.
Upvotes: 1