6 | | - | let b = 3 |
---|
7 | | - | |
---|
8 | | - | let c = 2 |
---|
9 | | - | |
---|
10 | | - | let d = "voting" |
---|
11 | | - | |
---|
12 | | - | let e = "reveal" |
---|
13 | | - | |
---|
14 | | - | let f = "featured" |
---|
15 | | - | |
---|
16 | | - | let g = "delisted" |
---|
17 | | - | |
---|
18 | | - | let h = base58'Ce7p5ejhjAmupqL2uKDVM6RuGazLdnPTY6fx71E4N3uV' |
---|
19 | | - | |
---|
20 | | - | func i (j) = (j + "_price") |
---|
21 | | - | |
---|
22 | | - | |
---|
23 | | - | func k (l) = { |
---|
24 | | - | let m = { |
---|
25 | | - | let n = getInteger(this, l) |
---|
26 | | - | if ($isInstanceOf(n, "Int")) |
---|
27 | | - | then { |
---|
28 | | - | let o = n |
---|
29 | | - | o |
---|
| 6 | + | @Callable(b) |
---|
| 7 | + | func deposit () = { |
---|
| 8 | + | let c = extract(b.payment) |
---|
| 9 | + | if ((c.assetId != a)) |
---|
| 10 | + | then throw("wEUR only at the moment") |
---|
| 11 | + | else { |
---|
| 12 | + | let d = toBase58String(b.caller.bytes) |
---|
| 13 | + | let e = { |
---|
| 14 | + | let f = getInteger(this, d) |
---|
| 15 | + | if ($isInstanceOf(f, "Int")) |
---|
| 16 | + | then { |
---|
| 17 | + | let g = f |
---|
| 18 | + | g |
---|
| 19 | + | } |
---|
| 20 | + | else 0 |
---|
31 | | - | else 0 |
---|
32 | | - | } |
---|
33 | | - | m |
---|
34 | | - | } |
---|
35 | | - | |
---|
36 | | - | |
---|
37 | | - | func p (j) = k(i(j)) |
---|
38 | | - | |
---|
39 | | - | |
---|
40 | | - | func q (r,j) = (((j + "_") + r) + "_cnt") |
---|
41 | | - | |
---|
42 | | - | |
---|
43 | | - | func s (r,j) = k(q(r, j)) |
---|
44 | | - | |
---|
45 | | - | |
---|
46 | | - | func t (u,v) = ("item_" + toBase58String(sha256(toBytes((u + v))))) |
---|
47 | | - | |
---|
48 | | - | |
---|
49 | | - | func w (j) = (j + "_data") |
---|
50 | | - | |
---|
51 | | - | |
---|
52 | | - | func x (j) = (j + "_owner") |
---|
53 | | - | |
---|
54 | | - | |
---|
55 | | - | func y (l) = { |
---|
56 | | - | let z = { |
---|
57 | | - | let n = getString(this, l) |
---|
58 | | - | if ($isInstanceOf(n, "String")) |
---|
59 | | - | then { |
---|
60 | | - | let o = n |
---|
61 | | - | o |
---|
62 | | - | } |
---|
63 | | - | else a |
---|
64 | | - | } |
---|
65 | | - | z |
---|
66 | | - | } |
---|
67 | | - | |
---|
68 | | - | |
---|
69 | | - | func A (j) = y(x(j)) |
---|
70 | | - | |
---|
71 | | - | |
---|
72 | | - | func B (C) = (C + "_balance") |
---|
73 | | - | |
---|
74 | | - | |
---|
75 | | - | func D (C) = k(B(C)) |
---|
76 | | - | |
---|
77 | | - | |
---|
78 | | - | func E (j,r) = (((j + "_") + r) + "_commit") |
---|
79 | | - | |
---|
80 | | - | |
---|
81 | | - | func F (j,r) = y(E(j, r)) |
---|
82 | | - | |
---|
83 | | - | |
---|
84 | | - | func G (j) = (j + "_comcnt") |
---|
85 | | - | |
---|
86 | | - | |
---|
87 | | - | func H (j) = k(G(j)) |
---|
88 | | - | |
---|
89 | | - | |
---|
90 | | - | func I (j,r) = (((j + "_") + r) + "_reveal") |
---|
91 | | - | |
---|
92 | | - | |
---|
93 | | - | func J (j,r) = y(I(j, r)) |
---|
94 | | - | |
---|
95 | | - | |
---|
96 | | - | func K (j) = (j + "_status") |
---|
97 | | - | |
---|
98 | | - | |
---|
99 | | - | func L (j) = y(K(j)) |
---|
100 | | - | |
---|
101 | | - | |
---|
102 | | - | func M (j,N) = ((j + "_res") + N) |
---|
103 | | - | |
---|
104 | | - | |
---|
105 | | - | func O (j,N) = k(M(j, N)) |
---|
106 | | - | |
---|
107 | | - | |
---|
108 | | - | @Callable(P) |
---|
109 | | - | func addItem (v,Q,R) = { |
---|
110 | | - | let S = toBase58String(P.caller.bytes) |
---|
111 | | - | let j = t(S, v) |
---|
112 | | - | if ((0 >= Q)) |
---|
113 | | - | then throw("purchase amount cannot be less than item price") |
---|
114 | | - | else if ((A(j) != a)) |
---|
115 | | - | then throw("an item already exists") |
---|
116 | | - | else WriteSet([DataEntry(x(j), S), DataEntry(i(j), Q), DataEntry(w(j), R)]) |
---|
117 | | - | } |
---|
118 | | - | |
---|
119 | | - | |
---|
120 | | - | |
---|
121 | | - | @Callable(P) |
---|
122 | | - | func purchase (j) = { |
---|
123 | | - | let T = extract(P.payment) |
---|
124 | | - | if (isDefined(T.assetId)) |
---|
125 | | - | then throw("can hold waves only at the moment") |
---|
126 | | - | else { |
---|
127 | | - | let U = toBase58String(P.caller.bytes) |
---|
128 | | - | let Q = p(j) |
---|
129 | | - | let S = A(j) |
---|
130 | | - | if ((Q > T.amount)) |
---|
131 | | - | then throw("purchase amount cannot be less than item price") |
---|
132 | | - | else if ((T.amount > Q)) |
---|
133 | | - | then throw("purchase amount cannot be higher than item price") |
---|
134 | | - | else if ((S == a)) |
---|
135 | | - | then throw("supplier does not exist") |
---|
136 | | - | else WriteSet([DataEntry(q(U, j), (s(U, j) + 1)), DataEntry(B(S), (D(S) + T.amount))]) |
---|
| 22 | + | let h = (e + c.amount) |
---|
| 23 | + | WriteSet([DataEntry(d, h)]) |
---|
142 | | - | @Callable(P) |
---|
143 | | - | func voteCommit (j,V) = { |
---|
144 | | - | let r = toBase58String(P.caller.bytes) |
---|
145 | | - | let W = H(j) |
---|
146 | | - | let X = L(j) |
---|
147 | | - | if ((W >= b)) |
---|
148 | | - | then throw("reached max num of voters") |
---|
149 | | - | else if ((F(j, r) != a)) |
---|
150 | | - | then throw("user has already participated") |
---|
151 | | - | else if ((x(j) == a)) |
---|
152 | | - | then throw("item does not exist") |
---|
153 | | - | else if (if ((X != a)) |
---|
154 | | - | then (X != d) |
---|
155 | | - | else false) |
---|
156 | | - | then throw("voting is not possible") |
---|
157 | | - | else WriteSet([DataEntry(E(j, r), V), DataEntry(G(j), (W + 1)), DataEntry(K(j), if ((W == b)) |
---|
158 | | - | then e |
---|
159 | | - | else d)]) |
---|
160 | | - | } |
---|
161 | | - | |
---|
162 | | - | |
---|
163 | | - | |
---|
164 | | - | @Callable(P) |
---|
165 | | - | func voteReveal (j,N,Y) = { |
---|
166 | | - | let r = toBase58String(P.caller.bytes) |
---|
167 | | - | let X = L(j) |
---|
168 | | - | let Z = (O(j, N) + 1) |
---|
169 | | - | if ((toBase58String(sha256(toBytes((N + Y)))) != F(j, r))) |
---|
170 | | - | then throw("reveal data is not valid") |
---|
171 | | - | else if ((b > H(j))) |
---|
172 | | - | then throw("max number of votes hasn't reach yet") |
---|
173 | | - | else if ((J(j, r) != a)) |
---|
174 | | - | then throw("user has already participated") |
---|
175 | | - | else if (if ((X != d)) |
---|
176 | | - | then (X != e) |
---|
177 | | - | else false) |
---|
178 | | - | then throw("wrong status") |
---|
179 | | - | else if (if ((N != f)) |
---|
180 | | - | then (N != g) |
---|
181 | | - | else false) |
---|
182 | | - | then throw("wrong vote") |
---|
183 | | - | else if (if ((X == f)) |
---|
184 | | - | then true |
---|
185 | | - | else (X == g)) |
---|
186 | | - | then throw("vote has finished") |
---|
187 | | - | else WriteSet([DataEntry(I(j, r), N), DataEntry(M(j, N), Z), DataEntry(K(j), if ((Z >= c)) |
---|
188 | | - | then N |
---|
189 | | - | else e)]) |
---|
190 | | - | } |
---|
191 | | - | |
---|
192 | | - | |
---|
193 | | - | |
---|
194 | | - | @Callable(P) |
---|
195 | | - | func deposit () = { |
---|
196 | | - | let T = extract(P.payment) |
---|
197 | | - | if ((T.assetId != h)) |
---|
198 | | - | then throw("wEUR only at the moment") |
---|
199 | | - | else { |
---|
200 | | - | let aa = toBase58String(P.caller.bytes) |
---|
201 | | - | let ab = { |
---|
202 | | - | let n = getInteger(this, aa) |
---|
203 | | - | if ($isInstanceOf(n, "Int")) |
---|
204 | | - | then { |
---|
205 | | - | let o = n |
---|
206 | | - | o |
---|
207 | | - | } |
---|
208 | | - | else 0 |
---|
209 | | - | } |
---|
210 | | - | let ac = (ab + T.amount) |
---|
211 | | - | WriteSet([DataEntry(aa, ac)]) |
---|
212 | | - | } |
---|
213 | | - | } |
---|
214 | | - | |
---|
215 | | - | |
---|
216 | | - | |
---|
217 | | - | @Callable(P) |
---|
218 | | - | func withdraw (ad) = { |
---|
219 | | - | let aa = toBase58String(P.caller.bytes) |
---|
220 | | - | let ab = { |
---|
221 | | - | let n = getInteger(this, aa) |
---|
222 | | - | if ($isInstanceOf(n, "Int")) |
---|
| 29 | + | @Callable(b) |
---|
| 30 | + | func withdraw (i) = { |
---|
| 31 | + | let d = toBase58String(b.caller.bytes) |
---|
| 32 | + | let e = { |
---|
| 33 | + | let f = getInteger(this, d) |
---|
| 34 | + | if ($isInstanceOf(f, "Int")) |
---|