tx · DBKHQbpqy3hPAy3BuFh3muybWBLHSRjd9XADWRMDmuy7 3N4Kzbxu521DHPxcgrmZ4XUqN2kF6TqLTzs: -0.01000000 Waves 2023.08.29 10:58 [2731717] smart account 3N4Kzbxu521DHPxcgrmZ4XUqN2kF6TqLTzs > SELF 0.00000000 Waves
{ "type": 13, "id": "DBKHQbpqy3hPAy3BuFh3muybWBLHSRjd9XADWRMDmuy7", "fee": 1000000, "feeAssetId": null, "timestamp": 1693296006053, "version": 2, "chainId": 84, "sender": "3N4Kzbxu521DHPxcgrmZ4XUqN2kF6TqLTzs", "senderPublicKey": "8yQuxvQ2qLzXJrgbKZHbsfnNNjuU5wfHheyVujdALGsF", "proofs": [ "4Bsj9RcdKsWJLf4e2AVwy8j3da3Kiv5SYEVSTpChFte47n8Jqy6emjykV2GVmR5S7weAXPmjsg8SKUYBswfGrT3H" ], "script": "base64:BgITCAISABIAEgQKAggBEgUKAwgBCAwADmxvdHRlcnlBc3NldElECQDZBAECLDNMejIzbVNVdlQxRXN3Y0JuMnNVUllKRzJhdDhyRzVhRnVVclRBd2FQTTZRAAp0aWNrZXRTaXplAAEBEGdldEludGVnZXJPckVsc2UCA2tleQN2YWwJAQt2YWx1ZU9yRWxzZQIJAJ8IAQUDa2V5BQN2YWwBD2dldFN0cmluZ09yRWxzZQIDa2V5A3ZhbAkBC3ZhbHVlT3JFbHNlAgkAoggBBQNrZXkFA3ZhbAECbWsBAXgJALkJAgUBeAIBXwERa2V5QWRyVG90YWxTdGFrZWQBA2FkcgkBAm1rAQkAzAgCAgNhZHIJAMwIAgUDYWRyCQDMCAICC3RvdGFsU3Rha2VkBQNuaWwBFWtleUxvdHRlcnlUb3RhbFN0YWtlZAELbG90dGVyeU5hbWUJAQJtawEJAMwIAgIHbG90dGVyeQkAzAgCBQtsb3R0ZXJ5TmFtZQkAzAgCAgt0b3RhbFN0YWtlZAUDbmlsARhrZXlBZHJMb3R0ZXJ5VG90YWxTdGFrZWQCC2xvdHRlcnlOYW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cgMIBQFpBmNhbGxlcgUJYXZhaWxhYmxlBQ5sb3R0ZXJ5QXNzZXRJRAkAzAgCCQEMSW50ZWdlckVudHJ5AgUPX2FkclRvdGFsU3Rha2VkCQBlAgUOYWRyVG90YWxTdGFrZWQFCWF2YWlsYWJsZQUDbmlsAWkBC2luaXRMb3R0ZXJ5Agtsb3R0ZXJ5TmFtZRJsb3R0ZXJ5RmluYWxIZWlnaHQDCQECIT0CCAUBaQZjYWxsZXIFBHRoaXMJAAIBAgphZG1pbiBvbmx5CQDMCAIJAQtTdHJpbmdFbnRyeQIFEl9hY3RpdmVMb3R0ZXJ5TmFtZQULbG90dGVyeU5hbWUJAMwIAgkBDEludGVnZXJFbnRyeQIJARVrZXlMb3R0ZXJ5RmluYWxIZWlnaHQBBQtsb3R0ZXJ5TmFtZQUSbG90dGVyeUZpbmFsSGVpZ2h0CQDMCAIJAQxJbnRlZ2VyRW50cnkCCQEVa2V5TG90dGVyeVRvdGFsU3Rha2VkAQULbG90dGVyeU5hbWUAAAUDbmlsAWkBDGRlY2xhcmVQcml6ZQMLbG90dGVyeU5hbWUHcHJpemVJZApwcml6ZVZhbHVlAwkBAiE9AggFAWkGY2FsbGVyBQR0aGlzCQACAQIKYWRtaW4gb25seQkAzAgCCQELU3RyaW5nRW50cnkCCQEUa2V5TG90dGVyeVByaXplVmFsdWUCBQtsb3R0ZXJ5TmFtZQUHcHJpemVJZAUKcHJpemVWYWx1ZQUDbmlsAQJ0eAEGdmVyaWZ5AAkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAgFAnR4D3NlbmRlclB1YmxpY0tlebsJerI=", "height": 2731717, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: FxpiGXxEC6kAsBUbBeZCsWk35CeNb8ehbVbCBNrCDTDy Next: 3RbYyiDCt9CZiqqLH63b674EmbMfX6vVLA1AxFeR41JU Diff:
Old | New | Differences | |
---|---|---|---|
6 | 6 | let ticketSize = 1 | |
7 | 7 | ||
8 | 8 | func getIntegerOrElse (key,val) = valueOrElse(getInteger(key), val) | |
9 | + | ||
10 | + | ||
11 | + | func getStringOrElse (key,val) = valueOrElse(getString(key), val) | |
9 | 12 | ||
10 | 13 | ||
11 | 14 | func mk (x) = makeString(x, "_") | |
23 | 26 | func keyLotteryFinalHeight (lotteryName) = mk(["lottery", lotteryName, "finalHeight"]) | |
24 | 27 | ||
25 | 28 | ||
29 | + | func keyLotteryPrizeValue (lotteryName,prizeID) = mk(["lottery", lotteryName, "prize", toString(prizeID), "value"]) | |
30 | + | ||
31 | + | ||
26 | 32 | let _activeLotteryName = mk(["param", "activeLotteryName"]) | |
27 | 33 | ||
28 | - | ||
29 | - | ||
30 | - | ||
31 | - | then "" | |
32 | - | else { | |
33 | - | let | |
34 | - | | |
35 | - | | |
36 | - | | |
37 | - | | |
38 | - | ||
34 | + | func activeLotteryName () = { | |
35 | + | let lotteryName = getStringOrElse(_activeLotteryName, "") | |
36 | + | if ((lotteryName == "")) | |
37 | + | then "" | |
38 | + | else { | |
39 | + | let lotteryFinalHeight = getIntegerValue(keyLotteryFinalHeight(lotteryName)) | |
40 | + | if (((height - 1) >= lotteryFinalHeight)) | |
41 | + | then "" | |
42 | + | else lotteryName | |
43 | + | } | |
44 | + | } | |
39 | 45 | ||
40 | 46 | ||
41 | 47 | @Callable(i) | |
91 | 97 | @Callable(i) | |
92 | 98 | func initLottery (lotteryName,lotteryFinalHeight) = if ((i.caller != this)) | |
93 | 99 | then throw("admin only") | |
94 | - | else [ | |
100 | + | else [StringEntry(_activeLotteryName, lotteryName), IntegerEntry(keyLotteryFinalHeight(lotteryName), lotteryFinalHeight), IntegerEntry(keyLotteryTotalStaked(lotteryName), 0)] | |
95 | 101 | ||
96 | 102 | ||
97 | 103 | ||
98 | 104 | @Callable(i) | |
99 | - | func call () = { | |
100 | - | let asset = Issue("Asset", "", 1, 0, true, unit, 0) | |
101 | - | let assetId = calculateAssetId(asset) | |
102 | - | [BinaryEntry("bin", base58''), BooleanEntry("bool", true), IntegerEntry("int", 1), StringEntry("str", ""), DeleteEntry("str"), asset, Reissue(assetId, 1, false), Burn(assetId, 1), ScriptTransfer(i.caller, 1, assetId)] | |
103 | - | } | |
105 | + | func declarePrize (lotteryName,prizeId,prizeValue) = if ((i.caller != this)) | |
106 | + | then throw("admin only") | |
107 | + | else [StringEntry(keyLotteryPrizeValue(lotteryName, prizeId), prizeValue)] | |
104 | 108 | ||
105 | 109 | ||
106 | 110 | @Verifier(tx) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let lotteryAssetID = fromBase58String("3Lz23mSUvT1EswcBn2sURYJG2at8rG5aFuUrTAwaPM6Q") | |
5 | 5 | ||
6 | 6 | let ticketSize = 1 | |
7 | 7 | ||
8 | 8 | func getIntegerOrElse (key,val) = valueOrElse(getInteger(key), val) | |
9 | + | ||
10 | + | ||
11 | + | func getStringOrElse (key,val) = valueOrElse(getString(key), val) | |
9 | 12 | ||
10 | 13 | ||
11 | 14 | func mk (x) = makeString(x, "_") | |
12 | 15 | ||
13 | 16 | ||
14 | 17 | func keyAdrTotalStaked (adr) = mk(["adr", adr, "totalStaked"]) | |
15 | 18 | ||
16 | 19 | ||
17 | 20 | func keyLotteryTotalStaked (lotteryName) = mk(["lottery", lotteryName, "totalStaked"]) | |
18 | 21 | ||
19 | 22 | ||
20 | 23 | func keyAdrLotteryTotalStaked (lotteryName,adr) = mk(["lottery", lotteryName, adr, "totalStaked"]) | |
21 | 24 | ||
22 | 25 | ||
23 | 26 | func keyLotteryFinalHeight (lotteryName) = mk(["lottery", lotteryName, "finalHeight"]) | |
24 | 27 | ||
25 | 28 | ||
29 | + | func keyLotteryPrizeValue (lotteryName,prizeID) = mk(["lottery", lotteryName, "prize", toString(prizeID), "value"]) | |
30 | + | ||
31 | + | ||
26 | 32 | let _activeLotteryName = mk(["param", "activeLotteryName"]) | |
27 | 33 | ||
28 | - | ||
29 | - | ||
30 | - | ||
31 | - | then "" | |
32 | - | else { | |
33 | - | let | |
34 | - | | |
35 | - | | |
36 | - | | |
37 | - | | |
38 | - | ||
34 | + | func activeLotteryName () = { | |
35 | + | let lotteryName = getStringOrElse(_activeLotteryName, "") | |
36 | + | if ((lotteryName == "")) | |
37 | + | then "" | |
38 | + | else { | |
39 | + | let lotteryFinalHeight = getIntegerValue(keyLotteryFinalHeight(lotteryName)) | |
40 | + | if (((height - 1) >= lotteryFinalHeight)) | |
41 | + | then "" | |
42 | + | else lotteryName | |
43 | + | } | |
44 | + | } | |
39 | 45 | ||
40 | 46 | ||
41 | 47 | @Callable(i) | |
42 | 48 | func stake () = { | |
43 | 49 | let lotteryName = activeLotteryName() | |
44 | 50 | if ((lotteryName == "")) | |
45 | 51 | then throw("Lottery not active") | |
46 | 52 | else if ((size(i.payments) == 0)) | |
47 | 53 | then throw("No payment added") | |
48 | 54 | else if ((size(i.payments) != 1)) | |
49 | 55 | then throw("Too many payments added") | |
50 | 56 | else if ((i.payments[0].assetId != lotteryAssetID)) | |
51 | 57 | then throw("Wrong payment assetId") | |
52 | 58 | else { | |
53 | 59 | let amount = i.payments[0].amount | |
54 | 60 | let ticketAmount = (amount / ticketSize) | |
55 | 61 | if ((ticketAmount == 0)) | |
56 | 62 | then throw("Not enough to buy at least one ticket") | |
57 | 63 | else { | |
58 | 64 | let callerAddress = toString(i.caller) | |
59 | 65 | let _lotteryTotalStaked = keyLotteryTotalStaked(lotteryName) | |
60 | 66 | let lotteryTotalStaked = getIntegerValue(_lotteryTotalStaked) | |
61 | 67 | let _owner = mk(["owner", lotteryName, toString(lotteryTotalStaked), toString(((lotteryTotalStaked + ticketAmount) - 1))]) | |
62 | 68 | let _adrTotalStaked = keyAdrTotalStaked(callerAddress) | |
63 | 69 | let adrTotalStaked = getIntegerOrElse(_adrTotalStaked, 0) | |
64 | 70 | let _adrLotteryTotalStaked = keyAdrLotteryTotalStaked(lotteryName, callerAddress) | |
65 | 71 | let adrLotteryTotalStaked = getIntegerOrElse(_adrLotteryTotalStaked, 0) | |
66 | 72 | let change = (amount - (ticketAmount * ticketSize)) | |
67 | 73 | [ScriptTransfer(i.caller, change, lotteryAssetID), IntegerEntry(_lotteryTotalStaked, (lotteryTotalStaked + ticketAmount)), StringEntry(_owner, callerAddress), IntegerEntry(_adrTotalStaked, (adrTotalStaked + ticketAmount)), IntegerEntry(_adrLotteryTotalStaked, (adrLotteryTotalStaked + ticketAmount))] | |
68 | 74 | } | |
69 | 75 | } | |
70 | 76 | } | |
71 | 77 | ||
72 | 78 | ||
73 | 79 | ||
74 | 80 | @Callable(i) | |
75 | 81 | func claim () = { | |
76 | 82 | let callerAddress = toString(i.caller) | |
77 | 83 | let lotteryName = activeLotteryName() | |
78 | 84 | let stakedInActiveLottery = if ((lotteryName == "")) | |
79 | 85 | then 0 | |
80 | 86 | else getIntegerOrElse(keyAdrLotteryTotalStaked(lotteryName, callerAddress), 0) | |
81 | 87 | let _adrTotalStaked = keyAdrTotalStaked(callerAddress) | |
82 | 88 | let adrTotalStaked = getIntegerOrElse(_adrTotalStaked, 0) | |
83 | 89 | let available = (adrTotalStaked - stakedInActiveLottery) | |
84 | 90 | if ((0 >= available)) | |
85 | 91 | then throw("No assets available for claim") | |
86 | 92 | else [ScriptTransfer(i.caller, available, lotteryAssetID), IntegerEntry(_adrTotalStaked, (adrTotalStaked - available))] | |
87 | 93 | } | |
88 | 94 | ||
89 | 95 | ||
90 | 96 | ||
91 | 97 | @Callable(i) | |
92 | 98 | func initLottery (lotteryName,lotteryFinalHeight) = if ((i.caller != this)) | |
93 | 99 | then throw("admin only") | |
94 | - | else [ | |
100 | + | else [StringEntry(_activeLotteryName, lotteryName), IntegerEntry(keyLotteryFinalHeight(lotteryName), lotteryFinalHeight), IntegerEntry(keyLotteryTotalStaked(lotteryName), 0)] | |
95 | 101 | ||
96 | 102 | ||
97 | 103 | ||
98 | 104 | @Callable(i) | |
99 | - | func call () = { | |
100 | - | let asset = Issue("Asset", "", 1, 0, true, unit, 0) | |
101 | - | let assetId = calculateAssetId(asset) | |
102 | - | [BinaryEntry("bin", base58''), BooleanEntry("bool", true), IntegerEntry("int", 1), StringEntry("str", ""), DeleteEntry("str"), asset, Reissue(assetId, 1, false), Burn(assetId, 1), ScriptTransfer(i.caller, 1, assetId)] | |
103 | - | } | |
105 | + | func declarePrize (lotteryName,prizeId,prizeValue) = if ((i.caller != this)) | |
106 | + | then throw("admin only") | |
107 | + | else [StringEntry(keyLotteryPrizeValue(lotteryName, prizeId), prizeValue)] | |
104 | 108 | ||
105 | 109 | ||
106 | 110 | @Verifier(tx) | |
107 | 111 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
108 | 112 |
github/deemru/w8io/026f985 38.12 ms ◑