In Daml, I have setup an Agent
contract. This is its down Agent.daml
file. I then have a proposal contract (Proposal.daml
), in which I imported the Agent
module. I wanted to specify agentname
is the signatory for the proposal contract, but compiler tells me that no such party exists.
There are no parties in my Proposal
contract which is why I chose a party from another contract. I'm not sure how to solve this?
This is the agent contract
module Agent where
-- MAIN_TEMPLATE_BEGIN
template Agent with
agentname: Party
guarantors: [Party]
where
signatory agentname
observer guarantors
And this is the Proposal
contract
module Proposal where
import Agent
-- MAIN_TEMPLATE_BEGIN
template Proposal with
projectdescription: Text
unitsrequired: Int
marketingcost: Int
distributioncost: Int
additionalcost: Int
where
signatory agentname
observer guarantors
-- MAIN_TEMPLATE_END
key agentname: Party
maintainer key
The signatories of a contract need to be computable from the contract arguments. You can't reference another contract by ContractId
and get them from there. The reason is that that other contract might be archived, in which case you suddenly have a contract for which the signatories can't be read.
So your Proposal
must contain the agent that is making the proposal:
template Proposal with
agent : Party
projectdescription: Text
unitsrequired: Int
marketingcost: Int
distributioncost: Int
additionalcost: Int
where
signatory agent
...
As a little aside: Party
is not in general a human-readable string so best not to use them as "names". If you want a human-readable name, add a name : Text
field to Agent
.
Now you may wonder: How do I enforce the constraint that for every Proposal
there exists an Agent
? There's a long and informative thread on that topic on the Daml forums.