4 | | - | let li = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "55", "56"] |
---|
5 | | - | |
---|
6 | | - | let hours = 1 |
---|
7 | | - | |
---|
8 | | - | let minutes = 10 |
---|
9 | | - | |
---|
10 | | - | func tryGetInteger (key) = match getInteger(this, key) { |
---|
11 | | - | case b: Int => |
---|
12 | | - | b |
---|
13 | | - | case _ => |
---|
14 | | - | 0 |
---|
15 | | - | } |
---|
16 | | - | |
---|
17 | | - | |
---|
18 | | - | func tryGetString (key) = match getString(this, key) { |
---|
19 | | - | case b: String => |
---|
20 | | - | b |
---|
21 | | - | case _ => |
---|
22 | | - | "" |
---|
23 | | - | } |
---|
24 | | - | |
---|
25 | | - | |
---|
26 | | - | func getAssetString (assetId) = match assetId { |
---|
27 | | - | case b: ByteVector => |
---|
28 | | - | toBase58String(b) |
---|
29 | | - | case _ => |
---|
30 | | - | "WAVES" |
---|
31 | | - | } |
---|
32 | | - | |
---|
33 | | - | |
---|
34 | | - | func getAssetBytes (assetIdStr) = if ((assetIdStr == "WAVES")) |
---|
35 | | - | then unit |
---|
36 | | - | else fromBase58String(assetIdStr) |
---|
37 | | - | |
---|
38 | | - | |
---|
39 | | - | func payBoostingResult (boostingId) = { |
---|
40 | | - | let lastHeight = tryGetInteger((("boosting_" + boostingId) + "_lastHeight")) |
---|
41 | | - | let finishHeight = tryGetInteger((("boosting_" + boostingId) + "_finishHeight")) |
---|
42 | | - | if (if ((lastHeight != 0)) |
---|
43 | | - | then (finishHeight > lastHeight) |
---|
44 | | - | else false) |
---|
45 | | - | then { |
---|
46 | | - | let blockReward = (tryGetInteger((("boosting_" + boostingId) + "_totalAmount")) / ((tryGetInteger((("boosting_" + boostingId) + "_days")) * hours) * minutes)) |
---|
47 | | - | let toPay = fraction((min([finishHeight, height]) - lastHeight), blockReward, 1) |
---|
48 | | - | [IntegerEntry((("boosting_" + boostingId) + "_lastHeight"), height), ScriptTransfer(addressFromStringValue(tryGetString((("boosting_" + boostingId) + "_poolId"))), toPay, getAssetBytes(tryGetString((("boosting_" + boostingId) + "_assetId"))))] |
---|
49 | | - | } |
---|
50 | | - | else nil |
---|
| 4 | + | func randomizer (inv) = { |
---|
| 5 | + | let lastPlay = match getBinary(this, "lastPlay") { |
---|
| 6 | + | case s: ByteVector => |
---|
| 7 | + | s |
---|
| 8 | + | case _: Unit => |
---|
| 9 | + | base58'2ee4oFDYriWJ9EMeR' |
---|
| 10 | + | case _ => |
---|
| 11 | + | throw("Match error") |
---|
| 12 | + | } |
---|
| 13 | + | let rand = (((((lastPlay + inv.transactionId) + inv.callerPublicKey) + lastBlock.generationSignature) + toBytes(lastBlock.timestamp)) + toBytes(lastBlock.height)) |
---|
| 14 | + | sha256(rand) |
---|
64 | | - | func addBoosting (poolId,days) = if ((1 > days)) |
---|
65 | | - | then throw("amount of days has to be between 1 and 365") |
---|
66 | | - | else if ((days > 365)) |
---|
67 | | - | then throw("amount of days has to be between 1 and 365") |
---|
68 | | - | else if (if ((i.caller != this)) |
---|
69 | | - | then (i.caller != Address(base58'3N3y7nQfqDc7rBUExjKQi5ZbspWRh9q8PYH')) |
---|
70 | | - | else false) |
---|
71 | | - | then throw("under maintenance until further notice") |
---|
72 | | - | else { |
---|
73 | | - | let fullAmount = i.payments[0].amount |
---|
74 | | - | if ((1440 > (fullAmount / days))) |
---|
75 | | - | then throw((("boosting amount too small, minimum is " + toString((1440 * days))) + " of the smallest unit of payment asset")) |
---|
76 | | - | else { |
---|
77 | | - | let assetId = getAssetString(i.payments[0].assetId) |
---|
78 | | - | if ((height == tryGetInteger("height"))) |
---|
79 | | - | then throw("wait 1 minute") |
---|
80 | | - | else { |
---|
81 | | - | let entry = invoke(this, "entryEnded", nil, nil) |
---|
82 | | - | if ((entry == entry)) |
---|
83 | | - | then { |
---|
84 | | - | let get = invoke(this, "firstEndedBoostingId", nil, nil) |
---|
85 | | - | if ((get == get)) |
---|
86 | | - | then { |
---|
87 | | - | let boostingId = toString(tryGetInteger("first")) |
---|
88 | | - | if ((addressFromString(poolId) == unit)) |
---|
89 | | - | then throw("incorrect pool address") |
---|
90 | | - | else [IntegerEntry((("boosting_" + boostingId) + "_days"), days), IntegerEntry((("boosting_" + boostingId) + "_totalAmount"), fullAmount), IntegerEntry((("boosting_" + boostingId) + "_dailyAmount"), (fullAmount / days)), IntegerEntry((("boosting_" + boostingId) + "_startHeight"), height), IntegerEntry((("boosting_" + boostingId) + "_finishHeight"), (height + ((days * hours) * minutes))), IntegerEntry((("boosting_" + boostingId) + "_finishTimestamp"), (lastBlock.timestamp + ((((days * hours) * minutes) * 60) * 1000))), IntegerEntry((("boosting_" + boostingId) + "_lastHeight"), height), StringEntry((("boosting_" + boostingId) + "_assetId"), assetId), StringEntry((("boosting_" + boostingId) + "_owner"), toString(i.caller)), StringEntry((("boosting_" + boostingId) + "_poolId"), poolId), StringEntry((("pool_" + poolId) + "_boostings"), ((tryGetString((("pool_" + poolId) + "_boostings")) + boostingId) + ","))] |
---|
91 | | - | } |
---|
92 | | - | else throw("Strict value is not equal to itself.") |
---|
93 | | - | } |
---|
94 | | - | else throw("Strict value is not equal to itself.") |
---|
95 | | - | } |
---|
96 | | - | } |
---|
97 | | - | } |
---|
98 | | - | |
---|
99 | | - | |
---|
100 | | - | |
---|
101 | | - | @Callable(i) |
---|
102 | | - | func payBoosting (boostingId) = payBoostingResult(boostingId) |
---|
103 | | - | |
---|
104 | | - | |
---|
105 | | - | |
---|
106 | | - | @Callable(i) |
---|
107 | | - | func payBoostings () = { |
---|
108 | | - | func f (accum,next) = { |
---|
109 | | - | let in = invoke(this, "payBoosting", [next], nil) |
---|
110 | | - | if ((in == in)) |
---|
111 | | - | then in |
---|
112 | | - | else throw("Strict value is not equal to itself.") |
---|
113 | | - | } |
---|
114 | | - | |
---|
115 | | - | let payments = { |
---|
116 | | - | let $l = li |
---|
117 | | - | let $s = size($l) |
---|
118 | | - | let $acc0 = 0 |
---|
119 | | - | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
120 | | - | then $a |
---|
121 | | - | else f($a, $l[$i]) |
---|
122 | | - | |
---|
123 | | - | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
124 | | - | then $a |
---|
125 | | - | else throw("List size exceeds 56") |
---|
126 | | - | |
---|
127 | | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20), 21), 22), 23), 24), 25), 26), 27), 28), 29), 30), 31), 32), 33), 34), 35), 36), 37), 38), 39), 40), 41), 42), 43), 44), 45), 46), 47), 48), 49), 50), 51), 52), 53), 54), 55), 56) |
---|
128 | | - | } |
---|
129 | | - | if ((payments == payments)) |
---|
130 | | - | then nil |
---|
131 | | - | else throw("Strict value is not equal to itself.") |
---|
132 | | - | } |
---|
133 | | - | |
---|
134 | | - | |
---|
135 | | - | |
---|
136 | | - | @Callable(i) |
---|
137 | | - | func endedBoostings (boostingId) = endedBoostingIds(boostingId) |
---|
138 | | - | |
---|
139 | | - | |
---|
140 | | - | |
---|
141 | | - | @Callable(i) |
---|
142 | | - | func entryEnded () = { |
---|
143 | | - | func f (accum,next) = { |
---|
144 | | - | let in = invoke(this, "endedBoostings", [next], nil) |
---|
145 | | - | if ((in == in)) |
---|
146 | | - | then in |
---|
147 | | - | else throw("Strict value is not equal to itself.") |
---|
148 | | - | } |
---|
149 | | - | |
---|
150 | | - | let end = { |
---|
151 | | - | let $l = li |
---|
152 | | - | let $s = size($l) |
---|
153 | | - | let $acc0 = 0 |
---|
154 | | - | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
155 | | - | then $a |
---|
156 | | - | else f($a, $l[$i]) |
---|
157 | | - | |
---|
158 | | - | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
159 | | - | then $a |
---|
160 | | - | else throw("List size exceeds 56") |
---|
161 | | - | |
---|
162 | | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20), 21), 22), 23), 24), 25), 26), 27), 28), 29), 30), 31), 32), 33), 34), 35), 36), 37), 38), 39), 40), 41), 42), 43), 44), 45), 46), 47), 48), 49), 50), 51), 52), 53), 54), 55), 56) |
---|
163 | | - | } |
---|
164 | | - | if ((end == end)) |
---|
165 | | - | then [IntegerEntry("height", height)] |
---|
166 | | - | else throw("Strict value is not equal to itself.") |
---|
167 | | - | } |
---|
168 | | - | |
---|
169 | | - | |
---|
170 | | - | |
---|
171 | | - | @Callable(i) |
---|
172 | | - | func firstEndedBoostingId () = { |
---|
173 | | - | func fold (accum,next) = (accum :+ parseIntValue(next)) |
---|
174 | | - | |
---|
175 | | - | let StringValue = dropRight(tryGetString((("list ended " + toString(height)) + " boostingIds")), 1) |
---|
176 | | - | let list = { |
---|
177 | | - | let $l = split(StringValue, ",") |
---|
178 | | - | let $s = size($l) |
---|
179 | | - | let $acc0 = nil |
---|
180 | | - | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
181 | | - | then $a |
---|
182 | | - | else fold($a, $l[$i]) |
---|
183 | | - | |
---|
184 | | - | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
185 | | - | then $a |
---|
186 | | - | else throw("List size exceeds 56") |
---|
187 | | - | |
---|
188 | | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20), 21), 22), 23), 24), 25), 26), 27), 28), 29), 30), 31), 32), 33), 34), 35), 36), 37), 38), 39), 40), 41), 42), 43), 44), 45), 46), 47), 48), 49), 50), 51), 52), 53), 54), 55), 56) |
---|
189 | | - | } |
---|
190 | | - | let firstOfList = list[0] |
---|
191 | | - | [IntegerEntry("first", firstOfList)] |
---|
192 | | - | } |
---|
| 39 | + | func lotto () = startLotto(i) |
---|