tx · 7unJcCZVyZm6SqBpuxZpXytQpDRtU8N5Zr4DVZDnaqbX 3PKwLVb8jYk58oYbfXxs2dUjD3YEKeqGWrX: -0.01000000 Waves 2022.08.06 16:25 [3238191] smart account 3PKwLVb8jYk58oYbfXxs2dUjD3YEKeqGWrX > SELF 0.00000000 Waves
{ "type": 13, "id": "7unJcCZVyZm6SqBpuxZpXytQpDRtU8N5Zr4DVZDnaqbX", "fee": 1000000, "feeAssetId": null, "timestamp": 1659792385970, "version": 2, "chainId": 87, "sender": "3PKwLVb8jYk58oYbfXxs2dUjD3YEKeqGWrX", "senderPublicKey": "27DK15MykfnsVojpifD1gbr8kRr8rpY5mw6EH4zL8R25", "proofs": [ "4Q5HhPyVbQqCbem4t2b3EfJ8msMTgBfp3FysQwf3pGxB8xf9imDaDNPG3FApRCjYTwayuopAZk3Yq48QP98VLACo" ], "script": "base64:BgIUCAISAwoBCBIECgIICBIDCgEIEgAUARR0cnlHZXRTdHJpbmdFeHRlcm5hbAIHYWRkcmVzcwNrZXkEByRtYXRjaDAJAJ0IAgUHYWRkcmVzcwUDa2V5AwkAAQIFByRtYXRjaDACBlN0cmluZwQBYQUHJG1hdGNoMAUBYQIAARV0cnlHZXRJbnRlZ2VyRXh0ZXJuYWwCB2FkZHJlc3MDa2V5BAckbWF0Y2gwCQCaCAIFB2FkZHJlc3MFA2tleQMJAAECBQckbWF0Y2gwAgNJbnQEAWIFByRtYXRjaDAFAWIAAAEMdHJ5R2V0U3RyaW5nAQNrZXkJARR0cnlHZXRTdHJpbmdFeHRlcm5hbAIFBHRoaXMFA2tleQEJZ2V0T3JhY2xlAAkBB0FkZHJlc3MBCQDZBAEJAQx0cnlHZXRTdHJpbmcBAhRzdGF0aWNfb3JhY2xlQWRkcmVzcwEPZ2V0U3BpY2VBc3NldElkAAkA2QQBCQEUdHJ5R2V0U3RyaW5nRXh0ZXJuYWwCCQEJZ2V0T3JhY2xlAAITc3RhdGljX3NwaWNlQXNzZXRJZAERZ2V0QnJl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hbW91bnQpBANwbXQJAQV2YWx1ZQEJAOwHAQkBBXZhbHVlAQgJAQV2YWx1ZQEJAJEDAggFAWkIcGF5bWVudHMAAAdhc3NldElkAwkAZgIFDURVQ0tMSU5HUFJJQ0UJARJnZXRDdXJyZW50TGV2ZWxJbnQBCQDYBAEIBQNwbXQCaWQJAAIBAiFCVEQ6IER1Y2tsaW5nIGlzIG5vdCBncm93biB5ZXQuLi4DCQECIT0CCAUDcG10Bmlzc3VlcgUEdGhpcwkAAgECKkJURDogQ2FuIHVzZSBvbmx5IGR1Y2tsaW5ncyBmcm9tIHRoaXMgZEFwcAQOa0R1Y2tsaW5nR3Jvd24JARBrZXlEdWNrbGluZ0dyb3duAQkA2AQBCAUDcG10AmlkCQCUCgIJAMwIAgkBDEJvb2xlYW5FbnRyeQIFDmtEdWNrbGluZ0dyb3duBgkAzAgCCQEMSW50ZWdlckVudHJ5AgUWS0dsb2JhbElzc3VlZFRpbWVzdGFtcAgFCWxhc3RCbG9jawl0aW1lc3RhbXAFA25pbAkA2AQBCAUDcG10AmlkAQJ0eAEGdmVyaWZ5AAkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAgFAnR4D3NlbmRlclB1YmxpY0tleWgFTyg=", "height": 3238191, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 5hcy5S23Y4v6yYxDctGC2rgmiVz8d4Nj9Q8EtjHB2bdh Next: A5ZvWnF6C1S57RfcvR1syoWMUesuKzL318tPVdWDAHTp Diff:
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | func tryGetStringExternal (address,key) = match getString(address, key) { | |
23 | 23 | func getOracle () = Address(fromBase58String(tryGetString("static_oracleAddress"))) | |
24 | 24 | ||
25 | 25 | ||
26 | - | func getDucklingPrice () = tryGetIntegerExternal(getOracle(), "static_ducklingPrice") | |
27 | - | ||
28 | - | ||
29 | - | func getEggAssetId () = fromBase58String(tryGetStringExternal(getOracle(), "static_eggAssetId")) | |
30 | - | ||
31 | - | ||
32 | 26 | func getSpiceAssetId () = fromBase58String(tryGetStringExternal(getOracle(), "static_spiceAssetId")) | |
33 | 27 | ||
34 | 28 | ||
35 | - | func | |
29 | + | func getBreederAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_breederAddress"))) | |
36 | 30 | ||
37 | 31 | ||
38 | - | func getIncubatorAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_incubatorAddress"))) | |
39 | - | ||
40 | - | ||
41 | - | func getCouponsAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_couponsAddress"))) | |
42 | - | ||
43 | - | ||
44 | - | func getBurnAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_burnAddress"))) | |
45 | - | ||
46 | - | ||
47 | - | let backendPubKey = base58'BmKAXRQy7jZm44fa1YxNQDTcAwNSb74EpQwP5CT7UHdV' | |
48 | - | ||
49 | - | let STARTTIMESTAMP = 1632474000000 | |
50 | - | ||
51 | - | let LAPLENGTH = 21600000 | |
52 | - | ||
53 | - | let DUCKLINGPRICE = 80000000 | |
54 | - | ||
55 | - | let percentGrowthPrecision = 10000000000000000 | |
56 | - | ||
57 | - | let existingDuckPrecision = 100000000000000 | |
32 | + | let DUCKLINGPRICE = 1000000000000 | |
58 | 33 | ||
59 | 34 | let KGlobalIssuedTimestamp = "global_issued_timestamp" | |
60 | 35 | ||
61 | - | let MSINDAY = 86400000 | |
62 | - | ||
63 | 36 | func keyTotalFeed (ducklingId) = (("duckling_" + ducklingId) + "_feed") | |
64 | - | ||
65 | - | ||
66 | - | func keyDucklingFedLap (ducklingId) = (("duckling_" + ducklingId) + "_fedLap") | |
67 | - | ||
68 | - | ||
69 | - | func keyDucklingFedTimestamp (ducklingId) = (("duckling_" + ducklingId) + "_fedTs") | |
70 | - | ||
71 | - | ||
72 | - | func keyDucklingFedLapTimestamp (ducklingId,lap) = (((("duckling_" + ducklingId) + "_lap_") + toString(lap)) + "_fedTs") | |
73 | - | ||
74 | - | ||
75 | - | func keyAddressFedTimestamp (address,lap,timestamp) = ((((("address_" + address) + "_lap_") + toString(lap)) + "_fedTs_") + toString(timestamp)) | |
76 | - | ||
77 | - | ||
78 | - | func keyAddressNonce (address) = (("address_" + address) + "_nonce") | |
79 | 37 | ||
80 | 38 | ||
81 | 39 | func keyDucklingFedLastTimestamp (ducklingId) = (("duckling_" + ducklingId) + "_fedLastTs") | |
84 | 42 | func keyDucklingLevel (ducklingId) = (("duckling_" + ducklingId) + "_level") | |
85 | 43 | ||
86 | 44 | ||
87 | - | func keyFeedForLap (address,lap) = (((("address_" + address) + "_lap_") + toString(lap)) + "_feed") | |
88 | - | ||
89 | - | ||
90 | 45 | func keyDucklingGrown (ducklingId) = (("duckling_" + ducklingId) + "_grown") | |
91 | - | ||
92 | - | ||
93 | - | func keyStartHatchingId (ducklingId) = (("duckling_" + ducklingId) + "_grown") | |
94 | 46 | ||
95 | 47 | ||
96 | 48 | func keyStartPercentage (ducklingId) = (("duckling_" + ducklingId) + "_startPercentage") | |
118 | 70 | } | |
119 | 71 | ||
120 | 72 | ||
121 | - | func getDucklingPercentage (ducklingId) = { | |
122 | - | let percentageDuckling = tryGetInteger(keyStartPercentage(ducklingId)) | |
123 | - | let base = if ((percentageDuckling != 0)) | |
124 | - | then percentageDuckling | |
125 | - | else 20 | |
126 | - | toBigInt((base * existingDuckPrecision)) | |
127 | - | } | |
128 | - | ||
129 | - | ||
130 | - | func getCurrentLevelBigInt (ducklingId) = { | |
73 | + | func getCurrentLevelInt (ducklingId) = { | |
131 | 74 | let kDuckLevel = keyDucklingLevel(ducklingId) | |
132 | 75 | match getString(kDuckLevel) { | |
133 | 76 | case s: String => | |
134 | - | | |
77 | + | parseIntValue(s) | |
135 | 78 | case _ => | |
136 | - | match getBoolean((("duckling_" + ducklingId) + "_issuedByFeedCall")) { | |
137 | - | case b: Boolean => | |
138 | - | if ((b == true)) | |
139 | - | then toBigInt(0) | |
140 | - | else getDucklingPercentage(ducklingId) | |
141 | - | case _ => | |
142 | - | getDucklingPercentage(ducklingId) | |
143 | - | } | |
79 | + | throw("BGCLBI: Weird value detected!") | |
144 | 80 | } | |
145 | 81 | } | |
146 | - | ||
147 | - | ||
148 | - | func getCurrentLap () = (((lastBlock.timestamp - STARTTIMESTAMP) / LAPLENGTH) + 1) | |
149 | 82 | ||
150 | 83 | ||
151 | 84 | func getLastFedTimestamp (ducklingId) = { | |
160 | 93 | let currentTs = lastBlock.timestamp | |
161 | 94 | let lastFedTimestampChecked = getLastFedTimestamp(ducklingId) | |
162 | 95 | let fedDiff = (currentTs - lastFedTimestampChecked) | |
163 | - | let penalty = toBigInt(0) | |
164 | - | let growth = fraction(toBigInt(paymentAmount), toBigInt(percentGrowthPrecision), toBigInt(DUCKLINGPRICE)) | |
165 | - | let currentLevel = getCurrentLevelBigInt(ducklingId) | |
166 | - | let newLevel = ((currentLevel - penalty) + growth) | |
167 | - | let result = if ((toBigInt(0) > newLevel)) | |
168 | - | then toString(growth) | |
169 | - | else toString(newLevel) | |
170 | - | $Tuple2(result, [("currentLevel=" + toString(currentLevel)), ("newLevel=" + toString(newLevel)), ("growth=" + toString(growth)), ("penalty=" + toString(penalty)), ("lastFedTs=" + toString(lastFedTimestampChecked)), ("fedDiff=" + toString(fedDiff))]) | |
96 | + | let growth = paymentAmount | |
97 | + | let currentLevel = getCurrentLevelInt(ducklingId) | |
98 | + | let newLevel = (currentLevel + paymentAmount) | |
99 | + | if ((newLevel >= DUCKLINGPRICE)) | |
100 | + | then throw((("CBDB: You are feeding your duckling to much! Only " + toString((DUCKLINGPRICE - currentLevel))) + "needed!")) | |
101 | + | else { | |
102 | + | let result = toString(newLevel) | |
103 | + | $Tuple2(result, [("currentLevel=" + toString(currentLevel)), ("newLevel=" + toString(newLevel)), ("growth=" + toString(growth)), ("lastFedTs=" + toString(lastFedTimestampChecked)), ("fedDiff=" + toString(fedDiff))]) | |
104 | + | } | |
171 | 105 | } | |
172 | - | ||
173 | - | ||
174 | - | func getBackendProof (maxFeedAmount,userNonce,address) = makeString([toString(maxFeedAmount), toString(userNonce), address], ";") | |
175 | 106 | ||
176 | 107 | ||
177 | 108 | func asInt (value) = match value { | |
190 | 121 | ||
191 | 122 | ||
192 | 123 | @Callable(i) | |
193 | - | func buyDuckling () = { | |
194 | - | let exactPrice = getDucklingPrice() | |
195 | - | if ((50000000 > exactPrice)) | |
196 | - | then throw("BBD: Invalid price from oracle!") | |
197 | - | else { | |
198 | - | let amountPaidByCoupons = asInt(invoke(getCouponsAddress(), "useCoupons", [exactPrice], nil)) | |
199 | - | if ((amountPaidByCoupons == amountPaidByCoupons)) | |
200 | - | then { | |
201 | - | let leftToPay = (exactPrice - amountPaidByCoupons) | |
202 | - | let payment = if ((leftToPay != 0)) | |
203 | - | then { | |
204 | - | let firstPayment = value(i.payments[0]) | |
205 | - | if ((firstPayment.assetId != getEggAssetId())) | |
206 | - | then throw(("BBD: You can attach only EGG tokens with the following asset id: " + toBase58String(getEggAssetId()))) | |
207 | - | else if ((firstPayment.amount != leftToPay)) | |
208 | - | then throw(("BBD: To buy a perch you currently need the following amount of EGGlets: " + toString(leftToPay))) | |
209 | - | else { | |
210 | - | let burnCall = invoke(getBurnAddress(), "burnAttachedPayments", nil, [AttachedPayment(getEggAssetId(), leftToPay)]) | |
211 | - | if ((burnCall == burnCall)) | |
212 | - | then leftToPay | |
213 | - | else throw("Strict value is not equal to itself.") | |
214 | - | } | |
215 | - | } | |
216 | - | else 0 | |
217 | - | if ((payment == payment)) | |
218 | - | then { | |
219 | - | let ducklingAssetId = invoke(this, "issueFreeDuckling", [toString(i.originCaller), toBase58String(i.transactionId), 0], nil) | |
220 | - | if ((ducklingAssetId == ducklingAssetId)) | |
221 | - | then nil | |
222 | - | else throw("Strict value is not equal to itself.") | |
223 | - | } | |
224 | - | else throw("Strict value is not equal to itself.") | |
124 | + | func issueDuckling (address,txIdStr) = if ((i.caller != getBreederAddress())) | |
125 | + | then throw("BIFD: You can't issue free duckling") | |
126 | + | else { | |
127 | + | let asset = Issue("BABY-11111111-HZ", "", 1, 0, false, unit, height) | |
128 | + | let assetId = calculateAssetId(asset) | |
129 | + | $Tuple2([StringEntry((((address + "_") + txIdStr) + "_di"), toBase58String(assetId)), IntegerEntry("stats_amount", (tryGetInteger("stats_amount") + 1)), BooleanEntry((("duckling_" + toBase58String(assetId)) + "_issuedByFeedCall"), (i.caller == this)), IntegerEntry(keyStartPercentage(toBase58String(assetId)), 0), StringEntry(keyOwner(toBase58String(assetId)), address), asset, ScriptTransfer(value(addressFromString(address)), 1, assetId)], toBase58String(assetId)) | |
130 | + | } | |
131 | + | ||
132 | + | ||
133 | + | ||
134 | + | @Callable(i) | |
135 | + | func feedDuckling (ducklingId) = { | |
136 | + | let addressString = toString(i.caller) | |
137 | + | let realDucklingId = if (if ((size(i.payments) != 1)) | |
138 | + | then true | |
139 | + | else (value(i.payments[0]).assetId != getSpiceAssetId())) | |
140 | + | then throw("BFD: Bad payment attached (asset[s] or amount)") | |
141 | + | else if (getBool(keyDucklingGrown(ducklingId))) | |
142 | + | then throw("BFD: Duckling is already grown") | |
143 | + | else if ((ducklingId == "")) | |
144 | + | then throw("BFD: Please hatch a duckling first!") | |
145 | + | else { | |
146 | + | let ducklingOwner = tryGetString(keyOwner(ducklingId)) | |
147 | + | let ducklingIdCheck = value(assetInfo(fromBase58String(ducklingId))) | |
148 | + | if ((assetBalance(i.caller, ducklingIdCheck.id) != 1)) | |
149 | + | then throw("BFD: You're not the owner of the duckling") | |
150 | + | else if ((ducklingOwner != toString(i.caller))) | |
151 | + | then throw("BFD: You can only feed ducklings that you won/bought yourself!") | |
152 | + | else if ((ducklingIdCheck.issuer != this)) | |
153 | + | then throw("BFD: Cant find duckling with such id") | |
154 | + | else { | |
155 | + | let ducklingIdString = toBase58String(ducklingIdCheck.id) | |
156 | + | ducklingIdString | |
157 | + | } | |
225 | 158 | } | |
226 | - | else throw("Strict value is not equal to itself.") | |
227 | - | } | |
159 | + | let kDucklingLastFedTs = keyDucklingFedLastTimestamp(ducklingId) | |
160 | + | let currentPayment = value(i.payments[0]).amount | |
161 | + | let kNewLevel = keyDucklingLevel(realDucklingId) | |
162 | + | let kTotalFeed = keyTotalFeed(realDucklingId) | |
163 | + | let totalFeed = tryGetInteger(kTotalFeed) | |
164 | + | let kFeedTxStats = ((("duckling_" + realDucklingId) + "_stat_") + toString(lastBlock.timestamp)) | |
165 | + | let calculateResults = calculateNewDucklingLevel(realDucklingId, currentPayment) | |
166 | + | [IntegerEntry(kDucklingLastFedTs, lastBlock.timestamp), IntegerEntry(kTotalFeed, (totalFeed + currentPayment)), IntegerEntry(kFeedTxStats, currentPayment), StringEntry(kNewLevel, calculateResults._1), StringEntry((kFeedTxStats + "_debug"), makeString(calculateResults._2, ";"))] | |
228 | 167 | } | |
229 | 168 | ||
230 | 169 | ||
231 | 170 | ||
232 | 171 | @Callable(i) | |
233 | - | func issueFreeDuckling (address,txIdStr,percentage) = if (if ((i.caller != this)) | |
234 | - | then (i.caller != getRebirthAddress()) | |
235 | - | else false) | |
236 | - | then throw("BIFD: You can't issue free duckling") | |
172 | + | func turnDucklingIntoDuck () = if ((i.caller != getBreederAddress())) | |
173 | + | then throw("BIFD: You can't turn duckling") | |
237 | 174 | else { | |
238 | - | let asset = Issue("BABY-11111111-GZ", "", 1, 0, false, unit, height) | |
239 | - | let assetId = calculateAssetId(asset) | |
240 | - | $Tuple2([StringEntry((((address + "_") + txIdStr) + "_di"), toBase58String(assetId)), IntegerEntry("stats_amount", (tryGetInteger("stats_amount") + 1)), BooleanEntry((("duckling_" + toBase58String(assetId)) + "_issuedByFeedCall"), (i.caller == this)), IntegerEntry(keyStartPercentage(toBase58String(assetId)), percentage), StringEntry(keyOwner(toBase58String(assetId)), address), asset, ScriptTransfer(value(addressFromString(address)), 1, assetId)], toBase58String(assetId)) | |
175 | + | let address = toString(i.caller) | |
176 | + | let txId = toBase58String(i.transactionId) | |
177 | + | let lastIssuedDucklingTs = tryGetInteger(KGlobalIssuedTimestamp) | |
178 | + | let fiveMinInMs = ((1 * 60) * 1000) | |
179 | + | let timeDiff = (lastBlock.timestamp - (lastIssuedDucklingTs + fiveMinInMs)) | |
180 | + | if (if ((lastIssuedDucklingTs > 0)) | |
181 | + | then (0 > timeDiff) | |
182 | + | else false) | |
183 | + | then throw((("BTD: Can issue ducklings only once per 1 minutes, please wait for " + toString(fraction(timeDiff, 1, 1000))) + " sec.")) | |
184 | + | else if ((size(i.payments) != 1)) | |
185 | + | then throw("BTD: Bad payment attached (asset[s] or amount)") | |
186 | + | else { | |
187 | + | let pmt = value(assetInfo(value(value(i.payments[0]).assetId))) | |
188 | + | if ((DUCKLINGPRICE > getCurrentLevelInt(toBase58String(pmt.id)))) | |
189 | + | then throw("BTD: Duckling is not grown yet...") | |
190 | + | else if ((pmt.issuer != this)) | |
191 | + | then throw("BTD: Can use only ducklings from this dApp") | |
192 | + | else { | |
193 | + | let kDucklingGrown = keyDucklingGrown(toBase58String(pmt.id)) | |
194 | + | $Tuple2([BooleanEntry(kDucklingGrown, true), IntegerEntry(KGlobalIssuedTimestamp, lastBlock.timestamp)], toBase58String(pmt.id)) | |
195 | + | } | |
196 | + | } | |
241 | 197 | } | |
242 | - | ||
243 | - | ||
244 | - | ||
245 | - | @Callable(i) | |
246 | - | func feedDuckling (ducklingId,backendSignature,maxFeedAmount,userNonce) = { | |
247 | - | let addressString = toString(i.caller) | |
248 | - | let backendProof = getBackendProof(maxFeedAmount, userNonce, addressString) | |
249 | - | let kAddressNonce = keyAddressNonce(addressString) | |
250 | - | let currentNonce = tryGetInteger(kAddressNonce) | |
251 | - | let realDucklingId = if (!(sigVerify_8Kb(toBytes(backendProof), fromBase58String(backendSignature), backendPubKey))) | |
252 | - | then throw("BFD: Invalid proof from backend") | |
253 | - | else if (if ((size(i.payments) != 1)) | |
254 | - | then true | |
255 | - | else (value(i.payments[0]).assetId != getSpiceAssetId())) | |
256 | - | then throw("BFD: Bad payment attached (asset[s] or amount)") | |
257 | - | else if (getBool(keyDucklingGrown(ducklingId))) | |
258 | - | then throw("BFD: Duckling is already grown") | |
259 | - | else if ((userNonce != (currentNonce + 1))) | |
260 | - | then throw(((("BFD: User Nonce should be " + toString(currentNonce)) + " + 1, while received ") + toString(userNonce))) | |
261 | - | else if ((ducklingId == "")) | |
262 | - | then throw("BFD: Please buy a duckling first!") | |
263 | - | else { | |
264 | - | let ducklingOwner = tryGetString(keyOwner(ducklingId)) | |
265 | - | let ducklingIdCheck = value(assetInfo(fromBase58String(ducklingId))) | |
266 | - | if ((assetBalance(i.caller, ducklingIdCheck.id) != 1)) | |
267 | - | then throw("BFD: You're not the owner of the duckling") | |
268 | - | else if ((ducklingOwner != toString(i.caller))) | |
269 | - | then throw("BFD: You can only feed ducklings that you won/bought yourself!") | |
270 | - | else if ((ducklingIdCheck.issuer != this)) | |
271 | - | then throw("BFD: Cant find duckling with such id") | |
272 | - | else { | |
273 | - | let ducklingIdString = toBase58String(ducklingIdCheck.id) | |
274 | - | ducklingIdString | |
275 | - | } | |
276 | - | } | |
277 | - | let kDucklingLastFedTs = keyDucklingFedLastTimestamp(ducklingId) | |
278 | - | let lastFedTs = getLastFedTimestamp(realDucklingId) | |
279 | - | let currentPayment = value(i.payments[0]).amount | |
280 | - | let kNewLevel = keyDucklingLevel(realDucklingId) | |
281 | - | let kTotalFeed = keyTotalFeed(realDucklingId) | |
282 | - | let totalFeed = tryGetInteger(kTotalFeed) | |
283 | - | let kFeedTxStats = ((("duckling_" + realDucklingId) + "_stat_") + toString(lastBlock.timestamp)) | |
284 | - | let kAddressFedTimestamp = keyAddressFedTimestamp(addressString, getCurrentLap(), lastBlock.timestamp) | |
285 | - | let kDucklingFedLapTimestamp = keyDucklingFedLapTimestamp(realDucklingId, getCurrentLap()) | |
286 | - | let kDucklingFedLap = keyDucklingFedLap(realDucklingId) | |
287 | - | if ((currentPayment > maxFeedAmount)) | |
288 | - | then throw(("BFD: Cannot feed duckling for such amount, max feed amount is: " + toString(maxFeedAmount))) | |
289 | - | else { | |
290 | - | let calculateResults = calculateNewDucklingLevel(realDucklingId, (currentPayment / 100)) | |
291 | - | [IntegerEntry(kAddressNonce, (currentNonce + 1)), IntegerEntry(kDucklingLastFedTs, lastBlock.timestamp), IntegerEntry(kTotalFeed, (totalFeed + currentPayment)), IntegerEntry(kFeedTxStats, currentPayment), IntegerEntry(kAddressFedTimestamp, currentPayment), IntegerEntry(kDucklingFedLapTimestamp, currentPayment), IntegerEntry(kDucklingFedLap, getCurrentLap()), StringEntry(kNewLevel, calculateResults._1), StringEntry((kFeedTxStats + "_debug"), makeString(calculateResults._2, ";"))] | |
292 | - | } | |
293 | - | } | |
294 | - | ||
295 | - | ||
296 | - | ||
297 | - | @Callable(i) | |
298 | - | func fixLevels (ducklingIds) = if (if ((i.callerPublicKey != base58'GDxBbsDRmeY39quNrDsTXKJzFWbQVtjxHseF4ikxZ7n9')) | |
299 | - | then (i.caller != this) | |
300 | - | else false) | |
301 | - | then throw("BFL: Not authorized") | |
302 | - | else { | |
303 | - | let ducklingIdsList = value(split(ducklingIds, ",")) | |
304 | - | func handleId (acc,id) = { | |
305 | - | let kTotalFeed = keyTotalFeed(id) | |
306 | - | let totalFeed = tryGetInteger(kTotalFeed) | |
307 | - | let kNewLevel = keyDucklingLevel(id) | |
308 | - | let startingLevel = match getBoolean((("duckling_" + id) + "_issuedByFeedCall")) { | |
309 | - | case b: Boolean => | |
310 | - | if ((b == true)) | |
311 | - | then toBigInt(0) | |
312 | - | else getDucklingPercentage(id) | |
313 | - | case _ => | |
314 | - | getDucklingPercentage(id) | |
315 | - | } | |
316 | - | let growth = fraction(toBigInt(totalFeed), toBigInt(percentGrowthPrecision), toBigInt(DUCKLINGPRICE)) | |
317 | - | (acc ++ [StringEntry(kNewLevel, toString((startingLevel + growth)))]) | |
318 | - | } | |
319 | - | ||
320 | - | let $l = ducklingIdsList | |
321 | - | let $s = size($l) | |
322 | - | let $acc0 = nil | |
323 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
324 | - | then $a | |
325 | - | else handleId($a, $l[$i]) | |
326 | - | ||
327 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
328 | - | then $a | |
329 | - | else throw("List size exceeds 20") | |
330 | - | ||
331 | - | $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($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20) | |
332 | - | } | |
333 | - | ||
334 | - | ||
335 | - | ||
336 | - | @Callable(i) | |
337 | - | func turnDucklingIntoDuck () = { | |
338 | - | let address = toString(i.caller) | |
339 | - | let txId = toBase58String(i.transactionId) | |
340 | - | let lastIssuedDucklingTs = tryGetInteger(KGlobalIssuedTimestamp) | |
341 | - | let fiveMinInMs = ((5 * 60) * 1000) | |
342 | - | let timeDiff = (lastBlock.timestamp - (lastIssuedDucklingTs + fiveMinInMs)) | |
343 | - | if (if ((lastIssuedDucklingTs > 0)) | |
344 | - | then (0 > timeDiff) | |
345 | - | else false) | |
346 | - | then throw((("BTD: Can issue ducklings only once per 5 minutes, please wait for " + toString(fraction(timeDiff, 1, 1000))) + " sec.")) | |
347 | - | else if ((size(i.payments) != 1)) | |
348 | - | then throw("BTD: Bad payment attached (asset[s] or amount)") | |
349 | - | else { | |
350 | - | let pmt = value(assetInfo(value(value(i.payments[0]).assetId))) | |
351 | - | if ((toBigInt(100) > getCurrentLevelBigInt(toBase58String(pmt.id)))) | |
352 | - | then throw("BTD: Duckling is not grown yet...") | |
353 | - | else if ((pmt.issuer != this)) | |
354 | - | then throw("BTD: Can use only ducklings from this dApp") | |
355 | - | else { | |
356 | - | let call = invoke(getIncubatorAddress(), "startDuckHatching", [""], nil) | |
357 | - | if ((call == call)) | |
358 | - | then { | |
359 | - | let kDucklingGrown = keyDucklingGrown(toBase58String(pmt.id)) | |
360 | - | [BooleanEntry(kDucklingGrown, true), IntegerEntry(KGlobalIssuedTimestamp, lastBlock.timestamp)] | |
361 | - | } | |
362 | - | else throw("Strict value is not equal to itself.") | |
363 | - | } | |
364 | - | } | |
365 | - | } | |
366 | 198 | ||
367 | 199 | ||
368 | 200 | @Verifier(tx) |
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | func tryGetStringExternal (address,key) = match getString(address, key) { | |
5 | 5 | case a: String => | |
6 | 6 | a | |
7 | 7 | case _ => | |
8 | 8 | "" | |
9 | 9 | } | |
10 | 10 | ||
11 | 11 | ||
12 | 12 | func tryGetIntegerExternal (address,key) = match getInteger(address, key) { | |
13 | 13 | case b: Int => | |
14 | 14 | b | |
15 | 15 | case _ => | |
16 | 16 | 0 | |
17 | 17 | } | |
18 | 18 | ||
19 | 19 | ||
20 | 20 | func tryGetString (key) = tryGetStringExternal(this, key) | |
21 | 21 | ||
22 | 22 | ||
23 | 23 | func getOracle () = Address(fromBase58String(tryGetString("static_oracleAddress"))) | |
24 | 24 | ||
25 | 25 | ||
26 | - | func getDucklingPrice () = tryGetIntegerExternal(getOracle(), "static_ducklingPrice") | |
27 | - | ||
28 | - | ||
29 | - | func getEggAssetId () = fromBase58String(tryGetStringExternal(getOracle(), "static_eggAssetId")) | |
30 | - | ||
31 | - | ||
32 | 26 | func getSpiceAssetId () = fromBase58String(tryGetStringExternal(getOracle(), "static_spiceAssetId")) | |
33 | 27 | ||
34 | 28 | ||
35 | - | func | |
29 | + | func getBreederAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_breederAddress"))) | |
36 | 30 | ||
37 | 31 | ||
38 | - | func getIncubatorAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_incubatorAddress"))) | |
39 | - | ||
40 | - | ||
41 | - | func getCouponsAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_couponsAddress"))) | |
42 | - | ||
43 | - | ||
44 | - | func getBurnAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_burnAddress"))) | |
45 | - | ||
46 | - | ||
47 | - | let backendPubKey = base58'BmKAXRQy7jZm44fa1YxNQDTcAwNSb74EpQwP5CT7UHdV' | |
48 | - | ||
49 | - | let STARTTIMESTAMP = 1632474000000 | |
50 | - | ||
51 | - | let LAPLENGTH = 21600000 | |
52 | - | ||
53 | - | let DUCKLINGPRICE = 80000000 | |
54 | - | ||
55 | - | let percentGrowthPrecision = 10000000000000000 | |
56 | - | ||
57 | - | let existingDuckPrecision = 100000000000000 | |
32 | + | let DUCKLINGPRICE = 1000000000000 | |
58 | 33 | ||
59 | 34 | let KGlobalIssuedTimestamp = "global_issued_timestamp" | |
60 | 35 | ||
61 | - | let MSINDAY = 86400000 | |
62 | - | ||
63 | 36 | func keyTotalFeed (ducklingId) = (("duckling_" + ducklingId) + "_feed") | |
64 | - | ||
65 | - | ||
66 | - | func keyDucklingFedLap (ducklingId) = (("duckling_" + ducklingId) + "_fedLap") | |
67 | - | ||
68 | - | ||
69 | - | func keyDucklingFedTimestamp (ducklingId) = (("duckling_" + ducklingId) + "_fedTs") | |
70 | - | ||
71 | - | ||
72 | - | func keyDucklingFedLapTimestamp (ducklingId,lap) = (((("duckling_" + ducklingId) + "_lap_") + toString(lap)) + "_fedTs") | |
73 | - | ||
74 | - | ||
75 | - | func keyAddressFedTimestamp (address,lap,timestamp) = ((((("address_" + address) + "_lap_") + toString(lap)) + "_fedTs_") + toString(timestamp)) | |
76 | - | ||
77 | - | ||
78 | - | func keyAddressNonce (address) = (("address_" + address) + "_nonce") | |
79 | 37 | ||
80 | 38 | ||
81 | 39 | func keyDucklingFedLastTimestamp (ducklingId) = (("duckling_" + ducklingId) + "_fedLastTs") | |
82 | 40 | ||
83 | 41 | ||
84 | 42 | func keyDucklingLevel (ducklingId) = (("duckling_" + ducklingId) + "_level") | |
85 | 43 | ||
86 | 44 | ||
87 | - | func keyFeedForLap (address,lap) = (((("address_" + address) + "_lap_") + toString(lap)) + "_feed") | |
88 | - | ||
89 | - | ||
90 | 45 | func keyDucklingGrown (ducklingId) = (("duckling_" + ducklingId) + "_grown") | |
91 | - | ||
92 | - | ||
93 | - | func keyStartHatchingId (ducklingId) = (("duckling_" + ducklingId) + "_grown") | |
94 | 46 | ||
95 | 47 | ||
96 | 48 | func keyStartPercentage (ducklingId) = (("duckling_" + ducklingId) + "_startPercentage") | |
97 | 49 | ||
98 | 50 | ||
99 | 51 | func keyOwner (ducklingId) = (("duckling_" + ducklingId) + "_owner") | |
100 | 52 | ||
101 | 53 | ||
102 | 54 | func tryGetInteger (key) = { | |
103 | 55 | let val = match getInteger(this, key) { | |
104 | 56 | case b: Int => | |
105 | 57 | b | |
106 | 58 | case _ => | |
107 | 59 | 0 | |
108 | 60 | } | |
109 | 61 | val | |
110 | 62 | } | |
111 | 63 | ||
112 | 64 | ||
113 | 65 | func getBool (key) = match getBoolean(this, key) { | |
114 | 66 | case b: Boolean => | |
115 | 67 | b | |
116 | 68 | case _ => | |
117 | 69 | false | |
118 | 70 | } | |
119 | 71 | ||
120 | 72 | ||
121 | - | func getDucklingPercentage (ducklingId) = { | |
122 | - | let percentageDuckling = tryGetInteger(keyStartPercentage(ducklingId)) | |
123 | - | let base = if ((percentageDuckling != 0)) | |
124 | - | then percentageDuckling | |
125 | - | else 20 | |
126 | - | toBigInt((base * existingDuckPrecision)) | |
127 | - | } | |
128 | - | ||
129 | - | ||
130 | - | func getCurrentLevelBigInt (ducklingId) = { | |
73 | + | func getCurrentLevelInt (ducklingId) = { | |
131 | 74 | let kDuckLevel = keyDucklingLevel(ducklingId) | |
132 | 75 | match getString(kDuckLevel) { | |
133 | 76 | case s: String => | |
134 | - | | |
77 | + | parseIntValue(s) | |
135 | 78 | case _ => | |
136 | - | match getBoolean((("duckling_" + ducklingId) + "_issuedByFeedCall")) { | |
137 | - | case b: Boolean => | |
138 | - | if ((b == true)) | |
139 | - | then toBigInt(0) | |
140 | - | else getDucklingPercentage(ducklingId) | |
141 | - | case _ => | |
142 | - | getDucklingPercentage(ducklingId) | |
143 | - | } | |
79 | + | throw("BGCLBI: Weird value detected!") | |
144 | 80 | } | |
145 | 81 | } | |
146 | - | ||
147 | - | ||
148 | - | func getCurrentLap () = (((lastBlock.timestamp - STARTTIMESTAMP) / LAPLENGTH) + 1) | |
149 | 82 | ||
150 | 83 | ||
151 | 84 | func getLastFedTimestamp (ducklingId) = { | |
152 | 85 | let lastFedTimestamp = tryGetInteger(keyDucklingFedLastTimestamp(ducklingId)) | |
153 | 86 | if ((lastFedTimestamp > 0)) | |
154 | 87 | then lastFedTimestamp | |
155 | 88 | else lastBlock.timestamp | |
156 | 89 | } | |
157 | 90 | ||
158 | 91 | ||
159 | 92 | func calculateNewDucklingLevel (ducklingId,paymentAmount) = { | |
160 | 93 | let currentTs = lastBlock.timestamp | |
161 | 94 | let lastFedTimestampChecked = getLastFedTimestamp(ducklingId) | |
162 | 95 | let fedDiff = (currentTs - lastFedTimestampChecked) | |
163 | - | let penalty = toBigInt(0) | |
164 | - | let growth = fraction(toBigInt(paymentAmount), toBigInt(percentGrowthPrecision), toBigInt(DUCKLINGPRICE)) | |
165 | - | let currentLevel = getCurrentLevelBigInt(ducklingId) | |
166 | - | let newLevel = ((currentLevel - penalty) + growth) | |
167 | - | let result = if ((toBigInt(0) > newLevel)) | |
168 | - | then toString(growth) | |
169 | - | else toString(newLevel) | |
170 | - | $Tuple2(result, [("currentLevel=" + toString(currentLevel)), ("newLevel=" + toString(newLevel)), ("growth=" + toString(growth)), ("penalty=" + toString(penalty)), ("lastFedTs=" + toString(lastFedTimestampChecked)), ("fedDiff=" + toString(fedDiff))]) | |
96 | + | let growth = paymentAmount | |
97 | + | let currentLevel = getCurrentLevelInt(ducklingId) | |
98 | + | let newLevel = (currentLevel + paymentAmount) | |
99 | + | if ((newLevel >= DUCKLINGPRICE)) | |
100 | + | then throw((("CBDB: You are feeding your duckling to much! Only " + toString((DUCKLINGPRICE - currentLevel))) + "needed!")) | |
101 | + | else { | |
102 | + | let result = toString(newLevel) | |
103 | + | $Tuple2(result, [("currentLevel=" + toString(currentLevel)), ("newLevel=" + toString(newLevel)), ("growth=" + toString(growth)), ("lastFedTs=" + toString(lastFedTimestampChecked)), ("fedDiff=" + toString(fedDiff))]) | |
104 | + | } | |
171 | 105 | } | |
172 | - | ||
173 | - | ||
174 | - | func getBackendProof (maxFeedAmount,userNonce,address) = makeString([toString(maxFeedAmount), toString(userNonce), address], ";") | |
175 | 106 | ||
176 | 107 | ||
177 | 108 | func asInt (value) = match value { | |
178 | 109 | case int: Int => | |
179 | 110 | int | |
180 | 111 | case _ => | |
181 | 112 | throw("BAI: wrong type, expected: Int") | |
182 | 113 | } | |
183 | 114 | ||
184 | 115 | ||
185 | 116 | @Callable(i) | |
186 | 117 | func configureOracle (oracle) = if ((i.caller != this)) | |
187 | 118 | then throw("BCO: admin only") | |
188 | 119 | else [StringEntry("static_oracleAddress", oracle)] | |
189 | 120 | ||
190 | 121 | ||
191 | 122 | ||
192 | 123 | @Callable(i) | |
193 | - | func buyDuckling () = { | |
194 | - | let exactPrice = getDucklingPrice() | |
195 | - | if ((50000000 > exactPrice)) | |
196 | - | then throw("BBD: Invalid price from oracle!") | |
197 | - | else { | |
198 | - | let amountPaidByCoupons = asInt(invoke(getCouponsAddress(), "useCoupons", [exactPrice], nil)) | |
199 | - | if ((amountPaidByCoupons == amountPaidByCoupons)) | |
200 | - | then { | |
201 | - | let leftToPay = (exactPrice - amountPaidByCoupons) | |
202 | - | let payment = if ((leftToPay != 0)) | |
203 | - | then { | |
204 | - | let firstPayment = value(i.payments[0]) | |
205 | - | if ((firstPayment.assetId != getEggAssetId())) | |
206 | - | then throw(("BBD: You can attach only EGG tokens with the following asset id: " + toBase58String(getEggAssetId()))) | |
207 | - | else if ((firstPayment.amount != leftToPay)) | |
208 | - | then throw(("BBD: To buy a perch you currently need the following amount of EGGlets: " + toString(leftToPay))) | |
209 | - | else { | |
210 | - | let burnCall = invoke(getBurnAddress(), "burnAttachedPayments", nil, [AttachedPayment(getEggAssetId(), leftToPay)]) | |
211 | - | if ((burnCall == burnCall)) | |
212 | - | then leftToPay | |
213 | - | else throw("Strict value is not equal to itself.") | |
214 | - | } | |
215 | - | } | |
216 | - | else 0 | |
217 | - | if ((payment == payment)) | |
218 | - | then { | |
219 | - | let ducklingAssetId = invoke(this, "issueFreeDuckling", [toString(i.originCaller), toBase58String(i.transactionId), 0], nil) | |
220 | - | if ((ducklingAssetId == ducklingAssetId)) | |
221 | - | then nil | |
222 | - | else throw("Strict value is not equal to itself.") | |
223 | - | } | |
224 | - | else throw("Strict value is not equal to itself.") | |
124 | + | func issueDuckling (address,txIdStr) = if ((i.caller != getBreederAddress())) | |
125 | + | then throw("BIFD: You can't issue free duckling") | |
126 | + | else { | |
127 | + | let asset = Issue("BABY-11111111-HZ", "", 1, 0, false, unit, height) | |
128 | + | let assetId = calculateAssetId(asset) | |
129 | + | $Tuple2([StringEntry((((address + "_") + txIdStr) + "_di"), toBase58String(assetId)), IntegerEntry("stats_amount", (tryGetInteger("stats_amount") + 1)), BooleanEntry((("duckling_" + toBase58String(assetId)) + "_issuedByFeedCall"), (i.caller == this)), IntegerEntry(keyStartPercentage(toBase58String(assetId)), 0), StringEntry(keyOwner(toBase58String(assetId)), address), asset, ScriptTransfer(value(addressFromString(address)), 1, assetId)], toBase58String(assetId)) | |
130 | + | } | |
131 | + | ||
132 | + | ||
133 | + | ||
134 | + | @Callable(i) | |
135 | + | func feedDuckling (ducklingId) = { | |
136 | + | let addressString = toString(i.caller) | |
137 | + | let realDucklingId = if (if ((size(i.payments) != 1)) | |
138 | + | then true | |
139 | + | else (value(i.payments[0]).assetId != getSpiceAssetId())) | |
140 | + | then throw("BFD: Bad payment attached (asset[s] or amount)") | |
141 | + | else if (getBool(keyDucklingGrown(ducklingId))) | |
142 | + | then throw("BFD: Duckling is already grown") | |
143 | + | else if ((ducklingId == "")) | |
144 | + | then throw("BFD: Please hatch a duckling first!") | |
145 | + | else { | |
146 | + | let ducklingOwner = tryGetString(keyOwner(ducklingId)) | |
147 | + | let ducklingIdCheck = value(assetInfo(fromBase58String(ducklingId))) | |
148 | + | if ((assetBalance(i.caller, ducklingIdCheck.id) != 1)) | |
149 | + | then throw("BFD: You're not the owner of the duckling") | |
150 | + | else if ((ducklingOwner != toString(i.caller))) | |
151 | + | then throw("BFD: You can only feed ducklings that you won/bought yourself!") | |
152 | + | else if ((ducklingIdCheck.issuer != this)) | |
153 | + | then throw("BFD: Cant find duckling with such id") | |
154 | + | else { | |
155 | + | let ducklingIdString = toBase58String(ducklingIdCheck.id) | |
156 | + | ducklingIdString | |
157 | + | } | |
225 | 158 | } | |
226 | - | else throw("Strict value is not equal to itself.") | |
227 | - | } | |
159 | + | let kDucklingLastFedTs = keyDucklingFedLastTimestamp(ducklingId) | |
160 | + | let currentPayment = value(i.payments[0]).amount | |
161 | + | let kNewLevel = keyDucklingLevel(realDucklingId) | |
162 | + | let kTotalFeed = keyTotalFeed(realDucklingId) | |
163 | + | let totalFeed = tryGetInteger(kTotalFeed) | |
164 | + | let kFeedTxStats = ((("duckling_" + realDucklingId) + "_stat_") + toString(lastBlock.timestamp)) | |
165 | + | let calculateResults = calculateNewDucklingLevel(realDucklingId, currentPayment) | |
166 | + | [IntegerEntry(kDucklingLastFedTs, lastBlock.timestamp), IntegerEntry(kTotalFeed, (totalFeed + currentPayment)), IntegerEntry(kFeedTxStats, currentPayment), StringEntry(kNewLevel, calculateResults._1), StringEntry((kFeedTxStats + "_debug"), makeString(calculateResults._2, ";"))] | |
228 | 167 | } | |
229 | 168 | ||
230 | 169 | ||
231 | 170 | ||
232 | 171 | @Callable(i) | |
233 | - | func issueFreeDuckling (address,txIdStr,percentage) = if (if ((i.caller != this)) | |
234 | - | then (i.caller != getRebirthAddress()) | |
235 | - | else false) | |
236 | - | then throw("BIFD: You can't issue free duckling") | |
172 | + | func turnDucklingIntoDuck () = if ((i.caller != getBreederAddress())) | |
173 | + | then throw("BIFD: You can't turn duckling") | |
237 | 174 | else { | |
238 | - | let asset = Issue("BABY-11111111-GZ", "", 1, 0, false, unit, height) | |
239 | - | let assetId = calculateAssetId(asset) | |
240 | - | $Tuple2([StringEntry((((address + "_") + txIdStr) + "_di"), toBase58String(assetId)), IntegerEntry("stats_amount", (tryGetInteger("stats_amount") + 1)), BooleanEntry((("duckling_" + toBase58String(assetId)) + "_issuedByFeedCall"), (i.caller == this)), IntegerEntry(keyStartPercentage(toBase58String(assetId)), percentage), StringEntry(keyOwner(toBase58String(assetId)), address), asset, ScriptTransfer(value(addressFromString(address)), 1, assetId)], toBase58String(assetId)) | |
175 | + | let address = toString(i.caller) | |
176 | + | let txId = toBase58String(i.transactionId) | |
177 | + | let lastIssuedDucklingTs = tryGetInteger(KGlobalIssuedTimestamp) | |
178 | + | let fiveMinInMs = ((1 * 60) * 1000) | |
179 | + | let timeDiff = (lastBlock.timestamp - (lastIssuedDucklingTs + fiveMinInMs)) | |
180 | + | if (if ((lastIssuedDucklingTs > 0)) | |
181 | + | then (0 > timeDiff) | |
182 | + | else false) | |
183 | + | then throw((("BTD: Can issue ducklings only once per 1 minutes, please wait for " + toString(fraction(timeDiff, 1, 1000))) + " sec.")) | |
184 | + | else if ((size(i.payments) != 1)) | |
185 | + | then throw("BTD: Bad payment attached (asset[s] or amount)") | |
186 | + | else { | |
187 | + | let pmt = value(assetInfo(value(value(i.payments[0]).assetId))) | |
188 | + | if ((DUCKLINGPRICE > getCurrentLevelInt(toBase58String(pmt.id)))) | |
189 | + | then throw("BTD: Duckling is not grown yet...") | |
190 | + | else if ((pmt.issuer != this)) | |
191 | + | then throw("BTD: Can use only ducklings from this dApp") | |
192 | + | else { | |
193 | + | let kDucklingGrown = keyDucklingGrown(toBase58String(pmt.id)) | |
194 | + | $Tuple2([BooleanEntry(kDucklingGrown, true), IntegerEntry(KGlobalIssuedTimestamp, lastBlock.timestamp)], toBase58String(pmt.id)) | |
195 | + | } | |
196 | + | } | |
241 | 197 | } | |
242 | - | ||
243 | - | ||
244 | - | ||
245 | - | @Callable(i) | |
246 | - | func feedDuckling (ducklingId,backendSignature,maxFeedAmount,userNonce) = { | |
247 | - | let addressString = toString(i.caller) | |
248 | - | let backendProof = getBackendProof(maxFeedAmount, userNonce, addressString) | |
249 | - | let kAddressNonce = keyAddressNonce(addressString) | |
250 | - | let currentNonce = tryGetInteger(kAddressNonce) | |
251 | - | let realDucklingId = if (!(sigVerify_8Kb(toBytes(backendProof), fromBase58String(backendSignature), backendPubKey))) | |
252 | - | then throw("BFD: Invalid proof from backend") | |
253 | - | else if (if ((size(i.payments) != 1)) | |
254 | - | then true | |
255 | - | else (value(i.payments[0]).assetId != getSpiceAssetId())) | |
256 | - | then throw("BFD: Bad payment attached (asset[s] or amount)") | |
257 | - | else if (getBool(keyDucklingGrown(ducklingId))) | |
258 | - | then throw("BFD: Duckling is already grown") | |
259 | - | else if ((userNonce != (currentNonce + 1))) | |
260 | - | then throw(((("BFD: User Nonce should be " + toString(currentNonce)) + " + 1, while received ") + toString(userNonce))) | |
261 | - | else if ((ducklingId == "")) | |
262 | - | then throw("BFD: Please buy a duckling first!") | |
263 | - | else { | |
264 | - | let ducklingOwner = tryGetString(keyOwner(ducklingId)) | |
265 | - | let ducklingIdCheck = value(assetInfo(fromBase58String(ducklingId))) | |
266 | - | if ((assetBalance(i.caller, ducklingIdCheck.id) != 1)) | |
267 | - | then throw("BFD: You're not the owner of the duckling") | |
268 | - | else if ((ducklingOwner != toString(i.caller))) | |
269 | - | then throw("BFD: You can only feed ducklings that you won/bought yourself!") | |
270 | - | else if ((ducklingIdCheck.issuer != this)) | |
271 | - | then throw("BFD: Cant find duckling with such id") | |
272 | - | else { | |
273 | - | let ducklingIdString = toBase58String(ducklingIdCheck.id) | |
274 | - | ducklingIdString | |
275 | - | } | |
276 | - | } | |
277 | - | let kDucklingLastFedTs = keyDucklingFedLastTimestamp(ducklingId) | |
278 | - | let lastFedTs = getLastFedTimestamp(realDucklingId) | |
279 | - | let currentPayment = value(i.payments[0]).amount | |
280 | - | let kNewLevel = keyDucklingLevel(realDucklingId) | |
281 | - | let kTotalFeed = keyTotalFeed(realDucklingId) | |
282 | - | let totalFeed = tryGetInteger(kTotalFeed) | |
283 | - | let kFeedTxStats = ((("duckling_" + realDucklingId) + "_stat_") + toString(lastBlock.timestamp)) | |
284 | - | let kAddressFedTimestamp = keyAddressFedTimestamp(addressString, getCurrentLap(), lastBlock.timestamp) | |
285 | - | let kDucklingFedLapTimestamp = keyDucklingFedLapTimestamp(realDucklingId, getCurrentLap()) | |
286 | - | let kDucklingFedLap = keyDucklingFedLap(realDucklingId) | |
287 | - | if ((currentPayment > maxFeedAmount)) | |
288 | - | then throw(("BFD: Cannot feed duckling for such amount, max feed amount is: " + toString(maxFeedAmount))) | |
289 | - | else { | |
290 | - | let calculateResults = calculateNewDucklingLevel(realDucklingId, (currentPayment / 100)) | |
291 | - | [IntegerEntry(kAddressNonce, (currentNonce + 1)), IntegerEntry(kDucklingLastFedTs, lastBlock.timestamp), IntegerEntry(kTotalFeed, (totalFeed + currentPayment)), IntegerEntry(kFeedTxStats, currentPayment), IntegerEntry(kAddressFedTimestamp, currentPayment), IntegerEntry(kDucklingFedLapTimestamp, currentPayment), IntegerEntry(kDucklingFedLap, getCurrentLap()), StringEntry(kNewLevel, calculateResults._1), StringEntry((kFeedTxStats + "_debug"), makeString(calculateResults._2, ";"))] | |
292 | - | } | |
293 | - | } | |
294 | - | ||
295 | - | ||
296 | - | ||
297 | - | @Callable(i) | |
298 | - | func fixLevels (ducklingIds) = if (if ((i.callerPublicKey != base58'GDxBbsDRmeY39quNrDsTXKJzFWbQVtjxHseF4ikxZ7n9')) | |
299 | - | then (i.caller != this) | |
300 | - | else false) | |
301 | - | then throw("BFL: Not authorized") | |
302 | - | else { | |
303 | - | let ducklingIdsList = value(split(ducklingIds, ",")) | |
304 | - | func handleId (acc,id) = { | |
305 | - | let kTotalFeed = keyTotalFeed(id) | |
306 | - | let totalFeed = tryGetInteger(kTotalFeed) | |
307 | - | let kNewLevel = keyDucklingLevel(id) | |
308 | - | let startingLevel = match getBoolean((("duckling_" + id) + "_issuedByFeedCall")) { | |
309 | - | case b: Boolean => | |
310 | - | if ((b == true)) | |
311 | - | then toBigInt(0) | |
312 | - | else getDucklingPercentage(id) | |
313 | - | case _ => | |
314 | - | getDucklingPercentage(id) | |
315 | - | } | |
316 | - | let growth = fraction(toBigInt(totalFeed), toBigInt(percentGrowthPrecision), toBigInt(DUCKLINGPRICE)) | |
317 | - | (acc ++ [StringEntry(kNewLevel, toString((startingLevel + growth)))]) | |
318 | - | } | |
319 | - | ||
320 | - | let $l = ducklingIdsList | |
321 | - | let $s = size($l) | |
322 | - | let $acc0 = nil | |
323 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
324 | - | then $a | |
325 | - | else handleId($a, $l[$i]) | |
326 | - | ||
327 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
328 | - | then $a | |
329 | - | else throw("List size exceeds 20") | |
330 | - | ||
331 | - | $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($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20) | |
332 | - | } | |
333 | - | ||
334 | - | ||
335 | - | ||
336 | - | @Callable(i) | |
337 | - | func turnDucklingIntoDuck () = { | |
338 | - | let address = toString(i.caller) | |
339 | - | let txId = toBase58String(i.transactionId) | |
340 | - | let lastIssuedDucklingTs = tryGetInteger(KGlobalIssuedTimestamp) | |
341 | - | let fiveMinInMs = ((5 * 60) * 1000) | |
342 | - | let timeDiff = (lastBlock.timestamp - (lastIssuedDucklingTs + fiveMinInMs)) | |
343 | - | if (if ((lastIssuedDucklingTs > 0)) | |
344 | - | then (0 > timeDiff) | |
345 | - | else false) | |
346 | - | then throw((("BTD: Can issue ducklings only once per 5 minutes, please wait for " + toString(fraction(timeDiff, 1, 1000))) + " sec.")) | |
347 | - | else if ((size(i.payments) != 1)) | |
348 | - | then throw("BTD: Bad payment attached (asset[s] or amount)") | |
349 | - | else { | |
350 | - | let pmt = value(assetInfo(value(value(i.payments[0]).assetId))) | |
351 | - | if ((toBigInt(100) > getCurrentLevelBigInt(toBase58String(pmt.id)))) | |
352 | - | then throw("BTD: Duckling is not grown yet...") | |
353 | - | else if ((pmt.issuer != this)) | |
354 | - | then throw("BTD: Can use only ducklings from this dApp") | |
355 | - | else { | |
356 | - | let call = invoke(getIncubatorAddress(), "startDuckHatching", [""], nil) | |
357 | - | if ((call == call)) | |
358 | - | then { | |
359 | - | let kDucklingGrown = keyDucklingGrown(toBase58String(pmt.id)) | |
360 | - | [BooleanEntry(kDucklingGrown, true), IntegerEntry(KGlobalIssuedTimestamp, lastBlock.timestamp)] | |
361 | - | } | |
362 | - | else throw("Strict value is not equal to itself.") | |
363 | - | } | |
364 | - | } | |
365 | - | } | |
366 | 198 | ||
367 | 199 | ||
368 | 200 | @Verifier(tx) | |
369 | 201 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
370 | 202 |
github/deemru/w8io/6500d08 52.14 ms ◑