tx · 5rxT1MWEwcwwUD3qydr6f7zcpkDfgaAjDLmyViRqxCQw 3N4Kzbxu521DHPxcgrmZ4XUqN2kF6TqLTzs: -0.01000000 Waves 2023.08.29 12:04 [2731783] smart account 3N4Kzbxu521DHPxcgrmZ4XUqN2kF6TqLTzs > SELF 0.00000000 Waves
{ "type": 13, "id": "5rxT1MWEwcwwUD3qydr6f7zcpkDfgaAjDLmyViRqxCQw", "fee": 1000000, "feeAssetId": null, "timestamp": 1693299915359, "version": 2, "chainId": 84, "sender": "3N4Kzbxu521DHPxcgrmZ4XUqN2kF6TqLTzs", "senderPublicKey": "8yQuxvQ2qLzXJrgbKZHbsfnNNjuU5wfHheyVujdALGsF", "proofs": [ "UWhjLD2mfjLE2tAT1v9FgoZTa82BJTr9RMAcCHHuW819q9WcE1aF2rSvELija1XjYN2gF6ieujD3NzVmUzT1WNo" ], "script": "base64:BgIZCAISABIAEgQKAggBEgUKAwgBCBIECgIIAQ0ADmxvdHRlcnlBc3NldElECQDZBAECLDNMejIzbVNVdlQxRXN3Y0JuMnNVUllKRzJhdDhyRzVhRnVVclRBd2FQTTZRAAp0aWNrZXRTaXplAAEBEGdldEludGVnZXJPckVsc2UCA2tleQN2YWwJAQt2YWx1ZU9yRWxzZQIJAJ8IAQUDa2V5BQN2YWwBD2dldFN0cmluZ09yRWxzZQIDa2V5A3ZhbAkBC3ZhbHVlT3JFbHNlAgkAoggBBQNrZXkFA3ZhbAECbWsBAXgJALkJAgUBeAIBXwERa2V5QWRyVG90YWxTdGFrZWQBA2FkcgkBAm1rAQkAzAgCAgNhZHIJAMwIAgUDYWRyCQDMCAICC3RvdGFsU3Rha2VkBQNuaWwBFWtleUxvdHRlcnlUb3RhbFN0YWtlZAELbG90dGVyeU5hbWUJAQJtawEJAMwIAgIHbG90dGVyeQkAzAgCBQtsb3R0ZXJ5TmFtZQkAzAgCAgt0b3RhbFN0YWtlZAUDbmlsARhrZXlBZHJMb3R0ZXJ5VG90YWxTdGFrZWQCC2xv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A25pbAECdHgBBnZlcmlmeQAJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAAIBQJ0eA9zZW5kZXJQdWJsaWNLZXkBePdI", "height": 2731783, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: B3LiJpVd2zpdeNcMuYYtDC1Gw7tL6YgReqTqdapNmKs3 Next: 7nv2AegxVknj7GqRr3cJvx42qp2FUKfwsmoedpSCGPFE Diff:
Old | New | Differences | |
---|---|---|---|
20 | 20 | func keyLotteryTotalStaked (lotteryName) = mk(["lottery", lotteryName, "totalStaked"]) | |
21 | 21 | ||
22 | 22 | ||
23 | - | func keyAdrLotteryTotalStaked (lotteryName,adr) = mk(["lottery", lotteryName, adr, "totalStaked"]) | |
23 | + | func keyAdrLotteryTotalStaked (lotteryName,adr) = mk(["lottery", lotteryName, "adr", adr, "totalStaked"]) | |
24 | 24 | ||
25 | 25 | ||
26 | 26 | func keyLotteryFinalHeight (lotteryName) = mk(["lottery", lotteryName, "finalHeight"]) | |
125 | 125 | if ((lotteryTotalStaked == 0)) | |
126 | 126 | then throw("No one entered the lottery") | |
127 | 127 | else { | |
128 | - | let finalBlock = value(blockInfoByHeight(lotteryFinalHeight)) | |
129 | - | let randomHash = sha256((toBytes(prizeId) + value(finalBlock.vrf))) | |
130 | - | let choice = toInt((toBigInt(randomHash) % toBigInt(lotteryTotalStaked))) | |
128 | + | let lotteryPrizeValue = getStringOrElse(keyLotteryPrizeValue(lotteryName, prizeId), "") | |
129 | + | if ((lotteryPrizeValue == "")) | |
130 | + | then throw("prize does not exist") | |
131 | + | else { | |
132 | + | let finalBlock = value(blockInfoByHeight(lotteryFinalHeight)) | |
133 | + | let randomHash = sha256((toBytes(prizeId) + value(finalBlock.vrf))) | |
134 | + | let choice = toInt((toBigInt(randomHash) % toBigInt(lotteryTotalStaked))) | |
131 | 135 | [StringEntry("lastHash", toString(toBigInt(randomHash))), IntegerEntry(keyLotteryPrizeChoice(lotteryName, prizeId), choice)] | |
136 | + | } | |
132 | 137 | } | |
133 | 138 | } | |
134 | 139 | } |
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 | 9 | ||
10 | 10 | ||
11 | 11 | func getStringOrElse (key,val) = valueOrElse(getString(key), val) | |
12 | 12 | ||
13 | 13 | ||
14 | 14 | func mk (x) = makeString(x, "_") | |
15 | 15 | ||
16 | 16 | ||
17 | 17 | func keyAdrTotalStaked (adr) = mk(["adr", adr, "totalStaked"]) | |
18 | 18 | ||
19 | 19 | ||
20 | 20 | func keyLotteryTotalStaked (lotteryName) = mk(["lottery", lotteryName, "totalStaked"]) | |
21 | 21 | ||
22 | 22 | ||
23 | - | func keyAdrLotteryTotalStaked (lotteryName,adr) = mk(["lottery", lotteryName, adr, "totalStaked"]) | |
23 | + | func keyAdrLotteryTotalStaked (lotteryName,adr) = mk(["lottery", lotteryName, "adr", adr, "totalStaked"]) | |
24 | 24 | ||
25 | 25 | ||
26 | 26 | func keyLotteryFinalHeight (lotteryName) = mk(["lottery", lotteryName, "finalHeight"]) | |
27 | 27 | ||
28 | 28 | ||
29 | 29 | func keyLotteryPrizeValue (lotteryName,prizeID) = mk(["lottery", lotteryName, "prize", toString(prizeID), "value"]) | |
30 | 30 | ||
31 | 31 | ||
32 | 32 | func keyLotteryPrizeChoice (lotteryName,prizeID) = mk(["lottery", lotteryName, "prize", toString(prizeID), "choice"]) | |
33 | 33 | ||
34 | 34 | ||
35 | 35 | let _activeLotteryName = mk(["param", "activeLotteryName"]) | |
36 | 36 | ||
37 | 37 | func activeLotteryName () = { | |
38 | 38 | let lotteryName = getStringOrElse(_activeLotteryName, "") | |
39 | 39 | if ((lotteryName == "")) | |
40 | 40 | then "" | |
41 | 41 | else { | |
42 | 42 | let lotteryFinalHeight = getIntegerValue(keyLotteryFinalHeight(lotteryName)) | |
43 | 43 | if (((height - 1) >= lotteryFinalHeight)) | |
44 | 44 | then "" | |
45 | 45 | else lotteryName | |
46 | 46 | } | |
47 | 47 | } | |
48 | 48 | ||
49 | 49 | ||
50 | 50 | @Callable(i) | |
51 | 51 | func stake () = { | |
52 | 52 | let lotteryName = activeLotteryName() | |
53 | 53 | if ((lotteryName == "")) | |
54 | 54 | then throw("Lottery not active") | |
55 | 55 | else if ((size(i.payments) == 0)) | |
56 | 56 | then throw("No payment added") | |
57 | 57 | else if ((size(i.payments) != 1)) | |
58 | 58 | then throw("Too many payments added") | |
59 | 59 | else if ((i.payments[0].assetId != lotteryAssetID)) | |
60 | 60 | then throw("Wrong payment assetId") | |
61 | 61 | else { | |
62 | 62 | let amount = i.payments[0].amount | |
63 | 63 | let ticketAmount = (amount / ticketSize) | |
64 | 64 | if ((ticketAmount == 0)) | |
65 | 65 | then throw("Not enough to buy at least one ticket") | |
66 | 66 | else { | |
67 | 67 | let callerAddress = toString(i.caller) | |
68 | 68 | let _lotteryTotalStaked = keyLotteryTotalStaked(lotteryName) | |
69 | 69 | let lotteryTotalStaked = getIntegerValue(_lotteryTotalStaked) | |
70 | 70 | let _owner = mk(["owner", lotteryName, toString(lotteryTotalStaked), toString(((lotteryTotalStaked + ticketAmount) - 1))]) | |
71 | 71 | let _adrTotalStaked = keyAdrTotalStaked(callerAddress) | |
72 | 72 | let adrTotalStaked = getIntegerOrElse(_adrTotalStaked, 0) | |
73 | 73 | let _adrLotteryTotalStaked = keyAdrLotteryTotalStaked(lotteryName, callerAddress) | |
74 | 74 | let adrLotteryTotalStaked = getIntegerOrElse(_adrLotteryTotalStaked, 0) | |
75 | 75 | let change = (amount - (ticketAmount * ticketSize)) | |
76 | 76 | [ScriptTransfer(i.caller, change, lotteryAssetID), IntegerEntry(_lotteryTotalStaked, (lotteryTotalStaked + ticketAmount)), StringEntry(_owner, callerAddress), IntegerEntry(_adrTotalStaked, (adrTotalStaked + ticketAmount)), IntegerEntry(_adrLotteryTotalStaked, (adrLotteryTotalStaked + ticketAmount))] | |
77 | 77 | } | |
78 | 78 | } | |
79 | 79 | } | |
80 | 80 | ||
81 | 81 | ||
82 | 82 | ||
83 | 83 | @Callable(i) | |
84 | 84 | func claim () = if ((size(i.payments) > 0)) | |
85 | 85 | then throw("No payments needed") | |
86 | 86 | else { | |
87 | 87 | let callerAddress = toString(i.caller) | |
88 | 88 | let lotteryName = activeLotteryName() | |
89 | 89 | let stakedInActiveLottery = if ((lotteryName == "")) | |
90 | 90 | then 0 | |
91 | 91 | else getIntegerOrElse(keyAdrLotteryTotalStaked(lotteryName, callerAddress), 0) | |
92 | 92 | let _adrTotalStaked = keyAdrTotalStaked(callerAddress) | |
93 | 93 | let adrTotalStaked = getIntegerOrElse(_adrTotalStaked, 0) | |
94 | 94 | let available = (adrTotalStaked - stakedInActiveLottery) | |
95 | 95 | if ((0 >= available)) | |
96 | 96 | then throw("No assets available for claim") | |
97 | 97 | else [ScriptTransfer(i.caller, available, lotteryAssetID), IntegerEntry(_adrTotalStaked, (adrTotalStaked - available))] | |
98 | 98 | } | |
99 | 99 | ||
100 | 100 | ||
101 | 101 | ||
102 | 102 | @Callable(i) | |
103 | 103 | func startLottery (lotteryName,lotteryFinalHeight) = if ((i.caller != this)) | |
104 | 104 | then throw("Admin only") | |
105 | 105 | else [StringEntry(_activeLotteryName, lotteryName), IntegerEntry(keyLotteryFinalHeight(lotteryName), lotteryFinalHeight), IntegerEntry(keyLotteryTotalStaked(lotteryName), 0)] | |
106 | 106 | ||
107 | 107 | ||
108 | 108 | ||
109 | 109 | @Callable(i) | |
110 | 110 | func declarePrize (lotteryName,prizeId,prizeValue) = if ((i.caller != this)) | |
111 | 111 | then throw("Admin only") | |
112 | 112 | else [StringEntry(keyLotteryPrizeValue(lotteryName, prizeId), prizeValue)] | |
113 | 113 | ||
114 | 114 | ||
115 | 115 | ||
116 | 116 | @Callable(i) | |
117 | 117 | func finalaizePrizeChoice (lotteryName,prizeId) = if ((i.caller != this)) | |
118 | 118 | then throw("Admin only") | |
119 | 119 | else { | |
120 | 120 | let lotteryFinalHeight = getIntegerValue(keyLotteryFinalHeight(lotteryName)) | |
121 | 121 | if ((lotteryFinalHeight > height)) | |
122 | 122 | then throw("Lottery is not over yet") | |
123 | 123 | else { | |
124 | 124 | let lotteryTotalStaked = getIntegerValue(keyLotteryTotalStaked(lotteryName)) | |
125 | 125 | if ((lotteryTotalStaked == 0)) | |
126 | 126 | then throw("No one entered the lottery") | |
127 | 127 | else { | |
128 | - | let finalBlock = value(blockInfoByHeight(lotteryFinalHeight)) | |
129 | - | let randomHash = sha256((toBytes(prizeId) + value(finalBlock.vrf))) | |
130 | - | let choice = toInt((toBigInt(randomHash) % toBigInt(lotteryTotalStaked))) | |
128 | + | let lotteryPrizeValue = getStringOrElse(keyLotteryPrizeValue(lotteryName, prizeId), "") | |
129 | + | if ((lotteryPrizeValue == "")) | |
130 | + | then throw("prize does not exist") | |
131 | + | else { | |
132 | + | let finalBlock = value(blockInfoByHeight(lotteryFinalHeight)) | |
133 | + | let randomHash = sha256((toBytes(prizeId) + value(finalBlock.vrf))) | |
134 | + | let choice = toInt((toBigInt(randomHash) % toBigInt(lotteryTotalStaked))) | |
131 | 135 | [StringEntry("lastHash", toString(toBigInt(randomHash))), IntegerEntry(keyLotteryPrizeChoice(lotteryName, prizeId), choice)] | |
136 | + | } | |
132 | 137 | } | |
133 | 138 | } | |
134 | 139 | } | |
135 | 140 | ||
136 | 141 | ||
137 | 142 | @Verifier(tx) | |
138 | 143 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
139 | 144 |
github/deemru/w8io/03bedc9 36.07 ms ◑![]()