Indentation is very important in Daml, but it’s not just the indentation here. Your definition of Agent
requires a list of Party
s called guarantors
which is missing in your snippet. The Investor
also requires a Guarantor
, which has a single Party
field, not a list. So here’s a version with correct indentation (I’ve set all the code in a single file and removed the choices for simplicity):
module Main where
template Investor with
agent: Agent
guarantor: Guarantor
investorname: Party
where
signatory investorname
observer agent.agentname, guarantor.guarantorname
key agent.agentname: Party
maintainer key
template Agent with
agentname: Party
guarantors: [Party]
where
signatory agentname
observer guarantors
key agentname: Party
maintainer key
template Guarantor with
guarantorname: Party
where
signatory guarantorname
exampleinvestor =
scenario do
hakan <- getParty "Hakan"
alice <- getParty "Alice"
fadhim <- getParty "Fadhim"
jahan <- getParty "Jahan"
submit hakan do
create Investor with
investorname = hakan
guarantor = Guarantor with guarantorname = jahan
agent = Agent with agentname = alice; guarantors = [fadhim]
return ()
Now, the indentation is correct, and I have added a return ()
at the end to get the right type for the scenario, but you’ll see this s still failing. The remaining error is that the Investor
template is declaring a non-signatory maintainer for its key. Key maintainers have to be signatories. The error message read:
Scenario execution failed on commit at Main:34:5:
0: create of Main:Investor at DA.Internal.Prelude:373:26
failed due to that some parties are maintainers but not signatories: 'Alice'
and a solution here would be to make the agent.agentname
party the signatory (and also therefore submit as Alice):
module Main where
template Investor with
agent: Agent
guarantor: Guarantor
investorname: Party
where
signatory agent.agentname
observer agent.agentname, guarantor.guarantorname
key agent.agentname: Party
maintainer key
template Agent with
agentname: Party
guarantors: [Party]
where
signatory agentname
observer guarantors
key agentname: Party
maintainer key
template Guarantor with
guarantorname: Party
where
signatory guarantorname
exampleinvestor =
scenario do
hakan <- getParty "Hakan"
alice <- getParty "Alice"
fadhim <- getParty "Fadhim"
jahan <- getParty "Jahan"
submit alice do
create Investor with
investorname = hakan
guarantor = Guarantor with guarantorname = jahan
agent = Agent with agentname = alice; guarantors = [fadhim]
return ()
As a final note, I would point you to my previous explanation of the differences between contracts, contract IDs and contract payloads. It’s obviously a bit of a preliminary code snippet here, but it seems like at least some of your templates should really just be data
declarations.