27 | | - | func k (f) = getBinaryValue(this, j(f)) |
---|
28 | | - | |
---|
29 | | - | |
---|
30 | | - | func l (m) = makeString(["item", m], d) |
---|
31 | | - | |
---|
32 | | - | |
---|
33 | | - | func n (m) = getIntegerValue(this, l(m)) |
---|
34 | | - | |
---|
35 | | - | |
---|
36 | | - | func o (p) = makeString(["votingDetails", p], d) |
---|
37 | | - | |
---|
38 | | - | |
---|
39 | | - | func q (m) = makeString(["sold", "item", m], d) |
---|
40 | | - | |
---|
41 | | - | |
---|
42 | | - | func r (p) = makeString(["votingEnd", p], d) |
---|
43 | | - | |
---|
44 | | - | |
---|
45 | | - | func s (p) = getIntegerValue(this, r(p)) |
---|
46 | | - | |
---|
47 | | - | |
---|
48 | | - | func t (p,u) = makeString(["votingId", p, "variant", toString(u)], d) |
---|
49 | | - | |
---|
50 | | - | |
---|
51 | | - | func v (p,u) = getIntegerValue(this, t(p, u)) |
---|
52 | | - | |
---|
53 | | - | |
---|
54 | | - | func w (p,x) = makeString(["votingId", p, x], d) |
---|
55 | | - | |
---|
56 | | - | |
---|
57 | | - | func y (z) = { |
---|
58 | | - | let A = getString(this, "admin") |
---|
59 | | - | if (!(isDefined(A))) |
---|
60 | | - | then throw("init first") |
---|
61 | | - | else (addressFromPublicKey(fromBase58String(value(A))) == z) |
---|
62 | | - | } |
---|
63 | | - | |
---|
64 | | - | |
---|
65 | | - | func B (p) = { |
---|
66 | | - | let C = value(blockInfoByHeight(height)).timestamp |
---|
67 | | - | let D = s(p) |
---|
68 | | - | (C >= D) |
---|
69 | | - | } |
---|
70 | | - | |
---|
71 | | - | |
---|
72 | | - | func E (p,F) = !(isDefined(getBoolean(this, w(p, toString(F))))) |
---|
73 | | - | |
---|
74 | | - | |
---|
75 | | - | func G (F) = i(toString(F)) |
---|
76 | | - | |
---|
77 | | - | |
---|
78 | | - | func H (p,F,I) = { |
---|
79 | | - | let J = k(toString(F)) |
---|
80 | | - | let K = value(I.assetId) |
---|
81 | | - | if ((J == K)) |
---|
82 | | - | then { |
---|
83 | | - | let L = (assetBalance(F, a) * b) |
---|
84 | | - | $Tuple4(L, Burn(value(I.assetId), 1), DeleteEntry(j(toString(F))), BooleanEntry(w(p, toString(F)), true)) |
---|
85 | | - | } |
---|
86 | | - | else throw("Wrong attachment asset") |
---|
87 | | - | } |
---|
88 | | - | |
---|
89 | | - | |
---|
90 | | - | @Callable(M) |
---|
91 | | - | func init (N) = { |
---|
92 | | - | let A = getString(this, "admin") |
---|
93 | | - | if (!(isDefined(A))) |
---|
94 | | - | then if ((M.caller == this)) |
---|
95 | | - | then [StringEntry("admin", N)] |
---|
96 | | - | else throw("Only admin") |
---|
97 | | - | else throw("Already inited") |
---|
98 | | - | } |
---|
| 25 | + | @Callable(l) |
---|
| 26 | + | func setStruct (m) = [j("mapString", toString(this), m)] |
---|
102 | | - | @Callable(M) |
---|
103 | | - | func startVoting (p,O,P) = if (y(M.caller)) |
---|
104 | | - | then { |
---|
105 | | - | let C = value(blockInfoByHeight(height)).timestamp |
---|
106 | | - | [StringEntry(o(p), O), IntegerEntry(r(p), (C + P)), IntegerEntry(t(p, 1), 0), IntegerEntry(t(p, 2), 0), IntegerEntry(t(p, 3), 0)] |
---|
107 | | - | } |
---|
108 | | - | else throw("Only admin") |
---|
| 30 | + | @Callable(l) |
---|
| 31 | + | func getArrayFromStruct (n) = if ((g("mapString", toString(this)) >= n)) |
---|
| 32 | + | then [StringEntry("1", f("mapString", toString(this))[n])] |
---|
| 33 | + | else throw("out of range") |
---|
112 | | - | @Callable(M) |
---|
113 | | - | func issueNft (Q) = if (if (y(M.caller)) |
---|
114 | | - | then !(G(addressFromStringValue(Q))) |
---|
115 | | - | else false) |
---|
116 | | - | then { |
---|
117 | | - | let R = j(Q) |
---|
118 | | - | if (!(isDefined(getBinary(this, R)))) |
---|
119 | | - | then { |
---|
120 | | - | let S = Issue("Ticket", "Multiplier for voting", 1, 0, false) |
---|
121 | | - | let T = calculateAssetId(S) |
---|
122 | | - | [S, ScriptTransfer(addressFromStringValue(Q), 1, T), BinaryEntry(R, T)] |
---|
123 | | - | } |
---|
124 | | - | else throw("Already granted") |
---|
125 | | - | } |
---|
126 | | - | else throw("Only admin") |
---|
| 37 | + | @Callable(l) |
---|
| 38 | + | func getElementFromArray (n,i) = if ((h(i) >= i)) |
---|
| 39 | + | then [StringEntry("2", split(f("mapString", toString(this))[n], b)[i])] |
---|
| 40 | + | else throw("out of range") |
---|
128 | | - | |
---|
129 | | - | |
---|
130 | | - | @Callable(M) |
---|
131 | | - | func getTokens () = { |
---|
132 | | - | let U = e(toString(M.caller)) |
---|
133 | | - | let V = g(toString(M.caller)) |
---|
134 | | - | if (!(V)) |
---|
135 | | - | then [BooleanEntry(U, true), ScriptTransfer(M.caller, c, a)] |
---|
136 | | - | else throw("Already got") |
---|
137 | | - | } |
---|
138 | | - | |
---|
139 | | - | |
---|
140 | | - | |
---|
141 | | - | @Callable(M) |
---|
142 | | - | func vote (p,u) = if (!(B(p))) |
---|
143 | | - | then if (E(p, M.caller)) |
---|
144 | | - | then { |
---|
145 | | - | let W = t(p, u) |
---|
146 | | - | let X = v(p, u) |
---|
147 | | - | let Y = h(toString(M.caller)) |
---|
148 | | - | if ((size(M.payments) != 1)) |
---|
149 | | - | then { |
---|
150 | | - | let L = assetBalance(M.caller, a) |
---|
151 | | - | [BooleanEntry(Y, false), BooleanEntry(w(p, toString(M.caller)), true), IntegerEntry(W, (X + L))] |
---|
152 | | - | } |
---|
153 | | - | else { |
---|
154 | | - | let Z = H(p, M.caller, M.payments[0]) |
---|
155 | | - | let aa = Z._1 |
---|
156 | | - | let ab = Z._2 |
---|
157 | | - | let ac = Z._3 |
---|
158 | | - | let ad = Z._4 |
---|
159 | | - | [ab, ac, ad, BooleanEntry(Y, false), IntegerEntry(W, (X + aa))] |
---|
160 | | - | } |
---|
161 | | - | } |
---|
162 | | - | else throw("Invalid voter") |
---|
163 | | - | else throw("Voting is ended") |
---|
164 | | - | |
---|
165 | | - | |
---|
166 | | - | |
---|
167 | | - | @Callable(M) |
---|
168 | | - | func joinProgram (ae) = { |
---|
169 | | - | let af = g(ae) |
---|
170 | | - | if (if (af) |
---|
171 | | - | then !(G(M.caller)) |
---|
172 | | - | else false) |
---|
173 | | - | then { |
---|
174 | | - | let U = e(toString(M.caller)) |
---|
175 | | - | let ag = e(ae) |
---|
176 | | - | let ah = getBoolean(this, U) |
---|
177 | | - | if (!(isDefined(ah))) |
---|
178 | | - | then [BooleanEntry(U, true), BooleanEntry(ag, false), ScriptTransfer(M.caller, c, a)] |
---|
179 | | - | else throw("Already in program") |
---|
180 | | - | } |
---|
181 | | - | else throw("Wrong patron or caller from blackList") |
---|
182 | | - | } |
---|
183 | | - | |
---|
184 | | - | |
---|
185 | | - | |
---|
186 | | - | @Callable(M) |
---|
187 | | - | func buyItem (m) = if (!(G(M.caller))) |
---|
188 | | - | then { |
---|
189 | | - | let ai = M.payments[0] |
---|
190 | | - | let aj = ai.amount |
---|
191 | | - | let ak = n(m) |
---|
192 | | - | if (if ((value(ai.assetId) == a)) |
---|
193 | | - | then (ak == aj) |
---|
194 | | - | else false) |
---|
195 | | - | then [Burn(a, aj), StringEntry(q(m), toString(M.caller))] |
---|
196 | | - | else throw("Wrong payment assetId") |
---|
197 | | - | } |
---|
198 | | - | else throw("Caller from blackList") |
---|
199 | | - | |
---|
200 | | - | |
---|
201 | | - | @Verifier(al) |
---|
202 | | - | func am () = { |
---|
203 | | - | let an = al |
---|
204 | | - | if ($isInstanceOf(an, "DataTransaction")) |
---|
205 | | - | then { |
---|
206 | | - | let ao = an |
---|
207 | | - | if (!(isDefined(getString(ao.data, "admin")))) |
---|
208 | | - | then sigVerify(al.bodyBytes, al.proofs[0], fromBase58String(getStringValue(this, "admin"))) |
---|
209 | | - | else false |
---|
210 | | - | } |
---|
211 | | - | else if ($isInstanceOf(an, "MassTransferTransaction")) |
---|
212 | | - | then { |
---|
213 | | - | let ap = an |
---|
214 | | - | sigVerify(al.bodyBytes, al.proofs[0], fromBase58String(getStringValue(this, "admin"))) |
---|
215 | | - | } |
---|
216 | | - | else sigVerify(al.bodyBytes, al.proofs[0], al.senderPublicKey) |
---|
217 | | - | } |
---|