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:BgIZCAISABIAEgQKAggBEgUKAwgBCBIECgIIAQ0ADmxvdHRlcnlBc3NldElECQDZBAECLDNMejIzbVNVdlQxRXN3Y0JuMnNVUllKRzJhdDhyRzVhRnVVclRBd2FQTTZRAAp0aWNrZXRTaXplAAEBEGdldEludGVnZXJPckVsc2UCA2tleQN2YWwJAQt2YWx1ZU9yRWxzZQIJAJ8IAQUDa2V5BQN2YWwBD2dldFN0cmluZ09yRWxzZQIDa2V5A3ZhbAkBC3ZhbHVlT3JFbHNlAgkAoggBBQNrZXkFA3ZhbAECbWsBAXgJALkJAgUBeAIBXwERa2V5QWRyVG90YWxTdGFrZWQBA2FkcgkBAm1rAQkAzAgCAgNhZHIJAMwIAgUDYWRyCQDMCAICC3RvdGFsU3Rha2VkBQNuaWwBFWtleUxvdHRlcnlUb3RhbFN0YWtlZAELbG90dGVyeU5hbWUJAQJtawEJAMwIAgIHbG90dGVyeQkAzAgCBQtsb3R0ZXJ5TmFtZQkAzAgCAgt0b3RhbFN0YWtlZAUDbmlsARhrZXlBZHJMb3R0ZXJ5VG90YWxTdG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aAjDLmyViRqxCQw Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let lotteryAssetID = fromBase58String("3Lz23mSUvT1EswcBn2sURYJG2at8rG5aFuUrTAwaPM6Q")
55
66 let ticketSize = 1
77
88 func getIntegerOrElse (key,val) = valueOrElse(getInteger(key), val)
99
1010
1111 func getStringOrElse (key,val) = valueOrElse(getString(key), val)
1212
1313
1414 func mk (x) = makeString(x, "_")
1515
1616
1717 func keyAdrTotalStaked (adr) = mk(["adr", adr, "totalStaked"])
1818
1919
2020 func keyLotteryTotalStaked (lotteryName) = mk(["lottery", lotteryName, "totalStaked"])
2121
2222
2323 func keyAdrLotteryTotalStaked (lotteryName,adr) = mk(["lottery", lotteryName, adr, "totalStaked"])
2424
2525
2626 func keyLotteryFinalHeight (lotteryName) = mk(["lottery", lotteryName, "finalHeight"])
2727
2828
2929 func keyLotteryPrizeValue (lotteryName,prizeID) = mk(["lottery", lotteryName, "prize", toString(prizeID), "value"])
3030
3131
3232 func keyLotteryPrizeChoice (lotteryName,prizeID) = mk(["lottery", lotteryName, "prize", toString(prizeID), "choice"])
3333
3434
3535 let _activeLotteryName = mk(["param", "activeLotteryName"])
3636
3737 func activeLotteryName () = {
3838 let lotteryName = getStringOrElse(_activeLotteryName, "")
3939 if ((lotteryName == ""))
4040 then ""
4141 else {
4242 let lotteryFinalHeight = getIntegerValue(keyLotteryFinalHeight(lotteryName))
4343 if (((height - 1) >= lotteryFinalHeight))
4444 then ""
4545 else lotteryName
4646 }
4747 }
4848
4949
5050 @Callable(i)
5151 func stake () = {
5252 let lotteryName = activeLotteryName()
5353 if ((lotteryName == ""))
5454 then throw("Lottery not active")
5555 else if ((size(i.payments) == 0))
5656 then throw("No payment added")
5757 else if ((size(i.payments) != 1))
5858 then throw("Too many payments added")
5959 else if ((i.payments[0].assetId != lotteryAssetID))
6060 then throw("Wrong payment assetId")
6161 else {
6262 let amount = i.payments[0].amount
6363 let ticketAmount = (amount / ticketSize)
6464 if ((ticketAmount == 0))
6565 then throw("Not enough to buy at least one ticket")
6666 else {
6767 let callerAddress = toString(i.caller)
6868 let _lotteryTotalStaked = keyLotteryTotalStaked(lotteryName)
6969 let lotteryTotalStaked = getIntegerValue(_lotteryTotalStaked)
7070 let _owner = mk(["owner", lotteryName, toString(lotteryTotalStaked), toString(((lotteryTotalStaked + ticketAmount) - 1))])
7171 let _adrTotalStaked = keyAdrTotalStaked(callerAddress)
7272 let adrTotalStaked = getIntegerOrElse(_adrTotalStaked, 0)
7373 let _adrLotteryTotalStaked = keyAdrLotteryTotalStaked(lotteryName, callerAddress)
7474 let adrLotteryTotalStaked = getIntegerOrElse(_adrLotteryTotalStaked, 0)
7575 let change = (amount - (ticketAmount * ticketSize))
7676 [ScriptTransfer(i.caller, change, lotteryAssetID), IntegerEntry(_lotteryTotalStaked, (lotteryTotalStaked + ticketAmount)), StringEntry(_owner, callerAddress), IntegerEntry(_adrTotalStaked, (adrTotalStaked + ticketAmount)), IntegerEntry(_adrLotteryTotalStaked, (adrLotteryTotalStaked + ticketAmount))]
7777 }
7878 }
7979 }
8080
8181
8282
8383 @Callable(i)
8484 func claim () = if ((size(i.payments) > 0))
8585 then throw("No payments needed")
8686 else {
8787 let callerAddress = toString(i.caller)
8888 let lotteryName = activeLotteryName()
8989 let stakedInActiveLottery = if ((lotteryName == ""))
9090 then 0
9191 else getIntegerOrElse(keyAdrLotteryTotalStaked(lotteryName, callerAddress), 0)
9292 let _adrTotalStaked = keyAdrTotalStaked(callerAddress)
9393 let adrTotalStaked = getIntegerOrElse(_adrTotalStaked, 0)
9494 let available = (adrTotalStaked - stakedInActiveLottery)
9595 if ((0 >= available))
9696 then throw("No assets available for claim")
9797 else [ScriptTransfer(i.caller, available, lotteryAssetID), IntegerEntry(_adrTotalStaked, (adrTotalStaked - available))]
9898 }
9999
100100
101101
102102 @Callable(i)
103103 func startLottery (lotteryName,lotteryFinalHeight) = if ((i.caller != this))
104104 then throw("Admin only")
105105 else [StringEntry(_activeLotteryName, lotteryName), IntegerEntry(keyLotteryFinalHeight(lotteryName), lotteryFinalHeight), IntegerEntry(keyLotteryTotalStaked(lotteryName), 0)]
106106
107107
108108
109109 @Callable(i)
110110 func declarePrize (lotteryName,prizeId,prizeValue) = if ((i.caller != this))
111111 then throw("Admin only")
112112 else [StringEntry(keyLotteryPrizeValue(lotteryName, prizeId), prizeValue)]
113113
114114
115115
116116 @Callable(i)
117117 func finalaizePrizeChoice (lotteryName,prizeId) = if ((i.caller != this))
118118 then throw("Admin only")
119119 else {
120120 let lotteryFinalHeight = getIntegerValue(keyLotteryFinalHeight(lotteryName))
121121 if ((lotteryFinalHeight > height))
122122 then throw("Lottery is not over yet")
123123 else {
124124 let lotteryTotalStaked = getIntegerValue(keyLotteryTotalStaked(lotteryName))
125125 if ((lotteryTotalStaked == 0))
126126 then throw("No one entered the lottery")
127127 else {
128128 let finalBlock = value(blockInfoByHeight(lotteryFinalHeight))
129129 let randomHash = sha256((toBytes(prizeId) + value(finalBlock.vrf)))
130130 let choice = toInt((toBigInt(randomHash) % toBigInt(lotteryTotalStaked)))
131131 [StringEntry("lastHash", toString(toBigInt(randomHash))), IntegerEntry(keyLotteryPrizeChoice(lotteryName, prizeId), choice)]
132132 }
133133 }
134134 }
135135
136136
137137 @Verifier(tx)
138138 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
139139

github/deemru/w8io/169f3d6 
60.68 ms