2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let a = "none" |
---|
5 | | - | |
---|
6 | | - | func b (c) = { |
---|
7 | | - | let d = { |
---|
8 | | - | let e = getInteger(this, c) |
---|
9 | | - | if ($isInstanceOf(e, "Int")) |
---|
10 | | - | then { |
---|
11 | | - | let f = e |
---|
12 | | - | f |
---|
13 | | - | } |
---|
14 | | - | else 0 |
---|
15 | | - | } |
---|
16 | | - | d |
---|
17 | | - | } |
---|
18 | | - | |
---|
19 | | - | |
---|
20 | | - | func g (c) = { |
---|
21 | | - | let h = { |
---|
22 | | - | let e = getString(this, c) |
---|
23 | | - | if ($isInstanceOf(e, "String")) |
---|
24 | | - | then { |
---|
25 | | - | let f = e |
---|
26 | | - | f |
---|
27 | | - | } |
---|
28 | | - | else a |
---|
29 | | - | } |
---|
30 | | - | h |
---|
31 | | - | } |
---|
32 | | - | |
---|
33 | | - | |
---|
34 | | - | func i (j) = (j + "_price") |
---|
35 | | - | |
---|
36 | | - | |
---|
37 | | - | func k (j) = b(i(j)) |
---|
38 | | - | |
---|
39 | | - | |
---|
40 | | - | func l (m,j) = (((j + "_") + m) + "_cnt") |
---|
41 | | - | |
---|
42 | | - | |
---|
43 | | - | func n (m,j) = b(l(m, j)) |
---|
44 | | - | |
---|
45 | | - | |
---|
46 | | - | func o (p,q) = ("item_" + toBase58String(sha256(toBytes((p + q))))) |
---|
47 | | - | |
---|
48 | | - | |
---|
49 | | - | func r (j) = (j + "_data") |
---|
50 | | - | |
---|
51 | | - | |
---|
52 | | - | func s (j) = (j + "_owner") |
---|
53 | | - | |
---|
54 | | - | |
---|
55 | | - | func t (j) = g(s(j)) |
---|
56 | | - | |
---|
57 | | - | |
---|
58 | | - | func u (v) = (v + "_balance") |
---|
59 | | - | |
---|
60 | | - | |
---|
61 | | - | func w (v) = b(u(v)) |
---|
62 | | - | |
---|
63 | | - | |
---|
64 | | - | @Callable(x) |
---|
65 | | - | func purchase (y) = { |
---|
66 | | - | let z = extract(x.payment) |
---|
67 | | - | if (isDefined(z.assetId)) |
---|
68 | | - | then throw("can use WAVES only at the moment") |
---|
69 | | - | else { |
---|
70 | | - | let A = toBase58String(x.caller.bytes) |
---|
71 | | - | let B = { |
---|
72 | | - | let e = getInteger(this, (("item_" + y) + "_coupon_price")) |
---|
73 | | - | if ($isInstanceOf(e, "Int")) |
---|
74 | | - | then { |
---|
75 | | - | let f = e |
---|
76 | | - | f |
---|
77 | | - | } |
---|
78 | | - | else 0 |
---|
79 | | - | } |
---|
80 | | - | if ((B > z.amount)) |
---|
81 | | - | then throw("purchase amount cannot be less than item price ") |
---|
82 | | - | else if ((z.amount > B)) |
---|
83 | | - | then throw("purchase amount cannot be higher than item price") |
---|
84 | | - | else WriteSet([DataEntry(((("status:purchase_item_" + y) + "_customer_") + A), "confirmed"), DataEntry(((("price:purchase_item_" + y) + "_customer_") + A), B)]) |
---|
85 | | - | } |
---|
86 | | - | } |
---|
87 | | - | |
---|
88 | | - | |
---|
89 | | - | |
---|
90 | | - | @Callable(x) |
---|
91 | | - | func addItem (q,B,C) = { |
---|
92 | | - | let D = toBase58String(x.caller.bytes) |
---|
93 | | - | let j = o(D, q) |
---|
94 | | - | if ((0 >= B)) |
---|
95 | | - | then throw("purchase amount cannot be less then item price") |
---|
96 | | - | else if ((t(j) != a)) |
---|
97 | | - | then throw("an item is already exist") |
---|
98 | | - | else WriteSet([DataEntry(s(j), D), DataEntry(i(j), B), DataEntry(r(j), C)]) |
---|
99 | | - | } |
---|
100 | | - | |
---|
101 | | - | |
---|
| 2 | + | {-# CONTENT_TYPE EXPRESSION #-} |
---|
| 3 | + | true |
---|