1 | | - | {-# STDLIB_VERSION 5 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let a = "__" |
---|
5 | | - | |
---|
6 | | - | let b = 1000000 |
---|
7 | | - | |
---|
8 | | - | let c = 100000000 |
---|
9 | | - | |
---|
10 | | - | let d = "WAVES" |
---|
11 | | - | |
---|
12 | | - | let e = fromBase58String(d) |
---|
13 | | - | |
---|
14 | | - | func f (g) = valueOrErrorMessage(getInteger(this, g), (("Mandatory this." + g) + " is not defined")) |
---|
15 | | - | |
---|
16 | | - | |
---|
17 | | - | func h (g,i) = valueOrElse(getString(this, g), i) |
---|
18 | | - | |
---|
19 | | - | |
---|
20 | | - | func j (k,g) = valueOrErrorMessage(getString(k, g), (("Mandatory this." + g) + " is not defined")) |
---|
21 | | - | |
---|
22 | | - | |
---|
23 | | - | func l (g) = valueOrErrorMessage(addressFromString(j(this, g)), (("Fail to convert this." + g) + " value into Address")) |
---|
24 | | - | |
---|
25 | | - | |
---|
26 | | - | func m (n) = { |
---|
27 | | - | let k = valueOrErrorMessage(addressFromString(n), ("fail to convert into address " + n)) |
---|
28 | | - | if ((0 > wavesBalance(k).available)) |
---|
29 | | - | then throw() |
---|
30 | | - | else n |
---|
31 | | - | } |
---|
32 | | - | |
---|
33 | | - | |
---|
34 | | - | func o (k) = ("%s__" + k) |
---|
35 | | - | |
---|
36 | | - | |
---|
37 | | - | func p (k) = ("%s%s__totals__" + k) |
---|
38 | | - | |
---|
39 | | - | |
---|
40 | | - | func q () = "%s%s__cfg__depositAmount" |
---|
41 | | - | |
---|
42 | | - | |
---|
43 | | - | func r () = "%s%s__cfg__neutrinoAddress" |
---|
44 | | - | |
---|
45 | | - | |
---|
46 | | - | func s () = "%s%s__cfg__mainNeutrinoNodeAddress" |
---|
47 | | - | |
---|
48 | | - | |
---|
49 | | - | func t () = "%s%s__cfg__protocolPartX6" |
---|
50 | | - | |
---|
51 | | - | |
---|
52 | | - | func u () = "%s%s__cfg__benificaryPartX6" |
---|
53 | | - | |
---|
54 | | - | |
---|
55 | | - | func v () = "%s%s__cfg__beneficiaryAddress" |
---|
56 | | - | |
---|
57 | | - | |
---|
58 | | - | func w () = "%s__lastUpdatedHeight" |
---|
59 | | - | |
---|
60 | | - | |
---|
61 | | - | func x () = "%s__scriptUpdateHash" |
---|
62 | | - | |
---|
63 | | - | |
---|
64 | | - | func y (z,A,B,C) = makeString(["%s%d%d%d%d%s%d%d", z, toString(lastBlock.height), toString(lastBlock.timestamp), toString(A), toString(B), C, "0", "0"], a) |
---|
65 | | - | |
---|
66 | | - | |
---|
67 | | - | func D (E,F) = { |
---|
68 | | - | let G = split(E, a) |
---|
69 | | - | makeString(["%s%d%d%d%d%s%d%d", G[1], G[2], G[3], G[4], G[5], F, toString(lastBlock.height), toString(lastBlock.timestamp)], a) |
---|
70 | | - | } |
---|
71 | | - | |
---|
72 | | - | |
---|
73 | | - | func H (I,J) = makeString(["%s%s%s", "history", toString(I), toBase58String(J)], a) |
---|
74 | | - | |
---|
75 | | - | |
---|
76 | | - | func K (L,M,N,O,P) = makeString(["%d%d%d%d%d%d%d", toString(lastBlock.height), toString(lastBlock.timestamp), toString(L), toString(M), toString(N), toString(O), toString(P)], a) |
---|
77 | | - | |
---|
78 | | - | |
---|
79 | | - | func Q (I,J,R,M,N,S,T) = StringEntry(H(I, J), K(R, M, N, S, T)) |
---|
80 | | - | |
---|
81 | | - | |
---|
82 | | - | func U (R,M,N,O,P) = makeString(["%d%d%d%d%d", toString(R), toString(M), toString(N), toString(O), toString(P)], a) |
---|
83 | | - | |
---|
84 | | - | |
---|
85 | | - | func V (W,R,M,N,O,P) = { |
---|
86 | | - | let X = p(toString(W)) |
---|
87 | | - | let Y = split(h(X, U(0, 0, 0, 0, 0)), a) |
---|
88 | | - | let Z = (parseIntValue(Y[1]) + R) |
---|
89 | | - | let aa = (parseIntValue(Y[2]) + M) |
---|
90 | | - | let ab = (parseIntValue(Y[3]) + N) |
---|
91 | | - | let ac = (parseIntValue(Y[4]) + O) |
---|
92 | | - | let ad = (parseIntValue(Y[5]) + P) |
---|
93 | | - | StringEntry(X, U(Z, aa, ab, ac, ad)) |
---|
94 | | - | } |
---|
95 | | - | |
---|
96 | | - | |
---|
97 | | - | @Callable(ae) |
---|
98 | | - | func constructor (A,af,ag,ah,ai) = if ((ae.caller != this)) |
---|
99 | | - | then throw("permissions denied") |
---|
100 | | - | else if ((0 > A)) |
---|
101 | | - | then throw("depositAmount less then zero") |
---|
102 | | - | else if ((0 > ah)) |
---|
103 | | - | then throw("protocolPartX6 less then zero") |
---|
104 | | - | else if ((0 > ai)) |
---|
105 | | - | then throw("benificaryPartX6 less then zero") |
---|
106 | | - | else if (((ah + ai) != b)) |
---|
107 | | - | then throw("parts sum must be 1") |
---|
108 | | - | else [IntegerEntry(q(), A), StringEntry(r(), m(af)), StringEntry(s(), m(ag)), IntegerEntry(t(), ah), IntegerEntry(u(), ai)] |
---|
109 | | - | |
---|
110 | | - | |
---|
111 | | - | |
---|
112 | | - | @Callable(ae) |
---|
113 | | - | func sumbitApplication () = if ((size(ae.payments) != 1)) |
---|
114 | | - | then throw("exact 1 payment must be attached") |
---|
115 | | - | else if ((ae.caller != ae.originCaller)) |
---|
116 | | - | then throw("dapp to dapp calls are not allowed") |
---|
117 | | - | else { |
---|
118 | | - | let aj = ae.payments[0] |
---|
119 | | - | let ak = aj.amount |
---|
120 | | - | let al = valueOrElse(aj.assetId, e) |
---|
121 | | - | let am = f(q()) |
---|
122 | | - | let J = toBase58String(ae.transactionId) |
---|
123 | | - | let I = toString(ae.caller) |
---|
124 | | - | let an = o(I) |
---|
125 | | - | if ((al != e)) |
---|
126 | | - | then throw("only Waves can be used for deposit") |
---|
127 | | - | else if ((ak != am)) |
---|
128 | | - | then throw((("exactly " + toString(am)) + " Wavelets are expected")) |
---|
129 | | - | else if ((h(an, "") != "")) |
---|
130 | | - | then throw("your node already registered") |
---|
131 | | - | else [StringEntry(an, y(J, ak, ak, "PENDING"))] |
---|
132 | | - | } |
---|
133 | | - | |
---|
134 | | - | |
---|
135 | | - | |
---|
136 | | - | @Callable(ae) |
---|
137 | | - | func distibuteMinerReward (ao) = if ((size(ae.payments) != 1)) |
---|
138 | | - | then throw("exact 1 payment must be attached") |
---|
139 | | - | else if ((ae.caller != ae.originCaller)) |
---|
140 | | - | then throw("dapp to dapp calls are not allowed") |
---|
141 | | - | else { |
---|
142 | | - | let aj = ae.payments[0] |
---|
143 | | - | let al = valueOrElse(aj.assetId, e) |
---|
144 | | - | let ap = ae.fee |
---|
145 | | - | let aq = valueOrElse(ae.feeAssetId, e) |
---|
146 | | - | let ar = (ap * 2) |
---|
147 | | - | let R = (aj.amount - ar) |
---|
148 | | - | if ((al != e)) |
---|
149 | | - | then throw("only Waves can be used in payment") |
---|
150 | | - | else if ((aq != e)) |
---|
151 | | - | then throw("only Waves can be used in fees") |
---|
152 | | - | else if ((ap != ((5 * c) / 1000))) |
---|
153 | | - | then throw("fee amount couldn't exceed 0.005") |
---|
154 | | - | else { |
---|
155 | | - | let as = l(r()) |
---|
156 | | - | let at = l(s()) |
---|
157 | | - | let au = ae.caller |
---|
158 | | - | let av = scriptHash(au) |
---|
159 | | - | let aw = addressFromStringValue(ao) |
---|
160 | | - | let ax = addressFromStringValue(j(au, v())) |
---|
161 | | - | let ay = if ((av == unit)) |
---|
162 | | - | then $Tuple2(aw, aw) |
---|
163 | | - | else $Tuple2(ax, aw) |
---|
164 | | - | let az = ay._1 |
---|
165 | | - | let aA = ay._2 |
---|
166 | | - | let aB = f(t()) |
---|
167 | | - | let aC = f(u()) |
---|
168 | | - | let aD = (wavesBalance(au).available - ap) |
---|
169 | | - | if ((aD != 0)) |
---|
170 | | - | then throw((("all " + toString(aD)) + " Wavelets from the Node balance must be attached into the payment")) |
---|
171 | | - | else { |
---|
172 | | - | let aE = fraction(R, aC, b) |
---|
173 | | - | let N = (R - aE) |
---|
174 | | - | let S = (N / 2) |
---|
175 | | - | let T = (N - S) |
---|
176 | | - | [ScriptTransfer(az, aE, unit), ScriptTransfer(as, S, unit), ScriptTransfer(at, T, unit), ScriptTransfer(aA, ar, unit), Q(au, ae.transactionId, R, aE, N, S, T), V(au, R, aE, N, S, T)] |
---|
177 | | - | } |
---|
178 | | - | } |
---|
179 | | - | } |
---|
180 | | - | |
---|
181 | | - | |
---|
182 | | - | |
---|
183 | | - | @Callable(ae) |
---|
184 | | - | func validateAndApproveLeasings (aF) = { |
---|
185 | | - | let aG = [0, 1, 2, 3, 4, 5, 6, 7] |
---|
186 | | - | let aH = split(aF, a) |
---|
187 | | - | let aI = size(aG) |
---|
188 | | - | let as = l(r()) |
---|
189 | | - | if ((ae.caller != as)) |
---|
190 | | - | then throw("validateAndApproveLeasings not authorized") |
---|
191 | | - | else if (((size(aH) % 2) != 0)) |
---|
192 | | - | then throw("Only even number of nodes is allowed") |
---|
193 | | - | else if ((size(aH) != aI)) |
---|
194 | | - | then throw((("Only " + toString(aI)) + " node's address cab be passed")) |
---|
195 | | - | else { |
---|
196 | | - | func aJ (aK,ae) = { |
---|
197 | | - | let aL = aH[ae] |
---|
198 | | - | let an = o(aL) |
---|
199 | | - | let aM = getString(this, an) |
---|
200 | | - | if (!(isDefined(aM))) |
---|
201 | | - | then throw(("invalid Node in list " + aL)) |
---|
202 | | - | else { |
---|
203 | | - | let aN = split(value(aM), a) |
---|
204 | | - | let aO = aN[6] |
---|
205 | | - | if (if ((size(aN) >= 9)) |
---|
206 | | - | then (aO != "PENDING") |
---|
207 | | - | else false) |
---|
208 | | - | then throw(((("node " + aL) + " already has a final status ") + aO)) |
---|
209 | | - | else (aK :+ StringEntry(an, D(value(aM), "APPROVED"))) |
---|
210 | | - | } |
---|
211 | | - | } |
---|
212 | | - | |
---|
213 | | - | let aP = { |
---|
214 | | - | let aQ = aG |
---|
215 | | - | let aR = size(aQ) |
---|
216 | | - | let aS = nil |
---|
217 | | - | func aT (aU,aV) = if ((aV >= aR)) |
---|
218 | | - | then aU |
---|
219 | | - | else aJ(aU, aQ[aV]) |
---|
220 | | - | |
---|
221 | | - | func aW (aU,aV) = if ((aV >= aR)) |
---|
222 | | - | then aU |
---|
223 | | - | else throw("List size exceeds 8") |
---|
224 | | - | |
---|
225 | | - | aW(aT(aT(aT(aT(aT(aT(aT(aT(aS, 0), 1), 2), 3), 4), 5), 6), 7), 8) |
---|
226 | | - | } |
---|
227 | | - | $Tuple2(aP, nil) |
---|
228 | | - | } |
---|
229 | | - | } |
---|
230 | | - | |
---|
231 | | - | |
---|
232 | | - | |
---|
233 | | - | @Callable(ae) |
---|
234 | | - | func returnDeposit (I) = if ((size(ae.payments) != 0)) |
---|
235 | | - | then throw("No payments allowed") |
---|
236 | | - | else { |
---|
237 | | - | let aX = ae.caller |
---|
238 | | - | if (if ((aX != this)) |
---|
239 | | - | then (I != toString(aX)) |
---|
240 | | - | else false) |
---|
241 | | - | then throw("returnDeposit permissions denied") |
---|
242 | | - | else { |
---|
243 | | - | let an = o(I) |
---|
244 | | - | let aM = getString(this, an) |
---|
245 | | - | if (!(isDefined(aM))) |
---|
246 | | - | then throw(("Address is not applied as neutrino node: " + I)) |
---|
247 | | - | else { |
---|
248 | | - | let aN = split(value(aM), a) |
---|
249 | | - | let C = if ((size(aN) >= 9)) |
---|
250 | | - | then aN[6] |
---|
251 | | - | else "PENDING" |
---|
252 | | - | if ((C != "PENDING")) |
---|
253 | | - | then throw("Application status is not PENDING!") |
---|
254 | | - | else { |
---|
255 | | - | let aY = parseIntValue(aN[4]) |
---|
256 | | - | [DeleteEntry(an), ScriptTransfer(addressFromStringValue(I), aY, unit)] |
---|
257 | | - | } |
---|
258 | | - | } |
---|
259 | | - | } |
---|
260 | | - | } |
---|
261 | | - | |
---|
262 | | - | |
---|
| 1 | + | # no script |
---|