2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let wavesLets = 100000000 |
---|
5 | | - | |
---|
6 | | - | let TotalAmountKey = "TotalAmount" |
---|
7 | | - | |
---|
8 | | - | let TotalAmountLeftKey = "TotalAmountLeft" |
---|
9 | | - | |
---|
10 | | - | let receiverPubKey = base58'8xLZH4uWaXHqxNcaf48a41X1bnYhPmkYs4kKcSBHp3xR' |
---|
11 | | - | |
---|
12 | | - | let receiver = addressFromPublicKey(receiverPubKey) |
---|
13 | | - | |
---|
14 | | - | let LastPaymentKey = "LastPayment" |
---|
15 | | - | |
---|
16 | | - | let PaymentTimeout = 10 |
---|
17 | | - | |
---|
18 | | - | let MaxSalary = 1 |
---|
19 | | - | |
---|
20 | | - | @Callable(i) |
---|
21 | | - | func deposit () = { |
---|
22 | | - | let pmt = extract(i.payment) |
---|
23 | | - | if (isDefined(pmt.assetId)) |
---|
24 | | - | then throw("can hodl waves only at the moment") |
---|
25 | | - | else { |
---|
26 | | - | let currentKey = toBase58String(i.caller.bytes) |
---|
27 | | - | let currentAmount = match getInteger(this, currentKey) { |
---|
28 | | - | case a: Int => |
---|
29 | | - | a |
---|
30 | | - | case _ => |
---|
31 | | - | 0 |
---|
32 | | - | } |
---|
33 | | - | let currentTotalAmount = match getInteger(this, TotalAmountKey) { |
---|
34 | | - | case a: Int => |
---|
35 | | - | a |
---|
36 | | - | case _ => |
---|
37 | | - | 0 |
---|
38 | | - | } |
---|
39 | | - | let currentAmountLeft = match getInteger(this, TotalAmountLeftKey) { |
---|
40 | | - | case a: Int => |
---|
41 | | - | a |
---|
42 | | - | case _ => |
---|
43 | | - | 0 |
---|
44 | | - | } |
---|
45 | | - | let newAmount = (currentAmount + pmt.amount) |
---|
46 | | - | let newtotalAmount = (currentTotalAmount + pmt.amount) |
---|
47 | | - | let newtotalamountleft = (currentAmountLeft + pmt.amount) |
---|
48 | | - | WriteSet([DataEntry(currentKey, newAmount), DataEntry(TotalAmountKey, newtotalAmount), DataEntry(TotalAmountLeftKey, newtotalamountleft)]) |
---|
49 | | - | } |
---|
50 | | - | } |
---|
51 | | - | |
---|
52 | | - | |
---|
53 | | - | |
---|
54 | | - | @Callable(i) |
---|
55 | | - | func withdraw (amount) = { |
---|
56 | | - | let currentKey = toBase58String(i.caller.bytes) |
---|
57 | | - | let AllowedSigner = (i.caller == receiver) |
---|
58 | | - | let currentAmountLeft = match getInteger(this, TotalAmountLeftKey) { |
---|
59 | | - | case a: Int => |
---|
60 | | - | a |
---|
61 | | - | case _ => |
---|
62 | | - | 0 |
---|
63 | | - | } |
---|
64 | | - | let lastPayment = match getInteger(this, LastPaymentKey) { |
---|
65 | | - | case a: Int => |
---|
66 | | - | a |
---|
67 | | - | case _ => |
---|
68 | | - | 0 |
---|
69 | | - | } |
---|
70 | | - | if (!(AllowedSigner)) |
---|
71 | | - | then throw("Withdraw is only allowed by recipient") |
---|
72 | | - | else if (((lastPayment + PaymentTimeout) > height)) |
---|
73 | | - | then throw("Next payment not yet allowed") |
---|
74 | | - | else { |
---|
75 | | - | let newAmountLeft = (currentAmountLeft - amount) |
---|
76 | | - | if ((0 > amount)) |
---|
77 | | - | then throw("Can't withdraw negative amount") |
---|
78 | | - | else if ((amount > (MaxSalary * wavesLets))) |
---|
79 | | - | then throw((("Not allowed to withdraw more than " + toString(MaxSalary)) + " WAVES")) |
---|
80 | | - | else if ((0 > newAmountLeft)) |
---|
81 | | - | then throw("Not enough balance") |
---|
82 | | - | else ScriptResult(WriteSet([DataEntry(TotalAmountLeftKey, newAmountLeft), DataEntry(LastPaymentKey, height)]), TransferSet([ScriptTransfer(receiver, amount, unit)])) |
---|
83 | | - | } |
---|
84 | | - | } |
---|
85 | | - | |
---|
86 | | - | |
---|
87 | | - | @Verifier(tx) |
---|
88 | | - | func verify () = match tx { |
---|
89 | | - | case s: SetScriptTransaction => |
---|
90 | | - | true |
---|
91 | | - | case _ => |
---|
92 | | - | false |
---|
93 | | - | } |
---|
94 | | - | |
---|
| 2 | + | {-# CONTENT_TYPE EXPRESSION #-} |
---|
| 3 | + | let PubKey1 = base58'854p8BYzrj6yBPRPmfQur3oF1Rjc1AJ548qRp5FT5kDa' |
---|
| 4 | + | let PubKey2 = base58'DKGFPozLrsiR8NM4NJzqQaBYC8NyGYjuw2hDYicQVjco' |
---|
| 5 | + | let sig1 = if (sigVerify(tx.bodyBytes, tx.proofs[0], PubKey1)) |
---|
| 6 | + | then 1 |
---|
| 7 | + | else 0 |
---|
| 8 | + | let sig2 = if (sigVerify(tx.bodyBytes, tx.proofs[1], PubKey2)) |
---|
| 9 | + | then 1 |
---|
| 10 | + | else 0 |
---|
| 11 | + | ((sig1 + sig2) > 0) |
---|