I am trying to recreate the example shown in the delegation pattern explained here[The Delegation Pattern — Daml SDK 2.2.0 documentation].
I am facing the following issue, even though Bob is making the request, daml is suggesting that Bob’s Authorisation is missing.
Script execution failed on commit at Main:93:3:
2: create of Main:TransferProposal at DA.Internal.Template.Functions:231:3
failed due to a missing authorization from 'Bob'
Ledger time: 1970-01-01T00:00:00Z
Partial transaction:
Failed exercise (unknown source):
exercises Transfer on #1:1 (Main:Coin)
with
newOwner = 'Bob'
Sub-transactions:
0
└─> 'Bob' exercises TransferCoin on #2:0 (Main:CoinPoA)
with
coinId = #1:1; newOwner = 'Bob'
children:
1
└─> 'Alice' exercises Transfer on #1:1 (Main:Coin)
with
newOwner = 'Bob'
children:
2
└─> create Main:TransferProposal
with
newOwner = 'Bob'
Committed transactions:
TX 0 1970-01-01T00:00:00Z (Main:75:16)
#0:0
│ consumed by: #1:0
│ referenced by #1:0
│ disclosed to (since): 'Alice' (0)
└─> create Main:Coin
with
owner = 'Alice'; issuer = 'Alice'; amount = 10.0000000000; delegates = ['Alice']
TX 1 1970-01-01T00:00:00Z (Main:82:25)
#1:0
│ disclosed to (since): 'Alice' (1)
└─> 'Alice' exercises Disclose on #0:0 (Main:Coin)
with
p = 'Bob'
children:
#1:1
│ disclosed to (since): 'Alice' (1), 'Bob' (1)
└─> create Main:Coin
with
owner = 'Alice';
issuer = 'Alice';
amount = 10.0000000000;
delegates = ['Bob', 'Alice']
TX 2 1970-01-01T00:00:00Z (Main:85:19)
#2:0
│ disclosed to (since): 'Alice' (2), 'Bob' (2)
└─> create Main:CoinPoA
with
attorney = 'Bob'; principal = 'Alice'
Here is the code, most code is from the document, i have just created some dummy templates to fill the gaps
module Main where
import Daml.Script
template Coin
with
owner: Party
issuer: Party
amount: Decimal
delegates : [Party]
where
signatory issuer, owner
observer delegates
choice Disclose : ContractId Coin
with p : Party
controller owner
do create this with delegates = p :: delegates
choice Transfer : ContractId TransferProposal
with
newOwner :Party
controller owner
do create TransferProposal with..
template TransferProposal
with
newOwner : Party
where
signatory newOwner
template CoinPoA
with
attorney: Party
principal: Party
where
signatory principal
observer attorney
choice WithdrawPoA
: ()
controller principal
do return ()
nonconsuming choice TransferCoin
: ContractId TransferProposal
with
coinId: ContractId Coin
newOwner: Party
controller attorney
do
exercise coinId Transfer with newOwner
setup : Script()
setup = script do
-- user_setup_begin
alice <- allocatePartyWithHint "Alice" (PartyIdHint "Alice")
bob <- allocatePartyWithHint "Bob" (PartyIdHint "Bob")
aliceId <- validateUserId "alice"
bobId <- validateUserId "bob"
createUser (User aliceId (Some alice)) [CanActAs alice]
createUser (User bobId (Some bob)) [CanActAs bob]
-- user_setup_end
aliceCoin <- submit alice do
createCmd Coin with
issuer = alice
owner = alice
amount = 10.0
delegates =[alice]
aliceCoinDisclosed <- submit alice do
exerciseCmd aliceCoin Disclose with p = bob
aliceCoinPoa <- submit alice do
createCmd CoinPoA with
attorney = bob
principal = alice
submit bob do
exerciseCmd aliceCoinPoa TransferCoin with newOwner = bob, coinId = aliceCoinDisclosed
return()