tx · B3LiJpVd2zpdeNcMuYYtDC1Gw7tL6YgReqTqdapNmKs3 3N4Kzbxu521DHPxcgrmZ4XUqN2kF6TqLTzs: -0.01000000 Waves 2023.08.29 11:57 [2731775] smart account 3N4Kzbxu521DHPxcgrmZ4XUqN2kF6TqLTzs > SELF 0.00000000 Waves
{ "type": 13, "id": "B3LiJpVd2zpdeNcMuYYtDC1Gw7tL6YgReqTqdapNmKs3", "fee": 1000000, "feeAssetId": null, "timestamp": 1693299502391, "version": 2, "chainId": 84, "sender": "3N4Kzbxu521DHPxcgrmZ4XUqN2kF6TqLTzs", "senderPublicKey": "8yQuxvQ2qLzXJrgbKZHbsfnNNjuU5wfHheyVujdALGsF", "proofs": [ "Tf9Eo2tiNZtMrhPkYMTMbD3DQeN37Q31GSA2b8CTPMDPDVZtH5ziFC4mCm1SJZjY6WByEn4wa4DTwQ3VBsHoUrs" ], "script": "base64:BgIZCAISABIAEgQKAggBEgUKAwgBCBIECgIIAQ0ADmxvdHRlcnlBc3NldElECQDZBAECLDNMejIzbVNVdlQxRXN3Y0JuMnNVUllKRzJhdDhyRzVhRnVVclRBd2FQTTZRAAp0aWNrZXRTaXplAAEBEGdldEludGVnZXJPckVsc2UCA2tleQN2YWwJAQt2YWx1ZU9yRWxzZQIJAJ8IAQUDa2V5BQN2YWwBD2dldFN0cmluZ09yRWxzZQIDa2V5A3ZhbAkBC3ZhbHVlT3JFbHNlAgkAoggBBQNrZXkFA3ZhbAECbWsBAXgJALkJAgUBeAIBXwERa2V5QWRyVG90YWxTdGFrZWQBA2FkcgkBAm1rAQkAzAgCAgNhZHIJAMwIAgUDYWRyCQDMCAICC3RvdGFsU3Rha2VkBQNuaWwBFWtleUxvdHRlcnlUb3RhbFN0YWtlZAELbG90dGVyeU5hbWUJAQJtawEJAMwIAgIHbG90dGVyeQkAzAgCBQtsb3R0ZXJ5TmFtZQkAzAgCAgt0b3RhbFN0YWtlZAUDbmlsARhrZXlBZHJMb3R0ZXJ5VG90YWxTdGF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AjDLmyViRqxCQw Full:
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 | 23 | func keyAdrLotteryTotalStaked (lotteryName,adr) = mk(["lottery", lotteryName, 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 | 128 | let finalBlock = value(blockInfoByHeight(lotteryFinalHeight)) | |
129 | 129 | let randomHash = sha256((toBytes(prizeId) + value(finalBlock.vrf))) | |
130 | 130 | let choice = toInt((toBigInt(randomHash) % toBigInt(lotteryTotalStaked))) | |
131 | 131 | [StringEntry("lastHash", toString(toBigInt(randomHash))), IntegerEntry(keyLotteryPrizeChoice(lotteryName, prizeId), choice)] | |
132 | 132 | } | |
133 | 133 | } | |
134 | 134 | } | |
135 | 135 | ||
136 | 136 | ||
137 | 137 | @Verifier(tx) | |
138 | 138 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
139 | 139 |
github/deemru/w8io/169f3d6 60.68 ms ◑