tx · FDMsfhsuZi2tm5SDvhD3tPWmnSNHLM7W1gMnLzV2H53v 3N4Kzbxu521DHPxcgrmZ4XUqN2kF6TqLTzs: -0.01000000 Waves 2023.09.07 11:56 [2744752] smart account 3N4Kzbxu521DHPxcgrmZ4XUqN2kF6TqLTzs > SELF 0.00000000 Waves
{ "type": 13, "id": "FDMsfhsuZi2tm5SDvhD3tPWmnSNHLM7W1gMnLzV2H53v", "fee": 1000000, "feeAssetId": null, "timestamp": 1694077015983, "version": 2, "chainId": 84, "sender": "3N4Kzbxu521DHPxcgrmZ4XUqN2kF6TqLTzs", "senderPublicKey": "8yQuxvQ2qLzXJrgbKZHbsfnNNjuU5wfHheyVujdALGsF", "proofs": [ "2c7ad7wuLDRG7ioTexfRXGEdjwnvQzoBZxx9z295a88x45J8QjQiYLmom1YfiA1tSXKY53YSEagJ7KQeLu1nyeN8" ], "script": "base64:BgIfCAISABIECgIIARIGCgQIAQEIEgQKAggBEgUKAwgBCBIADmxvdHRlcnlBc3NldElEASAi1eE3pAm1kH7yDd2K/R2HDGQ6c8cmK+ceUzFNVsLOiQEQZ2V0SW50ZWdlck9yRWxzZQIDa2V5A3ZhbAkBC3ZhbHVlT3JFbHNlAgkAnwgBBQNrZXkFA3ZhbAEPZ2V0U3RyaW5nT3JFbHNlAgNrZXkDdmFsCQELdmFsdWVPckVsc2UCCQCiCAEFA2tleQUDdmFsAQ9zdHJpbmdLZXlFeGlzdHMBA2tleQMJAQlpc0RlZmluZWQBCQCiCAEFA2tleQYHAQJtawEBeAkAuQkCBQF4AgFfARVrZXlMb3R0ZXJ5VG90YWxTdGFrZWQBC2xvdHRlcnlOYW1lCQECbWsBCQDMCAICB2xvdHRlcnkJAMwIAgULbG90dGVyeU5hbWUJAMwIAgILdG90YWxTdGFrZWQFA25pbAETa2V5TG90dGVyeUFkclN0YWtlZAILbG90dGVyeU5hbWUDYWRyCQECbWsBCQDMCAICB2xvdHRlcnkJAMwIAgULbG90dGVyeU5hbWUJAMwIAgI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JpTykPrbJP81GPE9St88paLte Diff:
Old | New | Differences | |
---|---|---|---|
96 | 96 | @Callable(i) | |
97 | 97 | func initLottery (lotteryName,lotteryFinalHeight) = if ((i.caller != this)) | |
98 | 98 | then throw("Admin only") | |
99 | - | else [StringEntry(_activeLotteryName, lotteryName), IntegerEntry(keyLotteryFinalHeight(lotteryName), lotteryFinalHeight)] | |
99 | + | else [StringEntry(_activeLotteryName, lotteryName), IntegerEntry(keyLotteryStartHeight(lotteryName), height), IntegerEntry(keyLotteryFinalHeight(lotteryName), lotteryFinalHeight)] | |
100 | 100 | ||
101 | 101 | ||
102 | 102 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let lotteryAssetID = base58'3Lz23mSUvT1EswcBn2sURYJG2at8rG5aFuUrTAwaPM6Q' | |
5 | 5 | ||
6 | 6 | func getIntegerOrElse (key,val) = valueOrElse(getInteger(key), val) | |
7 | 7 | ||
8 | 8 | ||
9 | 9 | func getStringOrElse (key,val) = valueOrElse(getString(key), val) | |
10 | 10 | ||
11 | 11 | ||
12 | 12 | func stringKeyExists (key) = if (isDefined(getString(key))) | |
13 | 13 | then true | |
14 | 14 | else false | |
15 | 15 | ||
16 | 16 | ||
17 | 17 | func mk (x) = makeString(x, "_") | |
18 | 18 | ||
19 | 19 | ||
20 | 20 | func keyLotteryTotalStaked (lotteryName) = mk(["lottery", lotteryName, "totalStaked"]) | |
21 | 21 | ||
22 | 22 | ||
23 | 23 | func keyLotteryAdrStaked (lotteryName,adr) = mk(["lottery", lotteryName, "adr", adr, "staked"]) | |
24 | 24 | ||
25 | 25 | ||
26 | 26 | func keyLotteryAdrLocked (lotteryName,adr) = mk(["lottery", lotteryName, "adr", adr, "locked"]) | |
27 | 27 | ||
28 | 28 | ||
29 | 29 | func keyLotteryFinalHeight (lotteryName) = mk(["lottery", lotteryName, "finalHeight"]) | |
30 | 30 | ||
31 | 31 | ||
32 | 32 | func keyLotteryStartHeight (lotteryName) = mk(["lottery", lotteryName, "startHeight"]) | |
33 | 33 | ||
34 | 34 | ||
35 | 35 | func keyLotteryPrizeValue (lotteryName,prizeID) = mk(["lottery", lotteryName, "prize", toString(prizeID), "value"]) | |
36 | 36 | ||
37 | 37 | ||
38 | 38 | func keyLotteryPrizeThreshold (lotteryName,prizeID) = mk(["lottery", lotteryName, "prize", toString(prizeID), "threshold"]) | |
39 | 39 | ||
40 | 40 | ||
41 | 41 | func keyLotteryPrizeRandom (lotteryName,prizeID) = mk(["lottery", lotteryName, "prize", toString(prizeID), "random"]) | |
42 | 42 | ||
43 | 43 | ||
44 | 44 | func keyLotteryPrizeWinner (lotteryName,prizeID) = mk(["lottery", lotteryName, "prize", toString(prizeID), "winner"]) | |
45 | 45 | ||
46 | 46 | ||
47 | 47 | func keyLotteryTicketsOwner (lotteryName,from,to) = mk(["lottery", lotteryName, "from", toString(from), "to", toString(to), "owner"]) | |
48 | 48 | ||
49 | 49 | ||
50 | 50 | let _activeLotteryName = mk(["param", "activeLotteryName"]) | |
51 | 51 | ||
52 | 52 | let _globalTotalStaked = mk(["param", "globalTotalStaked"]) | |
53 | 53 | ||
54 | 54 | func activeLotteryName () = { | |
55 | 55 | let lotteryName = getStringOrElse(_activeLotteryName, "") | |
56 | 56 | if ((lotteryName == "")) | |
57 | 57 | then "" | |
58 | 58 | else { | |
59 | 59 | let lotteryFinalHeight = getIntegerValue(keyLotteryFinalHeight(lotteryName)) | |
60 | 60 | if ((height >= lotteryFinalHeight)) | |
61 | 61 | then "" | |
62 | 62 | else lotteryName | |
63 | 63 | } | |
64 | 64 | } | |
65 | 65 | ||
66 | 66 | ||
67 | 67 | @Callable(i) | |
68 | 68 | func stake () = { | |
69 | 69 | let lotteryName = activeLotteryName() | |
70 | 70 | if ((lotteryName == "")) | |
71 | 71 | then throw("Lottery not active") | |
72 | 72 | else if ((size(i.payments) == 0)) | |
73 | 73 | then throw("No payment added. You must attach a payment in Dodllnode tokens") | |
74 | 74 | else if ((size(i.payments) != 1)) | |
75 | 75 | then throw("Too many payments added. There must be only one attached payment") | |
76 | 76 | else if ((i.payments[0].assetId != lotteryAssetID)) | |
77 | 77 | then throw("Wrong payment assetID. You must attach a payment in Dodllnode tokens") | |
78 | 78 | else { | |
79 | 79 | let amount = i.payments[0].amount | |
80 | 80 | if ((1 > amount)) | |
81 | 81 | then throw("Not enough payment to purchase even a single ticket.") | |
82 | 82 | else { | |
83 | 83 | let callerAddress = toString(i.caller) | |
84 | 84 | let _lotteryTotalStaked = keyLotteryTotalStaked(lotteryName) | |
85 | 85 | let lotteryTotalStaked = getIntegerOrElse(_lotteryTotalStaked, 0) | |
86 | 86 | let _lotteryAdrStaked = keyLotteryAdrStaked(lotteryName, callerAddress) | |
87 | 87 | let lotteryAdrStaked = getIntegerOrElse(_lotteryAdrStaked, 0) | |
88 | 88 | let _owner = keyLotteryTicketsOwner(lotteryName, lotteryTotalStaked, ((lotteryTotalStaked + amount) - 1)) | |
89 | 89 | [IntegerEntry(_lotteryTotalStaked, (lotteryTotalStaked + amount)), IntegerEntry(_lotteryAdrStaked, (lotteryAdrStaked + amount)), StringEntry(_owner, callerAddress)] | |
90 | 90 | } | |
91 | 91 | } | |
92 | 92 | } | |
93 | 93 | ||
94 | 94 | ||
95 | 95 | ||
96 | 96 | @Callable(i) | |
97 | 97 | func initLottery (lotteryName,lotteryFinalHeight) = if ((i.caller != this)) | |
98 | 98 | then throw("Admin only") | |
99 | - | else [StringEntry(_activeLotteryName, lotteryName), IntegerEntry(keyLotteryFinalHeight(lotteryName), lotteryFinalHeight)] | |
99 | + | else [StringEntry(_activeLotteryName, lotteryName), IntegerEntry(keyLotteryStartHeight(lotteryName), height), IntegerEntry(keyLotteryFinalHeight(lotteryName), lotteryFinalHeight)] | |
100 | 100 | ||
101 | 101 | ||
102 | 102 | ||
103 | 103 | @Callable(i) | |
104 | 104 | func declarePrize (lotteryName,prizeId,prizeThreshold,prizeValue) = if ((i.caller != this)) | |
105 | 105 | then throw("Admin only") | |
106 | 106 | else [IntegerEntry(keyLotteryPrizeThreshold(lotteryName, prizeId), prizeThreshold), StringEntry(keyLotteryPrizeValue(lotteryName, prizeId), prizeValue)] | |
107 | 107 | ||
108 | 108 | ||
109 | 109 | ||
110 | 110 | @Callable(i) | |
111 | 111 | func finalaizePrizeRandom (lotteryName,prizeId) = if ((i.caller != this)) | |
112 | 112 | then throw("Admin only") | |
113 | 113 | else { | |
114 | 114 | let lotteryFinalHeight = getIntegerValue(keyLotteryFinalHeight(lotteryName)) | |
115 | 115 | if (((lotteryFinalHeight + 1) > height)) | |
116 | 116 | then throw("Lottery is not over yet") | |
117 | 117 | else { | |
118 | 118 | let lotteryPrizeValue = valueOrErrorMessage(getString(keyLotteryPrizeValue(lotteryName, prizeId)), "Prize does not exist") | |
119 | 119 | let _lotteryPrizeRandom = keyLotteryPrizeRandom(lotteryName, prizeId) | |
120 | 120 | if (stringKeyExists(_lotteryPrizeRandom)) | |
121 | 121 | then throw("The prize random has already been finalaized") | |
122 | 122 | else { | |
123 | 123 | let finalBlock0 = value(blockInfoByHeight(lotteryFinalHeight)) | |
124 | 124 | let finalBlock1 = value(blockInfoByHeight((lotteryFinalHeight + 1))) | |
125 | 125 | let prizeRandomRaw = toBigInt(sha256((((base58'2WWKxchwx7zBB' + toBytes(prizeId)) + value(finalBlock0.vrf)) + value(finalBlock1.vrf)))) | |
126 | 126 | let prizeRandom = if ((toBigInt(0) > prizeRandomRaw)) | |
127 | 127 | then -(prizeRandomRaw) | |
128 | 128 | else prizeRandomRaw | |
129 | 129 | [StringEntry(_lotteryPrizeRandom, toString(prizeRandom))] | |
130 | 130 | } | |
131 | 131 | } | |
132 | 132 | } | |
133 | 133 | ||
134 | 134 | ||
135 | 135 | ||
136 | 136 | @Callable(i) | |
137 | 137 | func finalaizePrizeWinner (lotteryName,prizeId,winnerAdr) = if ((i.caller != this)) | |
138 | 138 | then throw("Admin only") | |
139 | 139 | else { | |
140 | 140 | let _lotteryPrizeWinner = keyLotteryPrizeWinner(lotteryName, prizeId) | |
141 | 141 | if (stringKeyExists(_lotteryPrizeWinner)) | |
142 | 142 | then throw("The prize winner has already been finalaized") | |
143 | 143 | else { | |
144 | 144 | let _lotteryAdrStaked = keyLotteryAdrStaked(lotteryName, winnerAdr) | |
145 | 145 | let lotteryAdrStaked = getIntegerOrElse(_lotteryAdrStaked, 0) | |
146 | 146 | let _lotteryAdrLocked = keyLotteryAdrLocked(lotteryName, winnerAdr) | |
147 | 147 | let lotteryAdrLocked = getIntegerOrElse(_lotteryAdrLocked, 0) | |
148 | 148 | [IntegerEntry(_lotteryAdrStaked, 0), IntegerEntry(_lotteryAdrLocked, (lotteryAdrLocked + lotteryAdrStaked)), StringEntry(_lotteryPrizeWinner, winnerAdr)] | |
149 | 149 | } | |
150 | 150 | } | |
151 | 151 | ||
152 | 152 | ||
153 | 153 | @Verifier(tx) | |
154 | 154 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
155 | 155 |
github/deemru/w8io/026f985 33.41 ms ◑