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