1 | | - | {-# STDLIB_VERSION 3 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | |
---|
5 | | - | |
---|
6 | | - | @Callable(i) |
---|
7 | | - | func purchase (kupon) = { |
---|
8 | | - | let pmt = extract(i.payment) |
---|
9 | | - | if (isDefined(pmt.assetId)) |
---|
10 | | - | then throw("can use WAVES only at the moment") |
---|
11 | | - | else { |
---|
12 | | - | let customerAddress = toBase58String(i.caller.bytes) |
---|
13 | | - | let price = match getInteger(this, (("item_" + kupon) + "_coupon_price")) { |
---|
14 | | - | case a: Int => |
---|
15 | | - | a |
---|
16 | | - | case _ => |
---|
17 | | - | 0 |
---|
18 | | - | } |
---|
19 | | - | if ((price > pmt.amount)) |
---|
20 | | - | then throw("purchase amount cannot be less than item price") |
---|
21 | | - | else if ((pmt.amount > price)) |
---|
22 | | - | then throw("purchase amount cannot be higer than item price") |
---|
23 | | - | else WriteSet([DataEntry(((("status:purchase_item_" + kupon) + "_customer_") + customerAddress), "confirmed"), DataEntry(((("price:purchase_item_" + kupon) + "_customer_") + customerAddress), price)]) |
---|
24 | | - | } |
---|
25 | | - | } |
---|
26 | | - | |
---|
27 | | - | |
---|
28 | | - | @Verifier(tx) |
---|
29 | | - | func verify () = { |
---|
30 | | - | let accountPubKey = base58'5rRMYG6R2BNvQFL9Ztxr4mLQL3XTvTYEpeLbta3nbmHs' |
---|
31 | | - | match tx { |
---|
32 | | - | case d: SetScriptTransaction => |
---|
33 | | - | true |
---|
34 | | - | case d: DataTransaction => |
---|
35 | | - | true |
---|
36 | | - | case _ => |
---|
37 | | - | sigVerify(tx.proofs[0], tx.bodyBytes, accountPubKey) |
---|
38 | | - | } |
---|
39 | | - | } |
---|
40 | | - | |
---|
| 1 | + | # no script |
---|