-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakeMint.rho
67 lines (67 loc) · 2.63 KB
/
MakeMint.rho
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
57
58
59
60
61
62
63
64
65
66
67
new
MakeMint, rs(`rho:registry:insertSigned:ed25519`), uriOut,
rl(`rho:registry:lookup`), NonNegativeNumberCh
in {
rl!(`rho:id:nd74ztexkao5awjhj95e3octkza7tydwiy7euthnyrt5ihgi9rj495`, *NonNegativeNumberCh) |
for(@(_, NonNegativeNumber) <- NonNegativeNumberCh) {
contract MakeMint(return) = {
new thisMint, internalMakePurse, decr in {
contract thisMint(@"makePurse", @init, return) = {
new balanceCh in {
@NonNegativeNumber!(init, *balanceCh) | for(@balance <- balanceCh) {
internalMakePurse!(balance, *return)
}
}
} |
contract internalMakePurse(balance, return) = {
//balance must be a name that NonNegativeNumber contract is listening on
new thisPurse in {
contract thisPurse(@=*decr, @amount, success) = { balance!("sub", amount, *success) } |
contract thisPurse(@"getBalance", return) = { balance!("value", *return) } |
contract thisPurse(@"sprout", return) = { thisMint!("makePurse", 0, *return) } |
contract thisPurse(@"split", @amount, return) = {
new destPurseCh, successCh in {
thisPurse!("sprout", *destPurseCh) | for(@destPurse <- destPurseCh) {
@destPurse!("deposit", amount, *thisPurse, *successCh) |
for(@success <- successCh) {
if (success) {
return!([destPurse])
} else {
return!([])
}
}
}
}
} |
contract thisPurse(@"deposit", @amount, @src, success) = {
new result in {
@src!(*decr, amount, *result) | //call src decr function.
for(@decrSuccess <- result) {
if (decrSuccess) {
balance!("add", amount, *success) // add transferred amount to this purse
} else {
success!(false)
}
}
}
} |
return!(bundle+{*thisPurse})
}
} |
return!(bundle+{*thisMint})
}
}
} |
rs!(
"d9ba2075d355755060205605f4cdbd5ecd3cce5ed1f39690f34772f7c9aa30ab".hexToBytes(),
(9223372036854775807, bundle+{*MakeMint}),
"36229e3f4530c15f3b7c1d9165369201b70b4673289a003652af14b436b20a275d5909d6dfbbd06e685292d39eadf3af11db6f882dcc78ef0b794e6da0ad6109".hexToBytes(),
*uriOut
) |
new $insertArbitrary, $stdout, ret in {
insertArbitrary!(*MakeMint, *ret) |
for ( uri <- ret ) {
stdout!(["#define $MakeMint", *uri])
}
}
}