1 | | - | {-# STDLIB_VERSION 3 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | |
---|
5 | | - | |
---|
6 | | - | @Callable(i) |
---|
7 | | - | func deposit () = { |
---|
8 | | - | let pmt = extract(i.payment) |
---|
9 | | - | let assetId = base58'FGZTpAqL2wwfXwFRX32tAeD88Uaw8LSt3DPS312XodHZ' |
---|
10 | | - | if (isDefined(pmt.assetId)) |
---|
11 | | - | then throw("can hodl AAico only at the moment") |
---|
12 | | - | else { |
---|
13 | | - | let currentKey = toBase58String(i.caller.bytes) |
---|
14 | | - | let currentAmount = match getInteger(this, currentKey) { |
---|
15 | | - | case a: Int => |
---|
16 | | - | a |
---|
17 | | - | case _ => |
---|
18 | | - | 0 |
---|
19 | | - | } |
---|
20 | | - | let newAmount = (currentAmount + pmt.amount) |
---|
21 | | - | WriteSet([DataEntry(currentKey, newAmount)]) |
---|
22 | | - | } |
---|
23 | | - | } |
---|
24 | | - | |
---|
25 | | - | |
---|
26 | | - | |
---|
27 | | - | @Callable(i) |
---|
28 | | - | func withdraw (amount) = { |
---|
29 | | - | let currentKey = toBase58String(i.caller.bytes) |
---|
30 | | - | let currentAmount = match getInteger(this, currentKey) { |
---|
31 | | - | case a: Int => |
---|
32 | | - | a |
---|
33 | | - | case _ => |
---|
34 | | - | 0 |
---|
35 | | - | } |
---|
36 | | - | let newAmount = (currentAmount - amount) |
---|
37 | | - | if ((0 > amount)) |
---|
38 | | - | then throw("Can't withdraw negative amount") |
---|
39 | | - | else if ((0 > newAmount)) |
---|
40 | | - | then throw("Not enough balance") |
---|
41 | | - | else ScriptResult(WriteSet([DataEntry(currentKey, newAmount)]), TransferSet([ScriptTransfer(i.caller, amount, unit)])) |
---|
42 | | - | } |
---|
43 | | - | |
---|
44 | | - | |
---|
45 | | - | @Verifier(tx) |
---|
46 | | - | func verify () = true |
---|
47 | | - | |
---|
| 1 | + | # no script |
---|