Hey, in the code below, Alice transfers money to Bob. It’s possible because Alice is an owner , and the owner is the controller of Transfer.
During Transfer choice, after the “do” block, its create a new SimpleIou with the new owner(in our case is Bob).
Can you explain how it’s possible?
I thought that only the signatory of SimpleIou(in our case “Dora”) can create a new SimpleIou, and in this case the creation happen during the Transfer choice, which Alice implemented.
module SimpleIou where
import Daml.Script
data Cash = Cash with
currency : Text
amount : Decimal
deriving (Eq, Show)
template SimpleIou
with
issuer : Party
owner : Party
cash : Cash
where
signatory issuer
controller owner can
Transfer
: ContractId SimpleIou
with
newOwner : Party
do
create this with owner = newOwner
test_iou = script do
alice <- allocateParty "Alice"
bob <- allocateParty "Bob"
charlie <- allocateParty "Charlie"
dora <- allocateParty "Dora"
-- Dora issues an Iou for $100 to Alice.
iou <- submit dora do
createCmd SimpleIou with
issuer = dora
owner = alice
cash = Cash with
amount = 100.0
currency = "USD"
**-- Alice transfers it to Bob.**
** iou2 <- submit alice do**
** exerciseCmd iou Transfer with**
** newOwner = bob**
-- Bob transfers it to Charlie.
submit bob do
exerciseCmd iou2 Transfer with
newOwner = charlie