Main.daml:14:13: error: parse error on input ‘ReleaseItemTo’

module Main where
import Daml.Script
type ItemCustodyId = ContractId ItemCustody

template ItemCustody
with
owner: Party
custodian: Party
itemName: Text
where
signatory owner

    controller owner 
        ReleaseItemTo: ItemCustodyId
            with
                friend: Party
            do
                create this with custodian = friend

    controller custodian 
        ReturnItemTo: ItemCustodyId
            with
                rightfulOwner: Party
            do 
                create this with custodian = rightfulOwner

– test

setup : Script ItemCustodyId

setup = script do

jerry <- allocateParty "Jerry"
elaine <- allocateParty "Elaine"

brandNewCamera <- submit jerry do
    createCmd ItemCustody with
        owner = jerry
        custodian = jerry
        itemName = "Really Expensive Camera"

elaineHasCamera <- submit jerry do
    exerciseCmd brandNewCamera ReleaseItemTo with friend = elaine

submit elaine do
    exerciseCmd elaineHasCamera ReturnItemTo with rightfulOwner = jerry

It looks like you ended up with a half-way syntax between the controller … can syntax which is deprecated and the choice syntax.

For controller … can you need to switch to the following

controller owner can
        ReleaseItemTo: ItemCustodyId
            with
                friend: Party
            do
                create this with custodian = friend

    controller custodian can
        ReturnItemTo: ItemCustodyId
            with
                rightfulOwner: Party
            do 
                create this with custodian = rightfulOwner

However, this syntax is deprecated since SDK 2.0 and you will get a warning if you use this.

To switch to the recommended syntax you need to add custodian as an observer explicitly and switch around the choice header:

template ItemCustody
  with
    owner: Party
    custodian: Party
    itemName: Text
  where
    signatory owner
    observer custodian

    choice ReleaseItemTo: ItemCustodyId
      with
          friend: Party
      controller owner
      do
          create this with custodian = friend

    choice ReturnItemTo: ItemCustodyId
      with
          rightfulOwner: Party
      controller custodian
      do 
          create this with custodian = rightfulOwner
1 Like