tx · AMTmWknLTqJmBSgN7jgk2LLmvqVpDTpgciCkWMSgbXzW 3MxbD7vwyGjwsRxT8fmMB9fngo59VfHcrea: -0.00900000 Waves 2022.08.18 21:11 [2190263] smart account 3MxbD7vwyGjwsRxT8fmMB9fngo59VfHcrea > SELF 0.00000000 Waves
{ "type": 13, "id": "AMTmWknLTqJmBSgN7jgk2LLmvqVpDTpgciCkWMSgbXzW", "fee": 900000, "feeAssetId": null, "timestamp": 1660846313384, "version": 2, "chainId": 84, "sender": "3MxbD7vwyGjwsRxT8fmMB9fngo59VfHcrea", "senderPublicKey": "7kBiESqWjiW6nNeStcbrVX9XRQkWmUM51MZFRZNQEVfR", "proofs": [ "3xzRtVs6iJ3BwPUjRBgAKXk5Jvy7dwA7YZJTBes9WLay2BkxgYLHBrAjbdAaWsLaGgwMnFqddGQCpS2QrPdczwSr" ], "script": "base64:AAIFAAAAAAAAABEIAhIDCgEBEgMKAQgSAwoBCAAAAAgAAAAABWFkbWluAQAAABoBVNjzO1N+o4TglJtDoCbGH7hRDlWj6ppSJAAAAAALY29hbEFzc2V0SWQBAAAAIDHg1fVAt3Hphex6Dm+3r1K6I7ymQhydmjuZJeiJho7mAQAAAA10cnlHZXRJbnRlZ2VyAAAAAQAAAANrZXkEAAAAByRtYXRjaDAJAAQaAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAANJbnQEAAAAAWIFAAAAByRtYXRjaDAFAAAAAWIAAAAAAAAAAAABAAAADXRyeUdldEJvb2xlYW4AAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABBsAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAB0Jvb2xlYW4EAAAAAWIFAAAAByRtYXRjaDAFAAAAAWIHAQAAAA5nZXRBc3NldFN0cmluZwAAAAEAAAAHYXNzZXRJZAQAAAAHJG1hdGNoMAUAAAAHYXNzZXRJZAMJAAABAAAAAgUAAAAHJ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spentComplexity": 0 } View: original | compacted Prev: 4sxfrA26HCjTiS8nvLZm596VCGSzNukBUEzGvAPXbu5G Next: none Diff:
Old | New | Differences | |
---|---|---|---|
13 | 13 | } | |
14 | 14 | ||
15 | 15 | ||
16 | + | func tryGetBoolean (key) = match getBoolean(this, key) { | |
17 | + | case b: Boolean => | |
18 | + | b | |
19 | + | case _ => | |
20 | + | false | |
21 | + | } | |
22 | + | ||
23 | + | ||
24 | + | func getAssetString (assetId) = match assetId { | |
25 | + | case b: ByteVector => | |
26 | + | toBase58String(b) | |
27 | + | case _ => | |
28 | + | "WAVES" | |
29 | + | } | |
30 | + | ||
31 | + | ||
32 | + | func tryGetString (key) = match getString(this, key) { | |
33 | + | case b: String => | |
34 | + | b | |
35 | + | case _ => | |
36 | + | "" | |
37 | + | } | |
38 | + | ||
39 | + | ||
40 | + | func tryGetBinary (key) = match getBinary(this, key) { | |
41 | + | case b: ByteVector => | |
42 | + | b | |
43 | + | case _ => | |
44 | + | base58'' | |
45 | + | } | |
46 | + | ||
47 | + | ||
48 | + | func getAssetBytes (assetIdStr) = if ((assetIdStr == "WAVES")) | |
49 | + | then unit | |
50 | + | else fromBase58String(assetIdStr) | |
51 | + | ||
52 | + | ||
16 | 53 | @Callable(i) | |
17 | - | func mintNazi () = { | |
18 | - | let caller = toBase58String(i.caller.bytes) | |
19 | - | let lastMint = tryGetInteger(("lastMint_" + caller)) | |
20 | - | if (if ((lastMint > 0)) | |
21 | - | then ((lastMint + 5) > height) | |
22 | - | else false) | |
23 | - | then throw("You need to wait 5 blocks after last mint") | |
24 | - | else [IntegerEntry(("lastMint_" + caller), height), Reissue(coalAssetId, 1, true), ScriptTransfer(i.caller, 1, coalAssetId)] | |
54 | + | func createFurnace (lifetime) = if ((toBase58String(i.caller.bytes) != toBase58String(admin))) | |
55 | + | then throw("You cannot create furnace") | |
56 | + | else if ((size(i.payments) != 1)) | |
57 | + | then throw("You should to provide reward") | |
58 | + | else { | |
59 | + | let rewardAmount = i.payments[0].amount | |
60 | + | let rewardAssetId = i.payments[0].assetId | |
61 | + | let newFurnacesAmount = (tryGetInteger("global_furnacesAmount") + 1) | |
62 | + | let furnaceId = toString(newFurnacesAmount) | |
63 | + | [IntegerEntry("global_furnacesAmount", newFurnacesAmount), IntegerEntry((("furnace_" + furnaceId) + "_lifetime"), lifetime), IntegerEntry((("furnace_" + furnaceId) + "_rewardAmount"), rewardAmount), StringEntry((("furnace_" + furnaceId) + "_rewardAssetId"), getAssetString(rewardAssetId))] | |
64 | + | } | |
65 | + | ||
66 | + | ||
67 | + | ||
68 | + | @Callable(i) | |
69 | + | func burn (furnaceId) = { | |
70 | + | let isFinished = tryGetBoolean((("furnace_" + furnaceId) + "_finished")) | |
71 | + | let lifetime = tryGetInteger((("furnace_" + furnaceId) + "_lifetime")) | |
72 | + | let lastBurn = tryGetInteger((("furnace_" + furnaceId) + "_lastBurn")) | |
73 | + | let finisHeight = (lastBurn + lifetime) | |
74 | + | if (isFinished) | |
75 | + | then throw("Already finished") | |
76 | + | else if ((lifetime == 0)) | |
77 | + | then throw("Cannot find furnace") | |
78 | + | else if (if ((lastBurn > 0)) | |
79 | + | then (height >= finisHeight) | |
80 | + | else false) | |
81 | + | then throw("Time is run out") | |
82 | + | else if ((size(i.payments) != 1)) | |
83 | + | then throw("You should to provide payment") | |
84 | + | else if ((i.payments[0].assetId != coalAssetId)) | |
85 | + | then throw("Invalid coal") | |
86 | + | else if ((i.payments[0].amount != 1)) | |
87 | + | then throw("You can burn only 1 coal") | |
88 | + | else { | |
89 | + | let callerAddress = toBase58String(i.caller.bytes) | |
90 | + | [Burn(coalAssetId, i.payments[0].amount), IntegerEntry((("furnace_" + furnaceId) + "_lastBurn"), height), StringEntry((("furnace_" + furnaceId) + "_lastStoker"), callerAddress)] | |
91 | + | } | |
92 | + | } | |
93 | + | ||
94 | + | ||
95 | + | ||
96 | + | @Callable(i) | |
97 | + | func claim (furnaceId) = { | |
98 | + | let isFinished = tryGetBoolean((("furnace_" + furnaceId) + "_finished")) | |
99 | + | let lifetime = tryGetInteger((("furnace_" + furnaceId) + "_lifetime")) | |
100 | + | let lastBurn = tryGetInteger((("furnace_" + furnaceId) + "_lastBurn")) | |
101 | + | let rewardAsset = tryGetString((("furnace_" + furnaceId) + "_rewardAssetId")) | |
102 | + | let lastStoker = tryGetString((("furnace_" + furnaceId) + "_lastStoker")) | |
103 | + | let rewardAmount = tryGetInteger((("furnace_" + furnaceId) + "_rewardAmount")) | |
104 | + | let finishHeight = (lastBurn + lifetime) | |
105 | + | if (isFinished) | |
106 | + | then throw("Already finished") | |
107 | + | else if ((lifetime == 0)) | |
108 | + | then throw("Cannot find furnace") | |
109 | + | else if ((lastBurn == 0)) | |
110 | + | then throw("Furnace not found") | |
111 | + | else if ((finishHeight > height)) | |
112 | + | then throw("Time has not run out") | |
113 | + | else if ((rewardAsset == "")) | |
114 | + | then throw("Cannot find reward asset") | |
115 | + | else if ((lastStoker == "")) | |
116 | + | then throw("Cannot find last stoker") | |
117 | + | else if ((rewardAmount == 0)) | |
118 | + | then throw("Reward already sent to winner") | |
119 | + | else [BooleanEntry((("furnace_" + furnaceId) + "_finished"), true), ScriptTransfer(Address(fromBase58String(lastStoker)), rewardAmount, getAssetBytes(rewardAsset))] | |
25 | 120 | } | |
26 | 121 | ||
27 | 122 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let admin = base58'3N9hD7PnazZB7wbwFmr7fw28UKXj593YmTR' | |
5 | 5 | ||
6 | 6 | let coalAssetId = base58'4MhpjsP1MPpC49v6zBr7eAAEPZdmHWcrSqcSv8tZcpjo' | |
7 | 7 | ||
8 | 8 | func tryGetInteger (key) = match getInteger(this, key) { | |
9 | 9 | case b: Int => | |
10 | 10 | b | |
11 | 11 | case _ => | |
12 | 12 | 0 | |
13 | 13 | } | |
14 | 14 | ||
15 | 15 | ||
16 | + | func tryGetBoolean (key) = match getBoolean(this, key) { | |
17 | + | case b: Boolean => | |
18 | + | b | |
19 | + | case _ => | |
20 | + | false | |
21 | + | } | |
22 | + | ||
23 | + | ||
24 | + | func getAssetString (assetId) = match assetId { | |
25 | + | case b: ByteVector => | |
26 | + | toBase58String(b) | |
27 | + | case _ => | |
28 | + | "WAVES" | |
29 | + | } | |
30 | + | ||
31 | + | ||
32 | + | func tryGetString (key) = match getString(this, key) { | |
33 | + | case b: String => | |
34 | + | b | |
35 | + | case _ => | |
36 | + | "" | |
37 | + | } | |
38 | + | ||
39 | + | ||
40 | + | func tryGetBinary (key) = match getBinary(this, key) { | |
41 | + | case b: ByteVector => | |
42 | + | b | |
43 | + | case _ => | |
44 | + | base58'' | |
45 | + | } | |
46 | + | ||
47 | + | ||
48 | + | func getAssetBytes (assetIdStr) = if ((assetIdStr == "WAVES")) | |
49 | + | then unit | |
50 | + | else fromBase58String(assetIdStr) | |
51 | + | ||
52 | + | ||
16 | 53 | @Callable(i) | |
17 | - | func mintNazi () = { | |
18 | - | let caller = toBase58String(i.caller.bytes) | |
19 | - | let lastMint = tryGetInteger(("lastMint_" + caller)) | |
20 | - | if (if ((lastMint > 0)) | |
21 | - | then ((lastMint + 5) > height) | |
22 | - | else false) | |
23 | - | then throw("You need to wait 5 blocks after last mint") | |
24 | - | else [IntegerEntry(("lastMint_" + caller), height), Reissue(coalAssetId, 1, true), ScriptTransfer(i.caller, 1, coalAssetId)] | |
54 | + | func createFurnace (lifetime) = if ((toBase58String(i.caller.bytes) != toBase58String(admin))) | |
55 | + | then throw("You cannot create furnace") | |
56 | + | else if ((size(i.payments) != 1)) | |
57 | + | then throw("You should to provide reward") | |
58 | + | else { | |
59 | + | let rewardAmount = i.payments[0].amount | |
60 | + | let rewardAssetId = i.payments[0].assetId | |
61 | + | let newFurnacesAmount = (tryGetInteger("global_furnacesAmount") + 1) | |
62 | + | let furnaceId = toString(newFurnacesAmount) | |
63 | + | [IntegerEntry("global_furnacesAmount", newFurnacesAmount), IntegerEntry((("furnace_" + furnaceId) + "_lifetime"), lifetime), IntegerEntry((("furnace_" + furnaceId) + "_rewardAmount"), rewardAmount), StringEntry((("furnace_" + furnaceId) + "_rewardAssetId"), getAssetString(rewardAssetId))] | |
64 | + | } | |
65 | + | ||
66 | + | ||
67 | + | ||
68 | + | @Callable(i) | |
69 | + | func burn (furnaceId) = { | |
70 | + | let isFinished = tryGetBoolean((("furnace_" + furnaceId) + "_finished")) | |
71 | + | let lifetime = tryGetInteger((("furnace_" + furnaceId) + "_lifetime")) | |
72 | + | let lastBurn = tryGetInteger((("furnace_" + furnaceId) + "_lastBurn")) | |
73 | + | let finisHeight = (lastBurn + lifetime) | |
74 | + | if (isFinished) | |
75 | + | then throw("Already finished") | |
76 | + | else if ((lifetime == 0)) | |
77 | + | then throw("Cannot find furnace") | |
78 | + | else if (if ((lastBurn > 0)) | |
79 | + | then (height >= finisHeight) | |
80 | + | else false) | |
81 | + | then throw("Time is run out") | |
82 | + | else if ((size(i.payments) != 1)) | |
83 | + | then throw("You should to provide payment") | |
84 | + | else if ((i.payments[0].assetId != coalAssetId)) | |
85 | + | then throw("Invalid coal") | |
86 | + | else if ((i.payments[0].amount != 1)) | |
87 | + | then throw("You can burn only 1 coal") | |
88 | + | else { | |
89 | + | let callerAddress = toBase58String(i.caller.bytes) | |
90 | + | [Burn(coalAssetId, i.payments[0].amount), IntegerEntry((("furnace_" + furnaceId) + "_lastBurn"), height), StringEntry((("furnace_" + furnaceId) + "_lastStoker"), callerAddress)] | |
91 | + | } | |
92 | + | } | |
93 | + | ||
94 | + | ||
95 | + | ||
96 | + | @Callable(i) | |
97 | + | func claim (furnaceId) = { | |
98 | + | let isFinished = tryGetBoolean((("furnace_" + furnaceId) + "_finished")) | |
99 | + | let lifetime = tryGetInteger((("furnace_" + furnaceId) + "_lifetime")) | |
100 | + | let lastBurn = tryGetInteger((("furnace_" + furnaceId) + "_lastBurn")) | |
101 | + | let rewardAsset = tryGetString((("furnace_" + furnaceId) + "_rewardAssetId")) | |
102 | + | let lastStoker = tryGetString((("furnace_" + furnaceId) + "_lastStoker")) | |
103 | + | let rewardAmount = tryGetInteger((("furnace_" + furnaceId) + "_rewardAmount")) | |
104 | + | let finishHeight = (lastBurn + lifetime) | |
105 | + | if (isFinished) | |
106 | + | then throw("Already finished") | |
107 | + | else if ((lifetime == 0)) | |
108 | + | then throw("Cannot find furnace") | |
109 | + | else if ((lastBurn == 0)) | |
110 | + | then throw("Furnace not found") | |
111 | + | else if ((finishHeight > height)) | |
112 | + | then throw("Time has not run out") | |
113 | + | else if ((rewardAsset == "")) | |
114 | + | then throw("Cannot find reward asset") | |
115 | + | else if ((lastStoker == "")) | |
116 | + | then throw("Cannot find last stoker") | |
117 | + | else if ((rewardAmount == 0)) | |
118 | + | then throw("Reward already sent to winner") | |
119 | + | else [BooleanEntry((("furnace_" + furnaceId) + "_finished"), true), ScriptTransfer(Address(fromBase58String(lastStoker)), rewardAmount, getAssetBytes(rewardAsset))] | |
25 | 120 | } | |
26 | 121 | ||
27 | 122 | ||
28 | 123 | @Verifier(tx) | |
29 | 124 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
30 | 125 |
github/deemru/w8io/169f3d6 26.33 ms ◑