tx · 8zfrTjqXSLyJtZpNXbseHnLfoyGkksWVyHxp2fWDhBrG

3P9REuLBnYBafDqtEu6hfzs2Rv2haSU158y:  -0.00700000 Waves

2022.08.03 16:57 [3233917] smart account 3P9REuLBnYBafDqtEu6hfzs2Rv2haSU158y > SELF 0.00000000 Waves

{ "type": 13, "id": "8zfrTjqXSLyJtZpNXbseHnLfoyGkksWVyHxp2fWDhBrG", "fee": 700000, "feeAssetId": null, "timestamp": 1659535097182, "version": 2, "chainId": 87, "sender": "3P9REuLBnYBafDqtEu6hfzs2Rv2haSU158y", "senderPublicKey": "4o7Wphn2swW4DxuPY7UcT6YpsZniEMnDH818h1pC3BeX", "proofs": [ "vfJtHZaLcX6Lmpzn7pdPN8sUJVBN28urDAH5rsnEtSeNzQHKkLUTCx2b5cbpeeajp3v7AdRtzbdEeVbFUPPzfwk" ], "script": "base64:BgIVCAISAwoBCBIECgIICBIECgIIARIAFwEUdHJ5R2V0U3RyaW5nRXh0ZXJuYWwCB2FkZHJlc3MDa2V5BAckbWF0Y2gwCQCdCAIFB2FkZHJlc3MFA2tleQMJAAECBQckbWF0Y2gwAgZTdHJpbmcEAWEFByRtYXRjaDAFAWECAAEVdHJ5R2V0SW50ZWdlckV4dGVybmFsAgdhZGRyZXNzA2tleQQHJG1hdGNoMAkAmggCBQdhZGRyZXNzBQNrZXkDCQABAgUHJG1hdGNoMAIDSW50BAFiBQckbWF0Y2gwBQFiAAABDHRyeUdldFN0cmluZwEDa2V5CQEUdHJ5R2V0U3RyaW5nRXh0ZXJuYWwCBQR0aGlzBQNrZXkBCWdldE9yYWNsZQAJAQdBZGRyZXNzAQkA2QQBCQEMdHJ5R2V0U3RyaW5nAQIUc3RhdGljX29yYWNsZUFkZHJlc3MBD2dldFNwaWNlQXNzZXRJZAAJANkEAQkBFHRyeUdldFN0cmluZ0V4dGVybmFsAgkBCWdldE9yYWNsZQACE3N0YXRpY19zcGljZUFzc2V0SWQBEWdldEJyZWVkZXJBZGRyZXNzAAkB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WNrbGluZ0dyb3duCQEQa2V5RHVja2xpbmdHcm93bgEJANgEAQgFA3BtdAJpZAkAzAgCCQEMQm9vbGVhbkVudHJ5AgUOa0R1Y2tsaW5nR3Jvd24GCQDMCAIJAQxJbnRlZ2VyRW50cnkCBRZLR2xvYmFsSXNzdWVkVGltZXN0YW1wCAUJbGFzdEJsb2NrCXRpbWVzdGFtcAUDbmlsAQJ0eAEGdmVyaWZ5AAkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAgFAnR4D3NlbmRlclB1YmxpY0tlefU7IzM=", "height": 3233917, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 5Gqfad4RJ7SXgWwyLFJjijy6ebMDK3WsCdLAJJDo6hZG Next: 8T8xfMBURzFKFts78kzS7wQUoRysW7hhgVi8fGt2RsU7 Diff:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let delayForHatching = 2
5-
6-let HatchingStarted = "BREEDING_STARTED"
7-
8-let HatchingFinished = "BREEDING_FINISHED"
9-
104 func tryGetStringExternal (address,key) = match getString(address, key) {
115 case a: String =>
126 a
2923 func getOracle () = Address(fromBase58String(tryGetString("static_oracleAddress")))
3024
3125
32-func getIncubatorAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_incubatorAddress")))
26+func getSpiceAssetId () = fromBase58String(tryGetStringExternal(getOracle(), "static_spiceAssetId"))
3327
3428
35-func getRebirthAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_rebirthAddress")))
29+func getBreederAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_breederAddress")))
3630
3731
38-func getItemsAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_itemsAddress")))
32+let DUCKLINGPRICE = 10000000000
33+
34+let percentGrowthPrecision = 10000000000000000
35+
36+let existingDuckPrecision = 100000000000000
37+
38+let KGlobalIssuedTimestamp = "global_issued_timestamp"
39+
40+func keyTotalFeed (ducklingId) = (("duckling_" + ducklingId) + "_feed")
3941
4042
41-func getEggAssetId () = fromBase58String(tryGetStringExternal(getOracle(), "static_eggAssetId"))
43+func keyDucklingFedLastTimestamp (ducklingId) = (("duckling_" + ducklingId) + "_fedLastTs")
4244
4345
44-func getBabyDuckBreedingAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_babyDuckBreedingAddress")))
46+func keyDucklingLevel (ducklingId) = (("duckling_" + ducklingId) + "_level")
4547
4648
47-func getDucklingPrice () = tryGetIntegerExternal(getOracle(), "static_ducklingPrice")
49+func keyDucklingGrown (ducklingId) = (("duckling_" + ducklingId) + "_grown")
4850
4951
50-let MaxGeneration = 7
51-
52-let Generations = ["G", "H", "I", "K", "L", "M", "N", "O"]
53-
54-func getProcessStatusKey (address,txId) = (((address + "_") + toBase58String(txId)) + "_status")
52+func keyStartPercentage (ducklingId) = (("duckling_" + ducklingId) + "_startPercentage")
5553
5654
57-func getDucklingKey (address,txId) = (((address + "_") + toBase58String(txId)) + "_duckling")
58-
59-
60-func getProcessFinishHeightKey (address,txId) = (((address + "_") + toBase58String(txId)) + "_fh")
61-
62-
63-func getDuckParentKey (txId,parentNum) = ((("inittx_" + toBase58String(txId)) + "_parent") + toString(parentNum))
64-
65-
66-func getDuckIdKey (address,txId) = (((address + "_") + toBase58String(txId)) + "_di")
67-
68-
69-func getDuckStatsKey (genString) = (("stats_" + genString) + "_amount")
55+func keyOwner (ducklingId) = (("duckling_" + ducklingId) + "_owner")
7056
7157
7258 func tryGetInteger (key) = {
8066 }
8167
8268
83-func determineGeneration (g1,g2) = {
84- let gIndex = max([value(indexOf(Generations, g1)), value(indexOf(Generations, g2))])
85-Generations[(gIndex + 1)]
69+func getBool (key) = match getBoolean(this, key) {
70+ case b: Boolean =>
71+ b
72+ case _ =>
73+ false
74+}
75+
76+
77+func getDucklingPercentage (ducklingId) = {
78+ let percentageDuckling = tryGetInteger(keyStartPercentage(ducklingId))
79+ let base = if ((percentageDuckling != 0))
80+ then percentageDuckling
81+ else 20
82+ toBigInt((base * existingDuckPrecision))
8683 }
8784
8885
89-func getRandomNumber (variants,txId,hatchingFinishHeight,offset) = {
90- let randomSeedBlock = value(blockInfoByHeight((hatchingFinishHeight - 1)))
91- let randomHash = sha256_16Kb((txId + value(randomSeedBlock.vrf)))
92- (toInt(randomHash, offset) % variants)
86+func getCurrentLevelBigInt (ducklingId) = {
87+ let kDuckLevel = keyDucklingLevel(ducklingId)
88+ match getString(kDuckLevel) {
89+ case s: String =>
90+ parseBigIntValue(s)
91+ case _ =>
92+ match getBoolean((("duckling_" + ducklingId) + "_issuedByFeedCall")) {
93+ case b: Boolean =>
94+ if ((b == true))
95+ then toBigInt(0)
96+ else getDucklingPercentage(ducklingId)
97+ case _ =>
98+ getDucklingPercentage(ducklingId)
99+ }
100+ }
93101 }
94102
95103
96-func getRandomGen (gen1,gen2,step,txId,hatchingFinishHeight,geneFromParent,genePostion,specifiqueGene,specifiqueGenePosition) = if (if ((geneFromParent != 0))
97- then (genePostion == step)
98- else false)
99- then if ((geneFromParent == 1))
100- then gen1
101- else if ((geneFromParent == 2))
102- then gen2
103- else throw("Parent either needs to be 1 or 2")
104- else if (if ((specifiqueGene != ""))
105- then (specifiqueGenePosition == step)
106- else false)
107- then specifiqueGene
108- else {
109- let randomNum = getRandomNumber(2, txId, hatchingFinishHeight, step)
110- let gen = if ((randomNum == 0))
111- then gen1
112- else gen2
113- gen
114- }
115-
116-
117-func checkAssetInIncubator (assetId) = {
118- let result = match getString(getIncubatorAddress(), assetId) {
119- case b: String =>
120- true
121- case _ =>
122- false
123- }
124- let result2 = match getString(this, assetId) {
125- case c: String =>
126- true
127- case _ =>
128- false
129- }
130- if (result)
131- then true
132- else result2
104+func getLastFedTimestamp (ducklingId) = {
105+ let lastFedTimestamp = tryGetInteger(keyDucklingFedLastTimestamp(ducklingId))
106+ if ((lastFedTimestamp > 0))
107+ then lastFedTimestamp
108+ else lastBlock.timestamp
133109 }
134110
135111
136-func canBeBreeded (asset1Id,asset2Id) = {
137- let asset1Gen = split(value(assetInfo(asset1Id)).name, "")
138- let asset2Gen = split(value(assetInfo(asset2Id)).name, "")
139- if ((value(indexOf(Generations, asset1Gen[14])) >= MaxGeneration))
140- then (("you can only breed ducks with generation " + Generations[MaxGeneration]) + " and lower")
141- else if ((value(indexOf(Generations, asset2Gen[14])) >= MaxGeneration))
142- then (("you can only breed ducks with generation " + Generations[MaxGeneration]) + " and lower")
143- else "true"
112+func calculateNewDucklingLevel (ducklingId,paymentAmount) = {
113+ let currentTs = lastBlock.timestamp
114+ let lastFedTimestampChecked = getLastFedTimestamp(ducklingId)
115+ let fedDiff = (currentTs - lastFedTimestampChecked)
116+ let penalty = toBigInt(0)
117+ let growth = fraction(toBigInt(paymentAmount), toBigInt(percentGrowthPrecision), toBigInt(DUCKLINGPRICE))
118+ let currentLevel = getCurrentLevelBigInt(ducklingId)
119+ let newLevel = ((currentLevel - penalty) + growth)
120+ let result = if ((toBigInt(0) > newLevel))
121+ then toString(growth)
122+ else toString(newLevel)
123+ $Tuple2(result, [("currentLevel=" + toString(currentLevel)), ("newLevel=" + toString(newLevel)), ("growth=" + toString(growth)), ("penalty=" + toString(penalty)), ("lastFedTs=" + toString(lastFedTimestampChecked)), ("fedDiff=" + toString(fedDiff))])
144124 }
145-
146-
147-func isSymbolA (accumulated,sym) = if ((sym == "A"))
148- then (accumulated + 1)
149- else (accumulated + 0)
150-
151-
152-func isSymbolB (accumulated,sym) = if ((sym == "B"))
153- then (accumulated + 1)
154- else (accumulated + 0)
155-
156-
157-func isSymbolC (accumulated,sym) = if ((sym == "C"))
158- then (accumulated + 1)
159- else (accumulated + 0)
160-
161-
162-func isSymbolD (accumulated,sym) = if ((sym == "D"))
163- then (accumulated + 1)
164- else (accumulated + 0)
165-
166-
167-func isSymbolE (accumulated,sym) = if ((sym == "E"))
168- then (accumulated + 1)
169- else (accumulated + 0)
170-
171-
172-func isSymbolF (accumulated,sym) = if ((sym == "F"))
173- then (accumulated + 1)
174- else (accumulated + 0)
175-
176-
177-func isSymbolG (accumulated,sym) = if ((sym == "G"))
178- then (accumulated + 1)
179- else (accumulated + 0)
180-
181-
182-func isSymbolH (accumulated,sym) = if ((sym == "H"))
183- then (accumulated + 1)
184- else (accumulated + 0)
185-
186-
187-func isSymbolI (accumulated,sym) = if ((sym == "I"))
188- then (accumulated + 1)
189- else (accumulated + 0)
190-
191-
192-func isSymbolK (accumulated,sym) = if ((sym == "K"))
193- then (accumulated + 1)
194- else (accumulated + 0)
195-
196-
197-func isSymbolS (accumulated,sym) = if ((sym == "S"))
198- then (accumulated + 1)
199- else (accumulated + 0)
200-
201-
202-func isSymbolT (accumulated,sym) = if ((sym == "T"))
203- then (accumulated + 1)
204- else (accumulated + 0)
205-
206-
207-func getAmountOrClear (amount) = if (contains(amount, "0"))
208- then ""
209- else amount
210-
211-
212-func asString (value) = match value {
213- case string: String =>
214- string
215- case _ =>
216- throw("wrong type, expected: String")
217-}
218125
219126
220127 func asInt (value) = match value {
221128 case int: Int =>
222129 int
223130 case _ =>
224- throw("wrong type, expected: Int")
131+ throw("BAI: wrong type, expected: Int")
225132 }
226-
227-
228-func composeGenericData (duckGen,duckIdKey,assetId,asset) = {
229- let farmGen = asString(invoke(this, "getGenFromName", [duckGen], nil))
230- if ((farmGen == farmGen))
231- then {
232- let amount = tryGetInteger(getDuckStatsKey(duckGen))
233- let quantity = tryGetInteger((("stats_" + farmGen) + "_quantity"))
234-[StringEntry(duckIdKey, toBase58String(assetId)), StringEntry(toBase58String(assetId), duckIdKey), IntegerEntry(getDuckStatsKey(duckGen), (amount + 1)), IntegerEntry((("stats_" + farmGen) + "_quantity"), (quantity + 1)), asset]
235- }
236- else throw("Strict value is not equal to itself.")
237- }
238-
239-
240-func finishDuckHatch (payments,txIdStr,owner,duckGenesString) = {
241- let ducklingFinish = invoke(getBabyDuckBreedingAddress(), "turnDucklingIntoDuck", nil, payments)
242- if ((ducklingFinish == ducklingFinish))
243- then {
244- let txId = fromBase58String(txIdStr)
245- let processStatusKey = getProcessStatusKey(owner, txId)
246- let duckIdKey = getDuckIdKey(owner, txId)
247- let processTxStatus = getStringValue(this, processStatusKey)
248- let finishHeightKey = getProcessFinishHeightKey(owner, txId)
249- let processFinishHeight = getIntegerValue(this, finishHeightKey)
250- if ((processTxStatus == HatchingFinished))
251- then {
252- let duckId = getStringValue(this, getDuckIdKey(owner, txId))
253- throw(("The duck was breeded and claimed already, here is the folowing: " + duckId))
254- }
255- else if ((processFinishHeight > height))
256- then throw((((("Breeding is not finished yet " + toString((processFinishHeight - height))) + " blocks remaining, it will take around ") + toString((processFinishHeight - height))) + " minutes"))
257- else {
258- let duckGen = if ((duckGenesString == ""))
259- then asString(invoke(this, "generateDuck", [txId, processFinishHeight, 0, 0, "", 0], nil))
260- else duckGenesString
261- if ((duckGen == duckGen))
262- then {
263- let description = (("{\"genotype\": \"" + duckGen) + "\", \"crossbreeding\": true}")
264- let asset = Issue(duckGen, description, 1, 0, false, unit, processFinishHeight)
265- let assetId = calculateAssetId(asset)
266- let parent1Id = tryGetString(getDuckParentKey(txId, 1))
267- let parent2Id = tryGetString(getDuckParentKey(txId, 2))
268- (composeGenericData(duckGen, duckIdKey, assetId, asset) ++ [StringEntry(processStatusKey, HatchingFinished), IntegerEntry((("asset_" + parent1Id) + "_children"), 1), IntegerEntry((("asset_" + parent2Id) + "_children"), 1), ScriptTransfer(addressFromStringValue(owner), 1, assetId), ScriptTransfer(addressFromStringValue(owner), 1, fromBase58String(parent1Id)), ScriptTransfer(addressFromStringValue(owner), 1, fromBase58String(parent2Id))])
269- }
270- else throw("Strict value is not equal to itself.")
271- }
272- }
273- else throw("Strict value is not equal to itself.")
274- }
275133
276134
277135 @Callable(i)
278136 func configureOracle (oracle) = if ((i.caller != this))
279- then throw("admin only")
137+ then throw("BCO: admin only")
280138 else [StringEntry("static_oracleAddress", oracle)]
281139
282140
283141
284142 @Callable(i)
285-func generateDuck (txId,hatchingFinishHeight,geneFromParent,genePostion,specifiqueGene,specifiqueGenePosition) = {
286- let colorRandom = getRandomNumber(4, txId, hatchingFinishHeight, 11)
287- let color = if ((colorRandom == 0))
288- then "Y"
289- else if ((colorRandom == 1))
290- then "G"
291- else if ((colorRandom == 2))
292- then "B"
293- else "R"
294- let parent1Id = fromBase58String(tryGetString(getDuckParentKey(txId, 1)))
295- let parent2Id = fromBase58String(tryGetString(getDuckParentKey(txId, 2)))
296- let parent1Gen = split(value(assetInfo(parent1Id)).name, "")
297- let parent2Gen = split(value(assetInfo(parent2Id)).name, "")
298- let gen = ((((((((((("DUCK-" + getRandomGen(parent1Gen[5], parent2Gen[5], 0, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + getRandomGen(parent1Gen[6], parent2Gen[6], 1, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + getRandomGen(parent1Gen[7], parent2Gen[7], 2, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + getRandomGen(parent1Gen[8], parent2Gen[8], 3, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + getRandomGen(parent1Gen[9], parent2Gen[9], 4, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + getRandomGen(parent1Gen[10], parent2Gen[10], 5, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + getRandomGen(parent1Gen[11], parent2Gen[11], 6, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + getRandomGen(parent1Gen[12], parent2Gen[12], 7, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + "-") + determineGeneration(parent1Gen[14], parent2Gen[14])) + color)
299- $Tuple2(nil, gen)
143+func issueDuckling (address,txIdStr) = if ((i.caller != getBreederAddress()))
144+ then throw("BIFD: You can't issue free duckling")
145+ else {
146+ let asset = Issue("BABY-11111111-HZ", "", 1, 0, false, unit, height)
147+ let assetId = calculateAssetId(asset)
148+ $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))
149+ }
150+
151+
152+
153+@Callable(i)
154+func feedDuckling (ducklingId,maxFeedAmount) = {
155+ let addressString = toString(i.caller)
156+ let realDucklingId = if (if ((size(i.payments) != 1))
157+ then true
158+ else (value(i.payments[0]).assetId != getSpiceAssetId()))
159+ then throw("BFD: Bad payment attached (asset[s] or amount)")
160+ else if (getBool(keyDucklingGrown(ducklingId)))
161+ then throw("BFD: Duckling is already grown")
162+ else if ((ducklingId == ""))
163+ then throw("BFD: Please hatch a duckling first!")
164+ else {
165+ let ducklingOwner = tryGetString(keyOwner(ducklingId))
166+ let ducklingIdCheck = value(assetInfo(fromBase58String(ducklingId)))
167+ if ((assetBalance(i.caller, ducklingIdCheck.id) != 1))
168+ then throw("BFD: You're not the owner of the duckling")
169+ else if ((ducklingOwner != toString(i.caller)))
170+ then throw("BFD: You can only feed ducklings that you won/bought yourself!")
171+ else if ((ducklingIdCheck.issuer != this))
172+ then throw("BFD: Cant find duckling with such id")
173+ else {
174+ let ducklingIdString = toBase58String(ducklingIdCheck.id)
175+ ducklingIdString
176+ }
177+ }
178+ let kDucklingLastFedTs = keyDucklingFedLastTimestamp(ducklingId)
179+ let currentPayment = value(i.payments[0]).amount
180+ let kNewLevel = keyDucklingLevel(realDucklingId)
181+ let kTotalFeed = keyTotalFeed(realDucklingId)
182+ let totalFeed = tryGetInteger(kTotalFeed)
183+ let kFeedTxStats = ((("duckling_" + realDucklingId) + "_stat_") + toString(lastBlock.timestamp))
184+ if ((currentPayment > maxFeedAmount))
185+ then throw(("BFD: Cannot feed duckling for such amount, max feed amount is: " + toString(maxFeedAmount)))
186+ else {
187+ let calculateResults = calculateNewDucklingLevel(realDucklingId, currentPayment)
188+[IntegerEntry(kDucklingLastFedTs, lastBlock.timestamp), IntegerEntry(kTotalFeed, (totalFeed + currentPayment)), IntegerEntry(kFeedTxStats, currentPayment), StringEntry(kNewLevel, calculateResults._1), StringEntry((kFeedTxStats + "_debug"), makeString(calculateResults._2, ";"))]
189+ }
300190 }
301191
302192
303193
304194 @Callable(i)
305-func getGenFromName (assetName) = {
306- let genotype = split(dropRight(drop(assetName, 5), 3), "")
307- let generation = split(assetName, "")[14]
308- let gen = (((((((((((((getAmountOrClear((toString({
309- let $l = genotype
310- let $s = size($l)
311- let $acc0 = 0
312- func $f0_1 ($a,$i) = if (($i >= $s))
313- then $a
314- else isSymbolA($a, $l[$i])
315-
316- func $f0_2 ($a,$i) = if (($i >= $s))
317- then $a
318- else throw("List size exceeds 8")
319-
320- $f0_2($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)
321- }) + "A")) + getAmountOrClear((toString({
322- let $l = genotype
323- let $s = size($l)
324- let $acc0 = 0
325- func $f1_1 ($a,$i) = if (($i >= $s))
326- then $a
327- else isSymbolB($a, $l[$i])
328-
329- func $f1_2 ($a,$i) = if (($i >= $s))
330- then $a
331- else throw("List size exceeds 8")
332-
333- $f1_2($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
334- }) + "B"))) + getAmountOrClear((toString({
335- let $l = genotype
336- let $s = size($l)
337- let $acc0 = 0
338- func $f2_1 ($a,$i) = if (($i >= $s))
339- then $a
340- else isSymbolC($a, $l[$i])
341-
342- func $f2_2 ($a,$i) = if (($i >= $s))
343- then $a
344- else throw("List size exceeds 8")
345-
346- $f2_2($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
347- }) + "C"))) + getAmountOrClear((toString({
348- let $l = genotype
349- let $s = size($l)
350- let $acc0 = 0
351- func $f3_1 ($a,$i) = if (($i >= $s))
352- then $a
353- else isSymbolD($a, $l[$i])
354-
355- func $f3_2 ($a,$i) = if (($i >= $s))
356- then $a
357- else throw("List size exceeds 8")
358-
359- $f3_2($f3_1($f3_1($f3_1($f3_1($f3_1($f3_1($f3_1($f3_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
360- }) + "D"))) + getAmountOrClear((toString({
361- let $l = genotype
362- let $s = size($l)
363- let $acc0 = 0
364- func $f4_1 ($a,$i) = if (($i >= $s))
365- then $a
366- else isSymbolE($a, $l[$i])
367-
368- func $f4_2 ($a,$i) = if (($i >= $s))
369- then $a
370- else throw("List size exceeds 8")
371-
372- $f4_2($f4_1($f4_1($f4_1($f4_1($f4_1($f4_1($f4_1($f4_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
373- }) + "E"))) + getAmountOrClear((toString({
374- let $l = genotype
375- let $s = size($l)
376- let $acc0 = 0
377- func $f5_1 ($a,$i) = if (($i >= $s))
378- then $a
379- else isSymbolF($a, $l[$i])
380-
381- func $f5_2 ($a,$i) = if (($i >= $s))
382- then $a
383- else throw("List size exceeds 8")
384-
385- $f5_2($f5_1($f5_1($f5_1($f5_1($f5_1($f5_1($f5_1($f5_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
386- }) + "F"))) + getAmountOrClear((toString({
387- let $l = genotype
388- let $s = size($l)
389- let $acc0 = 0
390- func $f6_1 ($a,$i) = if (($i >= $s))
391- then $a
392- else isSymbolG($a, $l[$i])
393-
394- func $f6_2 ($a,$i) = if (($i >= $s))
395- then $a
396- else throw("List size exceeds 8")
397-
398- $f6_2($f6_1($f6_1($f6_1($f6_1($f6_1($f6_1($f6_1($f6_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
399- }) + "G"))) + getAmountOrClear((toString({
400- let $l = genotype
401- let $s = size($l)
402- let $acc0 = 0
403- func $f7_1 ($a,$i) = if (($i >= $s))
404- then $a
405- else isSymbolH($a, $l[$i])
406-
407- func $f7_2 ($a,$i) = if (($i >= $s))
408- then $a
409- else throw("List size exceeds 8")
410-
411- $f7_2($f7_1($f7_1($f7_1($f7_1($f7_1($f7_1($f7_1($f7_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
412- }) + "H"))) + getAmountOrClear((toString({
413- let $l = genotype
414- let $s = size($l)
415- let $acc0 = 0
416- func $f8_1 ($a,$i) = if (($i >= $s))
417- then $a
418- else isSymbolI($a, $l[$i])
419-
420- func $f8_2 ($a,$i) = if (($i >= $s))
421- then $a
422- else throw("List size exceeds 8")
423-
424- $f8_2($f8_1($f8_1($f8_1($f8_1($f8_1($f8_1($f8_1($f8_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
425- }) + "I"))) + getAmountOrClear((toString({
426- let $l = genotype
427- let $s = size($l)
428- let $acc0 = 0
429- func $f9_1 ($a,$i) = if (($i >= $s))
430- then $a
431- else isSymbolK($a, $l[$i])
432-
433- func $f9_2 ($a,$i) = if (($i >= $s))
434- then $a
435- else throw("List size exceeds 8")
436-
437- $f9_2($f9_1($f9_1($f9_1($f9_1($f9_1($f9_1($f9_1($f9_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
438- }) + "K"))) + getAmountOrClear((toString({
439- let $l = genotype
440- let $s = size($l)
441- let $acc0 = 0
442- func $f10_1 ($a,$i) = if (($i >= $s))
443- then $a
444- else isSymbolS($a, $l[$i])
445-
446- func $f10_2 ($a,$i) = if (($i >= $s))
447- then $a
448- else throw("List size exceeds 8")
449-
450- $f10_2($f10_1($f10_1($f10_1($f10_1($f10_1($f10_1($f10_1($f10_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
451- }) + "S"))) + getAmountOrClear((toString({
452- let $l = genotype
453- let $s = size($l)
454- let $acc0 = 0
455- func $f11_1 ($a,$i) = if (($i >= $s))
456- then $a
457- else isSymbolT($a, $l[$i])
458-
459- func $f11_2 ($a,$i) = if (($i >= $s))
460- then $a
461- else throw("List size exceeds 8")
462-
463- $f11_2($f11_1($f11_1($f11_1($f11_1($f11_1($f11_1($f11_1($f11_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
464- }) + "T"))) + "-") + generation)
465- $Tuple2(nil, gen)
466- }
467-
468-
469-
470-@Callable(i)
471-func validateAndGetChildren (assetId) = if (!(checkAssetInIncubator(assetId)))
472- then throw((("You need to attach a valid NFT-duck. " + assetId) + " is invalid!"))
195+func turnDucklingIntoDuck () = if ((i.caller != getBreederAddress()))
196+ then throw("BIFD: You can't turn duckling")
473197 else {
474- let children = tryGetInteger((("asset_" + assetId) + "_children"))
475- $Tuple2(nil, children)
198+ let address = toString(i.caller)
199+ let txId = toBase58String(i.transactionId)
200+ let lastIssuedDucklingTs = tryGetInteger(KGlobalIssuedTimestamp)
201+ let fiveMinInMs = ((1 * 60) * 1000)
202+ let timeDiff = (lastBlock.timestamp - (lastIssuedDucklingTs + fiveMinInMs))
203+ if (if ((lastIssuedDucklingTs > 0))
204+ then (0 > timeDiff)
205+ else false)
206+ then throw((("BTD: Can issue ducklings only once per 1 minutes, please wait for " + toString(fraction(timeDiff, 1, 1000))) + " sec."))
207+ else if ((size(i.payments) != 1))
208+ then throw("BTD: Bad payment attached (asset[s] or amount)")
209+ else {
210+ let pmt = value(assetInfo(value(value(i.payments[0]).assetId)))
211+ if ((toBigInt(100) > getCurrentLevelBigInt(toBase58String(pmt.id))))
212+ then throw("BTD: Duckling is not grown yet...")
213+ else if ((pmt.issuer != this))
214+ then throw("BTD: Can use only ducklings from this dApp")
215+ else {
216+ let kDucklingGrown = keyDucklingGrown(toBase58String(pmt.id))
217+[BooleanEntry(kDucklingGrown, true), IntegerEntry(KGlobalIssuedTimestamp, lastBlock.timestamp)]
218+ }
219+ }
476220 }
477221
478222
479-
480-@Callable(i)
481-func createDuckSpecialGenes (address,duckGen,children) = if (if ((i.caller != getItemsAddress()))
482- then (i.caller != this)
483- else false)
484- then throw("admin or items only")
485- else {
486- let txId = i.transactionId
487- let description = (("{\"genotype\": \"" + duckGen) + "\", \"crossbreeding\": true}")
488- let asset = Issue(duckGen, description, 1, 0, false)
489- let assetId = calculateAssetId(asset)
490- let duckIdKey = getDuckIdKey(toString(i.caller), txId)
491- let farmGen = asString(invoke(this, "getGenFromName", [duckGen], nil))
492- if ((farmGen == farmGen))
493- then (composeGenericData(duckGen, duckIdKey, assetId, asset) ++ [IntegerEntry((("asset_" + toBase58String(assetId)) + "_children"), children), ScriptTransfer(Address(address), 1, assetId)])
494- else throw("Strict value is not equal to itself.")
495- }
496-
497-
498-
499-@Callable(i)
500-func startDuckBreeding () = {
501- let firstPayment = value(i.payments[0])
502- let secondPayment = value(i.payments[1])
503- let thirdPayment = value(i.payments[2])
504- let firstAssetId = toBase58String(value(firstPayment.assetId))
505- let secondAssetId = toBase58String(value(secondPayment.assetId))
506- let thirdAssetId = value(thirdPayment.assetId)
507- if (if ((firstPayment.amount != 1))
508- then true
509- else (secondPayment.amount != 1))
510- then throw("NFT is not attached")
511- else if ((thirdAssetId != getEggAssetId()))
512- then throw("BSDB: wrong payment added!")
513- else if ((thirdPayment.amount != getDucklingPrice()))
514- then throw("BSDB: not enough payment added!")
515- else {
516- let children1 = asInt(invoke(this, "validateAndGetChildren", [firstAssetId], nil))
517- if ((children1 == children1))
518- then {
519- let children2 = asInt(invoke(this, "validateAndGetChildren", [secondAssetId], nil))
520- if ((children2 == children2))
521- then if (if ((children1 > 0))
522- then true
523- else (children2 > 0))
524- then throw("One duck can be used for breeding only once in its lifetime.")
525- else {
526- let breededStatus = canBeBreeded(fromBase58String(firstAssetId), fromBase58String(secondAssetId))
527- if ((breededStatus != "true"))
528- then throw(("These ducks cannot be breeded: " + breededStatus))
529- else {
530- let ducklingGen = asString(invoke(getBabyDuckBreedingAddress(), "issueDuckling", [toString(i.caller), toBase58String(i.transactionId)], nil))
531- if ((ducklingGen == ducklingGen))
532- then [StringEntry(getDuckParentKey(i.transactionId, 1), firstAssetId), StringEntry(getDuckParentKey(i.transactionId, 2), secondAssetId), StringEntry(getProcessStatusKey(toString(i.caller), i.transactionId), HatchingStarted), IntegerEntry(getProcessFinishHeightKey(toString(i.caller), i.transactionId), (height + delayForHatching)), StringEntry(getDucklingKey(toString(i.caller), i.transactionId), ducklingGen)]
533- else throw("Strict value is not equal to itself.")
534- }
535- }
536- else throw("Strict value is not equal to itself.")
537- }
538- else throw("Strict value is not equal to itself.")
539- }
540- }
541-
542-
543-
544-@Callable(i)
545-func finishDuckHatchingItems (txIdStr,duckGenesString) = if (if ((i.caller != getItemsAddress()))
546- then (duckGenesString != "")
547- else false)
548- then throw("Only items can create fixed genes")
549- else {
550- let owner = toString(i.originCaller)
551- finishDuckHatch(i.payments, txIdStr, owner, duckGenesString)
552- }
553-
554-
555-
556-@Callable(i)
557-func finishDuckHatching (txIdStr) = {
558- let owner = toString(i.caller)
559- finishDuckHatch(i.payments, txIdStr, owner, "")
560- }
561-
562-
563-
564-@Callable(i)
565-func reduceRarity (assetId,farmGen) = {
566- let asset = fromBase58String(assetId)
567- if (if (if ((i.caller != getItemsAddress()))
568- then (i.caller != getRebirthAddress())
569- else false)
570- then (i.caller != this)
571- else false)
572- then throw("admin, items or rebirth only")
573- else {
574- let duckGen = value(assetInfo(asset)).name
575-[IntegerEntry(getDuckStatsKey(duckGen), (tryGetInteger(getDuckStatsKey(duckGen)) - 1)), IntegerEntry((("stats_" + farmGen) + "_quantity"), (tryGetInteger((("stats_" + farmGen) + "_quantity")) - 1))]
576- }
577- }
578-
223+@Verifier(tx)
224+func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
579225
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let delayForHatching = 2
5-
6-let HatchingStarted = "BREEDING_STARTED"
7-
8-let HatchingFinished = "BREEDING_FINISHED"
9-
104 func tryGetStringExternal (address,key) = match getString(address, key) {
115 case a: String =>
126 a
137 case _ =>
148 ""
159 }
1610
1711
1812 func tryGetIntegerExternal (address,key) = match getInteger(address, key) {
1913 case b: Int =>
2014 b
2115 case _ =>
2216 0
2317 }
2418
2519
2620 func tryGetString (key) = tryGetStringExternal(this, key)
2721
2822
2923 func getOracle () = Address(fromBase58String(tryGetString("static_oracleAddress")))
3024
3125
32-func getIncubatorAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_incubatorAddress")))
26+func getSpiceAssetId () = fromBase58String(tryGetStringExternal(getOracle(), "static_spiceAssetId"))
3327
3428
35-func getRebirthAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_rebirthAddress")))
29+func getBreederAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_breederAddress")))
3630
3731
38-func getItemsAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_itemsAddress")))
32+let DUCKLINGPRICE = 10000000000
33+
34+let percentGrowthPrecision = 10000000000000000
35+
36+let existingDuckPrecision = 100000000000000
37+
38+let KGlobalIssuedTimestamp = "global_issued_timestamp"
39+
40+func keyTotalFeed (ducklingId) = (("duckling_" + ducklingId) + "_feed")
3941
4042
41-func getEggAssetId () = fromBase58String(tryGetStringExternal(getOracle(), "static_eggAssetId"))
43+func keyDucklingFedLastTimestamp (ducklingId) = (("duckling_" + ducklingId) + "_fedLastTs")
4244
4345
44-func getBabyDuckBreedingAddress () = Address(fromBase58String(tryGetStringExternal(getOracle(), "static_babyDuckBreedingAddress")))
46+func keyDucklingLevel (ducklingId) = (("duckling_" + ducklingId) + "_level")
4547
4648
47-func getDucklingPrice () = tryGetIntegerExternal(getOracle(), "static_ducklingPrice")
49+func keyDucklingGrown (ducklingId) = (("duckling_" + ducklingId) + "_grown")
4850
4951
50-let MaxGeneration = 7
51-
52-let Generations = ["G", "H", "I", "K", "L", "M", "N", "O"]
53-
54-func getProcessStatusKey (address,txId) = (((address + "_") + toBase58String(txId)) + "_status")
52+func keyStartPercentage (ducklingId) = (("duckling_" + ducklingId) + "_startPercentage")
5553
5654
57-func getDucklingKey (address,txId) = (((address + "_") + toBase58String(txId)) + "_duckling")
58-
59-
60-func getProcessFinishHeightKey (address,txId) = (((address + "_") + toBase58String(txId)) + "_fh")
61-
62-
63-func getDuckParentKey (txId,parentNum) = ((("inittx_" + toBase58String(txId)) + "_parent") + toString(parentNum))
64-
65-
66-func getDuckIdKey (address,txId) = (((address + "_") + toBase58String(txId)) + "_di")
67-
68-
69-func getDuckStatsKey (genString) = (("stats_" + genString) + "_amount")
55+func keyOwner (ducklingId) = (("duckling_" + ducklingId) + "_owner")
7056
7157
7258 func tryGetInteger (key) = {
7359 let val = match getInteger(this, key) {
7460 case b: Int =>
7561 b
7662 case _ =>
7763 0
7864 }
7965 val
8066 }
8167
8268
83-func determineGeneration (g1,g2) = {
84- let gIndex = max([value(indexOf(Generations, g1)), value(indexOf(Generations, g2))])
85-Generations[(gIndex + 1)]
69+func getBool (key) = match getBoolean(this, key) {
70+ case b: Boolean =>
71+ b
72+ case _ =>
73+ false
74+}
75+
76+
77+func getDucklingPercentage (ducklingId) = {
78+ let percentageDuckling = tryGetInteger(keyStartPercentage(ducklingId))
79+ let base = if ((percentageDuckling != 0))
80+ then percentageDuckling
81+ else 20
82+ toBigInt((base * existingDuckPrecision))
8683 }
8784
8885
89-func getRandomNumber (variants,txId,hatchingFinishHeight,offset) = {
90- let randomSeedBlock = value(blockInfoByHeight((hatchingFinishHeight - 1)))
91- let randomHash = sha256_16Kb((txId + value(randomSeedBlock.vrf)))
92- (toInt(randomHash, offset) % variants)
86+func getCurrentLevelBigInt (ducklingId) = {
87+ let kDuckLevel = keyDucklingLevel(ducklingId)
88+ match getString(kDuckLevel) {
89+ case s: String =>
90+ parseBigIntValue(s)
91+ case _ =>
92+ match getBoolean((("duckling_" + ducklingId) + "_issuedByFeedCall")) {
93+ case b: Boolean =>
94+ if ((b == true))
95+ then toBigInt(0)
96+ else getDucklingPercentage(ducklingId)
97+ case _ =>
98+ getDucklingPercentage(ducklingId)
99+ }
100+ }
93101 }
94102
95103
96-func getRandomGen (gen1,gen2,step,txId,hatchingFinishHeight,geneFromParent,genePostion,specifiqueGene,specifiqueGenePosition) = if (if ((geneFromParent != 0))
97- then (genePostion == step)
98- else false)
99- then if ((geneFromParent == 1))
100- then gen1
101- else if ((geneFromParent == 2))
102- then gen2
103- else throw("Parent either needs to be 1 or 2")
104- else if (if ((specifiqueGene != ""))
105- then (specifiqueGenePosition == step)
106- else false)
107- then specifiqueGene
108- else {
109- let randomNum = getRandomNumber(2, txId, hatchingFinishHeight, step)
110- let gen = if ((randomNum == 0))
111- then gen1
112- else gen2
113- gen
114- }
115-
116-
117-func checkAssetInIncubator (assetId) = {
118- let result = match getString(getIncubatorAddress(), assetId) {
119- case b: String =>
120- true
121- case _ =>
122- false
123- }
124- let result2 = match getString(this, assetId) {
125- case c: String =>
126- true
127- case _ =>
128- false
129- }
130- if (result)
131- then true
132- else result2
104+func getLastFedTimestamp (ducklingId) = {
105+ let lastFedTimestamp = tryGetInteger(keyDucklingFedLastTimestamp(ducklingId))
106+ if ((lastFedTimestamp > 0))
107+ then lastFedTimestamp
108+ else lastBlock.timestamp
133109 }
134110
135111
136-func canBeBreeded (asset1Id,asset2Id) = {
137- let asset1Gen = split(value(assetInfo(asset1Id)).name, "")
138- let asset2Gen = split(value(assetInfo(asset2Id)).name, "")
139- if ((value(indexOf(Generations, asset1Gen[14])) >= MaxGeneration))
140- then (("you can only breed ducks with generation " + Generations[MaxGeneration]) + " and lower")
141- else if ((value(indexOf(Generations, asset2Gen[14])) >= MaxGeneration))
142- then (("you can only breed ducks with generation " + Generations[MaxGeneration]) + " and lower")
143- else "true"
112+func calculateNewDucklingLevel (ducklingId,paymentAmount) = {
113+ let currentTs = lastBlock.timestamp
114+ let lastFedTimestampChecked = getLastFedTimestamp(ducklingId)
115+ let fedDiff = (currentTs - lastFedTimestampChecked)
116+ let penalty = toBigInt(0)
117+ let growth = fraction(toBigInt(paymentAmount), toBigInt(percentGrowthPrecision), toBigInt(DUCKLINGPRICE))
118+ let currentLevel = getCurrentLevelBigInt(ducklingId)
119+ let newLevel = ((currentLevel - penalty) + growth)
120+ let result = if ((toBigInt(0) > newLevel))
121+ then toString(growth)
122+ else toString(newLevel)
123+ $Tuple2(result, [("currentLevel=" + toString(currentLevel)), ("newLevel=" + toString(newLevel)), ("growth=" + toString(growth)), ("penalty=" + toString(penalty)), ("lastFedTs=" + toString(lastFedTimestampChecked)), ("fedDiff=" + toString(fedDiff))])
144124 }
145-
146-
147-func isSymbolA (accumulated,sym) = if ((sym == "A"))
148- then (accumulated + 1)
149- else (accumulated + 0)
150-
151-
152-func isSymbolB (accumulated,sym) = if ((sym == "B"))
153- then (accumulated + 1)
154- else (accumulated + 0)
155-
156-
157-func isSymbolC (accumulated,sym) = if ((sym == "C"))
158- then (accumulated + 1)
159- else (accumulated + 0)
160-
161-
162-func isSymbolD (accumulated,sym) = if ((sym == "D"))
163- then (accumulated + 1)
164- else (accumulated + 0)
165-
166-
167-func isSymbolE (accumulated,sym) = if ((sym == "E"))
168- then (accumulated + 1)
169- else (accumulated + 0)
170-
171-
172-func isSymbolF (accumulated,sym) = if ((sym == "F"))
173- then (accumulated + 1)
174- else (accumulated + 0)
175-
176-
177-func isSymbolG (accumulated,sym) = if ((sym == "G"))
178- then (accumulated + 1)
179- else (accumulated + 0)
180-
181-
182-func isSymbolH (accumulated,sym) = if ((sym == "H"))
183- then (accumulated + 1)
184- else (accumulated + 0)
185-
186-
187-func isSymbolI (accumulated,sym) = if ((sym == "I"))
188- then (accumulated + 1)
189- else (accumulated + 0)
190-
191-
192-func isSymbolK (accumulated,sym) = if ((sym == "K"))
193- then (accumulated + 1)
194- else (accumulated + 0)
195-
196-
197-func isSymbolS (accumulated,sym) = if ((sym == "S"))
198- then (accumulated + 1)
199- else (accumulated + 0)
200-
201-
202-func isSymbolT (accumulated,sym) = if ((sym == "T"))
203- then (accumulated + 1)
204- else (accumulated + 0)
205-
206-
207-func getAmountOrClear (amount) = if (contains(amount, "0"))
208- then ""
209- else amount
210-
211-
212-func asString (value) = match value {
213- case string: String =>
214- string
215- case _ =>
216- throw("wrong type, expected: String")
217-}
218125
219126
220127 func asInt (value) = match value {
221128 case int: Int =>
222129 int
223130 case _ =>
224- throw("wrong type, expected: Int")
131+ throw("BAI: wrong type, expected: Int")
225132 }
226-
227-
228-func composeGenericData (duckGen,duckIdKey,assetId,asset) = {
229- let farmGen = asString(invoke(this, "getGenFromName", [duckGen], nil))
230- if ((farmGen == farmGen))
231- then {
232- let amount = tryGetInteger(getDuckStatsKey(duckGen))
233- let quantity = tryGetInteger((("stats_" + farmGen) + "_quantity"))
234-[StringEntry(duckIdKey, toBase58String(assetId)), StringEntry(toBase58String(assetId), duckIdKey), IntegerEntry(getDuckStatsKey(duckGen), (amount + 1)), IntegerEntry((("stats_" + farmGen) + "_quantity"), (quantity + 1)), asset]
235- }
236- else throw("Strict value is not equal to itself.")
237- }
238-
239-
240-func finishDuckHatch (payments,txIdStr,owner,duckGenesString) = {
241- let ducklingFinish = invoke(getBabyDuckBreedingAddress(), "turnDucklingIntoDuck", nil, payments)
242- if ((ducklingFinish == ducklingFinish))
243- then {
244- let txId = fromBase58String(txIdStr)
245- let processStatusKey = getProcessStatusKey(owner, txId)
246- let duckIdKey = getDuckIdKey(owner, txId)
247- let processTxStatus = getStringValue(this, processStatusKey)
248- let finishHeightKey = getProcessFinishHeightKey(owner, txId)
249- let processFinishHeight = getIntegerValue(this, finishHeightKey)
250- if ((processTxStatus == HatchingFinished))
251- then {
252- let duckId = getStringValue(this, getDuckIdKey(owner, txId))
253- throw(("The duck was breeded and claimed already, here is the folowing: " + duckId))
254- }
255- else if ((processFinishHeight > height))
256- then throw((((("Breeding is not finished yet " + toString((processFinishHeight - height))) + " blocks remaining, it will take around ") + toString((processFinishHeight - height))) + " minutes"))
257- else {
258- let duckGen = if ((duckGenesString == ""))
259- then asString(invoke(this, "generateDuck", [txId, processFinishHeight, 0, 0, "", 0], nil))
260- else duckGenesString
261- if ((duckGen == duckGen))
262- then {
263- let description = (("{\"genotype\": \"" + duckGen) + "\", \"crossbreeding\": true}")
264- let asset = Issue(duckGen, description, 1, 0, false, unit, processFinishHeight)
265- let assetId = calculateAssetId(asset)
266- let parent1Id = tryGetString(getDuckParentKey(txId, 1))
267- let parent2Id = tryGetString(getDuckParentKey(txId, 2))
268- (composeGenericData(duckGen, duckIdKey, assetId, asset) ++ [StringEntry(processStatusKey, HatchingFinished), IntegerEntry((("asset_" + parent1Id) + "_children"), 1), IntegerEntry((("asset_" + parent2Id) + "_children"), 1), ScriptTransfer(addressFromStringValue(owner), 1, assetId), ScriptTransfer(addressFromStringValue(owner), 1, fromBase58String(parent1Id)), ScriptTransfer(addressFromStringValue(owner), 1, fromBase58String(parent2Id))])
269- }
270- else throw("Strict value is not equal to itself.")
271- }
272- }
273- else throw("Strict value is not equal to itself.")
274- }
275133
276134
277135 @Callable(i)
278136 func configureOracle (oracle) = if ((i.caller != this))
279- then throw("admin only")
137+ then throw("BCO: admin only")
280138 else [StringEntry("static_oracleAddress", oracle)]
281139
282140
283141
284142 @Callable(i)
285-func generateDuck (txId,hatchingFinishHeight,geneFromParent,genePostion,specifiqueGene,specifiqueGenePosition) = {
286- let colorRandom = getRandomNumber(4, txId, hatchingFinishHeight, 11)
287- let color = if ((colorRandom == 0))
288- then "Y"
289- else if ((colorRandom == 1))
290- then "G"
291- else if ((colorRandom == 2))
292- then "B"
293- else "R"
294- let parent1Id = fromBase58String(tryGetString(getDuckParentKey(txId, 1)))
295- let parent2Id = fromBase58String(tryGetString(getDuckParentKey(txId, 2)))
296- let parent1Gen = split(value(assetInfo(parent1Id)).name, "")
297- let parent2Gen = split(value(assetInfo(parent2Id)).name, "")
298- let gen = ((((((((((("DUCK-" + getRandomGen(parent1Gen[5], parent2Gen[5], 0, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + getRandomGen(parent1Gen[6], parent2Gen[6], 1, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + getRandomGen(parent1Gen[7], parent2Gen[7], 2, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + getRandomGen(parent1Gen[8], parent2Gen[8], 3, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + getRandomGen(parent1Gen[9], parent2Gen[9], 4, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + getRandomGen(parent1Gen[10], parent2Gen[10], 5, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + getRandomGen(parent1Gen[11], parent2Gen[11], 6, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + getRandomGen(parent1Gen[12], parent2Gen[12], 7, txId, hatchingFinishHeight, geneFromParent, genePostion, specifiqueGene, specifiqueGenePosition)) + "-") + determineGeneration(parent1Gen[14], parent2Gen[14])) + color)
299- $Tuple2(nil, gen)
143+func issueDuckling (address,txIdStr) = if ((i.caller != getBreederAddress()))
144+ then throw("BIFD: You can't issue free duckling")
145+ else {
146+ let asset = Issue("BABY-11111111-HZ", "", 1, 0, false, unit, height)
147+ let assetId = calculateAssetId(asset)
148+ $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))
149+ }
150+
151+
152+
153+@Callable(i)
154+func feedDuckling (ducklingId,maxFeedAmount) = {
155+ let addressString = toString(i.caller)
156+ let realDucklingId = if (if ((size(i.payments) != 1))
157+ then true
158+ else (value(i.payments[0]).assetId != getSpiceAssetId()))
159+ then throw("BFD: Bad payment attached (asset[s] or amount)")
160+ else if (getBool(keyDucklingGrown(ducklingId)))
161+ then throw("BFD: Duckling is already grown")
162+ else if ((ducklingId == ""))
163+ then throw("BFD: Please hatch a duckling first!")
164+ else {
165+ let ducklingOwner = tryGetString(keyOwner(ducklingId))
166+ let ducklingIdCheck = value(assetInfo(fromBase58String(ducklingId)))
167+ if ((assetBalance(i.caller, ducklingIdCheck.id) != 1))
168+ then throw("BFD: You're not the owner of the duckling")
169+ else if ((ducklingOwner != toString(i.caller)))
170+ then throw("BFD: You can only feed ducklings that you won/bought yourself!")
171+ else if ((ducklingIdCheck.issuer != this))
172+ then throw("BFD: Cant find duckling with such id")
173+ else {
174+ let ducklingIdString = toBase58String(ducklingIdCheck.id)
175+ ducklingIdString
176+ }
177+ }
178+ let kDucklingLastFedTs = keyDucklingFedLastTimestamp(ducklingId)
179+ let currentPayment = value(i.payments[0]).amount
180+ let kNewLevel = keyDucklingLevel(realDucklingId)
181+ let kTotalFeed = keyTotalFeed(realDucklingId)
182+ let totalFeed = tryGetInteger(kTotalFeed)
183+ let kFeedTxStats = ((("duckling_" + realDucklingId) + "_stat_") + toString(lastBlock.timestamp))
184+ if ((currentPayment > maxFeedAmount))
185+ then throw(("BFD: Cannot feed duckling for such amount, max feed amount is: " + toString(maxFeedAmount)))
186+ else {
187+ let calculateResults = calculateNewDucklingLevel(realDucklingId, currentPayment)
188+[IntegerEntry(kDucklingLastFedTs, lastBlock.timestamp), IntegerEntry(kTotalFeed, (totalFeed + currentPayment)), IntegerEntry(kFeedTxStats, currentPayment), StringEntry(kNewLevel, calculateResults._1), StringEntry((kFeedTxStats + "_debug"), makeString(calculateResults._2, ";"))]
189+ }
300190 }
301191
302192
303193
304194 @Callable(i)
305-func getGenFromName (assetName) = {
306- let genotype = split(dropRight(drop(assetName, 5), 3), "")
307- let generation = split(assetName, "")[14]
308- let gen = (((((((((((((getAmountOrClear((toString({
309- let $l = genotype
310- let $s = size($l)
311- let $acc0 = 0
312- func $f0_1 ($a,$i) = if (($i >= $s))
313- then $a
314- else isSymbolA($a, $l[$i])
315-
316- func $f0_2 ($a,$i) = if (($i >= $s))
317- then $a
318- else throw("List size exceeds 8")
319-
320- $f0_2($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)
321- }) + "A")) + getAmountOrClear((toString({
322- let $l = genotype
323- let $s = size($l)
324- let $acc0 = 0
325- func $f1_1 ($a,$i) = if (($i >= $s))
326- then $a
327- else isSymbolB($a, $l[$i])
328-
329- func $f1_2 ($a,$i) = if (($i >= $s))
330- then $a
331- else throw("List size exceeds 8")
332-
333- $f1_2($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
334- }) + "B"))) + getAmountOrClear((toString({
335- let $l = genotype
336- let $s = size($l)
337- let $acc0 = 0
338- func $f2_1 ($a,$i) = if (($i >= $s))
339- then $a
340- else isSymbolC($a, $l[$i])
341-
342- func $f2_2 ($a,$i) = if (($i >= $s))
343- then $a
344- else throw("List size exceeds 8")
345-
346- $f2_2($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
347- }) + "C"))) + getAmountOrClear((toString({
348- let $l = genotype
349- let $s = size($l)
350- let $acc0 = 0
351- func $f3_1 ($a,$i) = if (($i >= $s))
352- then $a
353- else isSymbolD($a, $l[$i])
354-
355- func $f3_2 ($a,$i) = if (($i >= $s))
356- then $a
357- else throw("List size exceeds 8")
358-
359- $f3_2($f3_1($f3_1($f3_1($f3_1($f3_1($f3_1($f3_1($f3_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
360- }) + "D"))) + getAmountOrClear((toString({
361- let $l = genotype
362- let $s = size($l)
363- let $acc0 = 0
364- func $f4_1 ($a,$i) = if (($i >= $s))
365- then $a
366- else isSymbolE($a, $l[$i])
367-
368- func $f4_2 ($a,$i) = if (($i >= $s))
369- then $a
370- else throw("List size exceeds 8")
371-
372- $f4_2($f4_1($f4_1($f4_1($f4_1($f4_1($f4_1($f4_1($f4_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
373- }) + "E"))) + getAmountOrClear((toString({
374- let $l = genotype
375- let $s = size($l)
376- let $acc0 = 0
377- func $f5_1 ($a,$i) = if (($i >= $s))
378- then $a
379- else isSymbolF($a, $l[$i])
380-
381- func $f5_2 ($a,$i) = if (($i >= $s))
382- then $a
383- else throw("List size exceeds 8")
384-
385- $f5_2($f5_1($f5_1($f5_1($f5_1($f5_1($f5_1($f5_1($f5_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
386- }) + "F"))) + getAmountOrClear((toString({
387- let $l = genotype
388- let $s = size($l)
389- let $acc0 = 0
390- func $f6_1 ($a,$i) = if (($i >= $s))
391- then $a
392- else isSymbolG($a, $l[$i])
393-
394- func $f6_2 ($a,$i) = if (($i >= $s))
395- then $a
396- else throw("List size exceeds 8")
397-
398- $f6_2($f6_1($f6_1($f6_1($f6_1($f6_1($f6_1($f6_1($f6_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
399- }) + "G"))) + getAmountOrClear((toString({
400- let $l = genotype
401- let $s = size($l)
402- let $acc0 = 0
403- func $f7_1 ($a,$i) = if (($i >= $s))
404- then $a
405- else isSymbolH($a, $l[$i])
406-
407- func $f7_2 ($a,$i) = if (($i >= $s))
408- then $a
409- else throw("List size exceeds 8")
410-
411- $f7_2($f7_1($f7_1($f7_1($f7_1($f7_1($f7_1($f7_1($f7_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
412- }) + "H"))) + getAmountOrClear((toString({
413- let $l = genotype
414- let $s = size($l)
415- let $acc0 = 0
416- func $f8_1 ($a,$i) = if (($i >= $s))
417- then $a
418- else isSymbolI($a, $l[$i])
419-
420- func $f8_2 ($a,$i) = if (($i >= $s))
421- then $a
422- else throw("List size exceeds 8")
423-
424- $f8_2($f8_1($f8_1($f8_1($f8_1($f8_1($f8_1($f8_1($f8_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
425- }) + "I"))) + getAmountOrClear((toString({
426- let $l = genotype
427- let $s = size($l)
428- let $acc0 = 0
429- func $f9_1 ($a,$i) = if (($i >= $s))
430- then $a
431- else isSymbolK($a, $l[$i])
432-
433- func $f9_2 ($a,$i) = if (($i >= $s))
434- then $a
435- else throw("List size exceeds 8")
436-
437- $f9_2($f9_1($f9_1($f9_1($f9_1($f9_1($f9_1($f9_1($f9_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
438- }) + "K"))) + getAmountOrClear((toString({
439- let $l = genotype
440- let $s = size($l)
441- let $acc0 = 0
442- func $f10_1 ($a,$i) = if (($i >= $s))
443- then $a
444- else isSymbolS($a, $l[$i])
445-
446- func $f10_2 ($a,$i) = if (($i >= $s))
447- then $a
448- else throw("List size exceeds 8")
449-
450- $f10_2($f10_1($f10_1($f10_1($f10_1($f10_1($f10_1($f10_1($f10_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
451- }) + "S"))) + getAmountOrClear((toString({
452- let $l = genotype
453- let $s = size($l)
454- let $acc0 = 0
455- func $f11_1 ($a,$i) = if (($i >= $s))
456- then $a
457- else isSymbolT($a, $l[$i])
458-
459- func $f11_2 ($a,$i) = if (($i >= $s))
460- then $a
461- else throw("List size exceeds 8")
462-
463- $f11_2($f11_1($f11_1($f11_1($f11_1($f11_1($f11_1($f11_1($f11_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8)
464- }) + "T"))) + "-") + generation)
465- $Tuple2(nil, gen)
466- }
467-
468-
469-
470-@Callable(i)
471-func validateAndGetChildren (assetId) = if (!(checkAssetInIncubator(assetId)))
472- then throw((("You need to attach a valid NFT-duck. " + assetId) + " is invalid!"))
195+func turnDucklingIntoDuck () = if ((i.caller != getBreederAddress()))
196+ then throw("BIFD: You can't turn duckling")
473197 else {
474- let children = tryGetInteger((("asset_" + assetId) + "_children"))
475- $Tuple2(nil, children)
198+ let address = toString(i.caller)
199+ let txId = toBase58String(i.transactionId)
200+ let lastIssuedDucklingTs = tryGetInteger(KGlobalIssuedTimestamp)
201+ let fiveMinInMs = ((1 * 60) * 1000)
202+ let timeDiff = (lastBlock.timestamp - (lastIssuedDucklingTs + fiveMinInMs))
203+ if (if ((lastIssuedDucklingTs > 0))
204+ then (0 > timeDiff)
205+ else false)
206+ then throw((("BTD: Can issue ducklings only once per 1 minutes, please wait for " + toString(fraction(timeDiff, 1, 1000))) + " sec."))
207+ else if ((size(i.payments) != 1))
208+ then throw("BTD: Bad payment attached (asset[s] or amount)")
209+ else {
210+ let pmt = value(assetInfo(value(value(i.payments[0]).assetId)))
211+ if ((toBigInt(100) > getCurrentLevelBigInt(toBase58String(pmt.id))))
212+ then throw("BTD: Duckling is not grown yet...")
213+ else if ((pmt.issuer != this))
214+ then throw("BTD: Can use only ducklings from this dApp")
215+ else {
216+ let kDucklingGrown = keyDucklingGrown(toBase58String(pmt.id))
217+[BooleanEntry(kDucklingGrown, true), IntegerEntry(KGlobalIssuedTimestamp, lastBlock.timestamp)]
218+ }
219+ }
476220 }
477221
478222
479-
480-@Callable(i)
481-func createDuckSpecialGenes (address,duckGen,children) = if (if ((i.caller != getItemsAddress()))
482- then (i.caller != this)
483- else false)
484- then throw("admin or items only")
485- else {
486- let txId = i.transactionId
487- let description = (("{\"genotype\": \"" + duckGen) + "\", \"crossbreeding\": true}")
488- let asset = Issue(duckGen, description, 1, 0, false)
489- let assetId = calculateAssetId(asset)
490- let duckIdKey = getDuckIdKey(toString(i.caller), txId)
491- let farmGen = asString(invoke(this, "getGenFromName", [duckGen], nil))
492- if ((farmGen == farmGen))
493- then (composeGenericData(duckGen, duckIdKey, assetId, asset) ++ [IntegerEntry((("asset_" + toBase58String(assetId)) + "_children"), children), ScriptTransfer(Address(address), 1, assetId)])
494- else throw("Strict value is not equal to itself.")
495- }
496-
497-
498-
499-@Callable(i)
500-func startDuckBreeding () = {
501- let firstPayment = value(i.payments[0])
502- let secondPayment = value(i.payments[1])
503- let thirdPayment = value(i.payments[2])
504- let firstAssetId = toBase58String(value(firstPayment.assetId))
505- let secondAssetId = toBase58String(value(secondPayment.assetId))
506- let thirdAssetId = value(thirdPayment.assetId)
507- if (if ((firstPayment.amount != 1))
508- then true
509- else (secondPayment.amount != 1))
510- then throw("NFT is not attached")
511- else if ((thirdAssetId != getEggAssetId()))
512- then throw("BSDB: wrong payment added!")
513- else if ((thirdPayment.amount != getDucklingPrice()))
514- then throw("BSDB: not enough payment added!")
515- else {
516- let children1 = asInt(invoke(this, "validateAndGetChildren", [firstAssetId], nil))
517- if ((children1 == children1))
518- then {
519- let children2 = asInt(invoke(this, "validateAndGetChildren", [secondAssetId], nil))
520- if ((children2 == children2))
521- then if (if ((children1 > 0))
522- then true
523- else (children2 > 0))
524- then throw("One duck can be used for breeding only once in its lifetime.")
525- else {
526- let breededStatus = canBeBreeded(fromBase58String(firstAssetId), fromBase58String(secondAssetId))
527- if ((breededStatus != "true"))
528- then throw(("These ducks cannot be breeded: " + breededStatus))
529- else {
530- let ducklingGen = asString(invoke(getBabyDuckBreedingAddress(), "issueDuckling", [toString(i.caller), toBase58String(i.transactionId)], nil))
531- if ((ducklingGen == ducklingGen))
532- then [StringEntry(getDuckParentKey(i.transactionId, 1), firstAssetId), StringEntry(getDuckParentKey(i.transactionId, 2), secondAssetId), StringEntry(getProcessStatusKey(toString(i.caller), i.transactionId), HatchingStarted), IntegerEntry(getProcessFinishHeightKey(toString(i.caller), i.transactionId), (height + delayForHatching)), StringEntry(getDucklingKey(toString(i.caller), i.transactionId), ducklingGen)]
533- else throw("Strict value is not equal to itself.")
534- }
535- }
536- else throw("Strict value is not equal to itself.")
537- }
538- else throw("Strict value is not equal to itself.")
539- }
540- }
541-
542-
543-
544-@Callable(i)
545-func finishDuckHatchingItems (txIdStr,duckGenesString) = if (if ((i.caller != getItemsAddress()))
546- then (duckGenesString != "")
547- else false)
548- then throw("Only items can create fixed genes")
549- else {
550- let owner = toString(i.originCaller)
551- finishDuckHatch(i.payments, txIdStr, owner, duckGenesString)
552- }
553-
554-
555-
556-@Callable(i)
557-func finishDuckHatching (txIdStr) = {
558- let owner = toString(i.caller)
559- finishDuckHatch(i.payments, txIdStr, owner, "")
560- }
561-
562-
563-
564-@Callable(i)
565-func reduceRarity (assetId,farmGen) = {
566- let asset = fromBase58String(assetId)
567- if (if (if ((i.caller != getItemsAddress()))
568- then (i.caller != getRebirthAddress())
569- else false)
570- then (i.caller != this)
571- else false)
572- then throw("admin, items or rebirth only")
573- else {
574- let duckGen = value(assetInfo(asset)).name
575-[IntegerEntry(getDuckStatsKey(duckGen), (tryGetInteger(getDuckStatsKey(duckGen)) - 1)), IntegerEntry((("stats_" + farmGen) + "_quantity"), (tryGetInteger((("stats_" + farmGen) + "_quantity")) - 1))]
576- }
577- }
578-
223+@Verifier(tx)
224+func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
579225

github/deemru/w8io/3ef1775 
62.49 ms