/
Main.daml
56 lines (48 loc) · 1.6 KB
/
Main.daml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
-- Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
module Main where
import Daml.Script
import Iou
import IouTrade()
initialize : Script [Party]
initialize = do
-- allocate parties
alice <- allocatePartyWithHint "Alice" (PartyIdHint "Alice")
bob <- allocatePartyWithHint "Bob" (PartyIdHint "Bob")
usBank <- allocatePartyWithHint "USD_Bank" (PartyIdHint "USD_Bank")
eurBank <- allocatePartyWithHint "EUR_Bank" (PartyIdHint "EUR_Bank")
aliceId <- validateUserId "alice"
bobId <- validateUserId "bob"
eurBankId <- validateUserId "eur"
usBankId <- validateUserId "us"
createUser (User aliceId (Some alice)) [CanActAs alice]
createUser (User bobId (Some bob)) [CanActAs bob]
createUser (User eurBankId (Some eurBank)) [CanActAs eurBank]
createUser (User usBankId (Some usBank)) [CanActAs usBank]
-- Banks issue IOU transfers.
iouTransferAliceCid <- submit eurBank do
createAndExerciseCmd
Iou with
issuer = eurBank
owner = eurBank
currency = "EUR"
amount = 100.0
observers = []
Iou_Transfer with
newOwner = alice
iouTransferBobCid <- submit usBank do
createAndExerciseCmd
Iou with
issuer = usBank
owner = usBank
currency = "USD"
amount = 110.0
observers = []
Iou_Transfer with
newOwner = bob
-- Bob and Alice accept.
submit alice do
exerciseCmd iouTransferAliceCid IouTransfer_Accept
submit bob do
exerciseCmd iouTransferBobCid IouTransfer_Accept
pure [alice, eurBank]