tx · FyUiMgrDR899JgkyHJNsKXGvjgCwNKrzrHsw2cQMLdqS 3NAyEmf6LcDGEDPTPdRS5Tmw7gHM5eYT282: -0.01000000 Waves 2022.08.15 22:16 [2185987] smart account 3NAyEmf6LcDGEDPTPdRS5Tmw7gHM5eYT282 > SELF 0.00000000 Waves
{ "type": 13, "id": "FyUiMgrDR899JgkyHJNsKXGvjgCwNKrzrHsw2cQMLdqS", "fee": 1000000, "feeAssetId": null, "timestamp": 1660591058362, "version": 2, "chainId": 84, "sender": "3NAyEmf6LcDGEDPTPdRS5Tmw7gHM5eYT282", "senderPublicKey": "41UVTJkibkjYf8R9TYLpLhyBumYYDk22tQNQXEZtAqMH", "proofs": [ "3VZoRv3M62wMRvo9RWHXmzyHWfo22PyBa2cZs2Gfz9EAqnxpRqNLn5HLQdpWQn7ykRDPZQQx8nfZbXtruWjeCny1" ], "script": "base64:BgIiCAISAwoBCBIAEgUKAwgIARIDCgEIEgASBQoDCAgIEgASABEABXdhdmVzAIDC1y8ADnRpY2tldFByaWNlSW50AMCEPQALdGlja2V0UHJpY2UFDnRpY2tldFByaWNlSW50AAZpbnZGZWUAoMIeABJ3aXRoZHJhd0ZlZVBlcmNlbnQABQAWZmVlQ29sbGVjdG9yQWRkcmVzc0tleQITZmVlQ29sbGVjdG9yQWRkcmVzcwAOZGVwb3NpdEFzc2V0SWQCLDV1ZTFmaXVWNmo2VUJyNlhmMjhRbXM2eTVGcXpLdHF2YXh4aHd1N2hUUTU4AQ10cnlHZXRJbnRlZ2VyAQNrZXkEByRtYXRjaDAJAJoIAgUEdGhpcwUDa2V5AwkAAQIFByRtYXRjaDACA0ludAQBYgUHJG1hdGNoMAUBYgAAARJnZXRUaWNrZXRzQ291bnRLZXkBDWFkZHJlc3NTdHJpbmcJAKwCAgUNYWRkcmVzc1N0cmluZwINX3RpY2tldHNDb3VudAENZ2FtZVdpbm5lcktleQEGZ2FtZUlkCQCsAgIFBmdhbWVJZAIHX3dpbm5lcgEYYWRkcmVz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BWJ5dGVzBBNjdXJyZW50VGlja2V0c0NvdW50CQENdHJ5R2V0SW50ZWdlcgEJARJnZXRUaWNrZXRzQ291bnRLZXkBBQ1jYWxsZXJBZGRyU3RyCQCUCgIJAMwIAgkBDEludGVnZXJFbnRyeQIJARJnZXRUaWNrZXRzQ291bnRLZXkBBQ1jYWxsZXJBZGRyU3RyCQBkAgUTY3VycmVudFRpY2tldHNDb3VudAABBQNuaWwAAQECdHgBBnZlcmlmeQAJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAAIBQJ0eA9zZW5kZXJQdWJsaWNLZXl3M7wF", "height": 2185987, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: none Next: none Full:
Old | New | Differences | |
---|---|---|---|
1 | - | # no script | |
1 | + | {-# STDLIB_VERSION 6 #-} | |
2 | + | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | + | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let waves = 100000000 | |
5 | + | ||
6 | + | let ticketPriceInt = 1000000 | |
7 | + | ||
8 | + | let ticketPrice = ticketPriceInt | |
9 | + | ||
10 | + | let invFee = 500000 | |
11 | + | ||
12 | + | let withdrawFeePercent = 5 | |
13 | + | ||
14 | + | let feeCollectorAddressKey = "feeCollectorAddress" | |
15 | + | ||
16 | + | let depositAssetId = "5ue1fiuV6j6UBr6Xf28Qms6y5FqzKtqvaxxhwu7hTQ58" | |
17 | + | ||
18 | + | func tryGetInteger (key) = match getInteger(this, key) { | |
19 | + | case b: Int => | |
20 | + | b | |
21 | + | case _ => | |
22 | + | 0 | |
23 | + | } | |
24 | + | ||
25 | + | ||
26 | + | func getTicketsCountKey (addressString) = (addressString + "_ticketsCount") | |
27 | + | ||
28 | + | ||
29 | + | func gameWinnerKey (gameId) = (gameId + "_winner") | |
30 | + | ||
31 | + | ||
32 | + | func addressAvailableFundsKey (address) = (address + "_availableFunds") | |
33 | + | ||
34 | + | ||
35 | + | func addressTotalLockedFundsKey (address) = (address + "_totalLockedFunds") | |
36 | + | ||
37 | + | ||
38 | + | func addressLockedFundsTotalHistoryKey (address) = (address + "_lockedFundsTotalHistory") | |
39 | + | ||
40 | + | ||
41 | + | func addressLockedFundsForGameKey (address,gameId) = ((address + "_lockedFunds_") + gameId) | |
42 | + | ||
43 | + | ||
44 | + | func addressAvailableRewardsKey (address) = (address + "_availableRewards") | |
45 | + | ||
46 | + | ||
47 | + | func getTicketsCount (addressString) = tryGetInteger(getTicketsCountKey(addressString)) | |
48 | + | ||
49 | + | ||
50 | + | func consumeTicket (playerAddr) = { | |
51 | + | let currentTicketCount = getTicketsCount(playerAddr) | |
52 | + | let newCurrentTicketCount = (currentTicketCount - 1) | |
53 | + | if ((0 > newCurrentTicketCount)) | |
54 | + | then 0 | |
55 | + | else newCurrentTicketCount | |
56 | + | } | |
57 | + | ||
58 | + | ||
59 | + | @Callable(i) | |
60 | + | func setFeeCollectorAddress (collectorAddr) = if ((i.caller != this)) | |
61 | + | then throw("Admin Only") | |
62 | + | else [StringEntry(feeCollectorAddressKey, collectorAddr)] | |
63 | + | ||
64 | + | ||
65 | + | ||
66 | + | @Callable(i) | |
67 | + | func depositFunds () = { | |
68 | + | let pmt = if ((size(i.payments) == 1)) | |
69 | + | then i.payments[0] | |
70 | + | else throw("Please attach exactly one payment") | |
71 | + | if ((pmt.assetId != fromBase58String(depositAssetId))) | |
72 | + | then throw("You can only deposit USDN") | |
73 | + | else { | |
74 | + | let callerAddrStr = toBase58String(i.caller.bytes) | |
75 | + | let currentAvailableFunds = tryGetInteger(addressAvailableFundsKey(callerAddrStr)) | |
76 | + | $Tuple2([IntegerEntry(addressAvailableFundsKey(callerAddrStr), (currentAvailableFunds + pmt.amount))], 1) | |
77 | + | } | |
78 | + | } | |
79 | + | ||
80 | + | ||
81 | + | ||
82 | + | @Callable(i) | |
83 | + | func playerExitGame (gameId,playerAddr,exitStackAmount) = if ((i.caller != this)) | |
84 | + | then throw("Admin Only") | |
85 | + | else { | |
86 | + | let currentTotalLockedFunds = tryGetInteger(addressTotalLockedFundsKey(playerAddr)) | |
87 | + | let currentGameLockedAmountForPlayer = tryGetInteger(addressLockedFundsForGameKey(playerAddr, gameId)) | |
88 | + | $Tuple2([IntegerEntry(addressTotalLockedFundsKey(playerAddr), (currentTotalLockedFunds - currentGameLockedAmountForPlayer)), IntegerEntry(addressLockedFundsForGameKey(playerAddr, gameId), 0), ScriptTransfer(i.caller, exitStackAmount, fromBase58String(depositAssetId))], 1) | |
89 | + | } | |
90 | + | ||
91 | + | ||
92 | + | ||
93 | + | @Callable(i) | |
94 | + | func lockFundsForGame (gameId) = { | |
95 | + | let pmt = if ((size(i.payments) == 1)) | |
96 | + | then i.payments[0] | |
97 | + | else throw("Please attach exactly one payment") | |
98 | + | if ((pmt.assetId != fromBase58String(depositAssetId))) | |
99 | + | then throw("You can only deposit USDN") | |
100 | + | else { | |
101 | + | let callerAddrStr = toBase58String(i.caller.bytes) | |
102 | + | let currentTotalLockedFunds = tryGetInteger(addressTotalLockedFundsKey(callerAddrStr)) | |
103 | + | let currentLockedFundsTotalHistory = tryGetInteger(addressLockedFundsTotalHistoryKey(callerAddrStr)) | |
104 | + | $Tuple2([IntegerEntry(addressTotalLockedFundsKey(callerAddrStr), (currentTotalLockedFunds + pmt.amount)), IntegerEntry(addressLockedFundsTotalHistoryKey(callerAddrStr), (currentLockedFundsTotalHistory + pmt.amount)), IntegerEntry(addressLockedFundsForGameKey(callerAddrStr, gameId), pmt.amount)], 1) | |
105 | + | } | |
106 | + | } | |
107 | + | ||
108 | + | ||
109 | + | ||
110 | + | @Callable(i) | |
111 | + | func withdrawFunds () = { | |
112 | + | let callerAddrStr = toBase58String(i.caller.bytes) | |
113 | + | let feeCollectorAddr = addressFromStringValue(getStringValue(feeCollectorAddressKey)) | |
114 | + | let currentAvailableFunds = tryGetInteger(addressAvailableFundsKey(callerAddrStr)) | |
115 | + | let withdrawFee = fraction(currentAvailableFunds, withdrawFeePercent, 100) | |
116 | + | let actualAvailableFunds = (currentAvailableFunds - withdrawFee) | |
117 | + | if ((0 >= actualAvailableFunds)) | |
118 | + | then throw("No available funds to withdraw") | |
119 | + | else [IntegerEntry(addressAvailableFundsKey(callerAddrStr), 0), ScriptTransfer(i.caller, actualAvailableFunds, fromBase58String(depositAssetId)), ScriptTransfer(feeCollectorAddr, withdrawFee, fromBase58String(depositAssetId))] | |
120 | + | } | |
121 | + | ||
122 | + | ||
123 | + | ||
124 | + | @Callable(i) | |
125 | + | func setWinnerHeadsUp (gameId,winnerAddrStr,otherPlayerAddr) = if ((i.caller != this)) | |
126 | + | then throw("Admin Only") | |
127 | + | else { | |
128 | + | let availableRewardsKey = addressAvailableRewardsKey(winnerAddrStr) | |
129 | + | let currentAvailableRewards = tryGetInteger(availableRewardsKey) | |
130 | + | let newTicketCountWinner = consumeTicket(winnerAddrStr) | |
131 | + | let newTicketCountOtherPlayer = consumeTicket(otherPlayerAddr) | |
132 | + | [StringEntry(gameWinnerKey(gameId), winnerAddrStr), IntegerEntry(availableRewardsKey, (currentAvailableRewards + (ticketPrice * 2))), IntegerEntry(getTicketsCountKey(winnerAddrStr), newTicketCountWinner), IntegerEntry(getTicketsCountKey(otherPlayerAddr), newTicketCountOtherPlayer)] | |
133 | + | } | |
134 | + | ||
135 | + | ||
136 | + | ||
137 | + | @Callable(i) | |
138 | + | func withdrawRewards () = { | |
139 | + | let callerAddrStr = toBase58String(i.caller.bytes) | |
140 | + | let feeCollectorAddr = addressFromStringValue(getStringValue(feeCollectorAddressKey)) | |
141 | + | let currentAvailableRewards = tryGetInteger(addressAvailableRewardsKey(callerAddrStr)) | |
142 | + | let withdrawFee = fraction(currentAvailableRewards, withdrawFeePercent, 100) | |
143 | + | let actualAvailableRewards = ((currentAvailableRewards - invFee) - withdrawFee) | |
144 | + | if ((0 >= currentAvailableRewards)) | |
145 | + | then throw("No available rewards to withdraw") | |
146 | + | else [IntegerEntry(addressAvailableRewardsKey(callerAddrStr), 0), ScriptTransfer(i.caller, actualAvailableRewards, unit), ScriptTransfer(feeCollectorAddr, withdrawFee, unit)] | |
147 | + | } | |
148 | + | ||
149 | + | ||
150 | + | ||
151 | + | @Callable(i) | |
152 | + | func buyTickets () = { | |
153 | + | let pmt = if ((size(i.payments) == 1)) | |
154 | + | then i.payments[0] | |
155 | + | else throw("Please attach exactly one payment") | |
156 | + | if (isDefined(pmt.assetId)) | |
157 | + | then throw("Tickets can only ibe purchased in Waves") | |
158 | + | else if ((pmt.amount != ticketPrice)) | |
159 | + | then throw((("The payment must be of exactly " + toString(ticketPriceInt)) + " waves")) | |
160 | + | else { | |
161 | + | let callerAddrStr = toBase58String(i.caller.bytes) | |
162 | + | let currentTicketsCount = tryGetInteger(getTicketsCountKey(callerAddrStr)) | |
163 | + | $Tuple2([IntegerEntry(getTicketsCountKey(callerAddrStr), (currentTicketsCount + 1))], 1) | |
164 | + | } | |
165 | + | } | |
166 | + | ||
167 | + | ||
168 | + | @Verifier(tx) | |
169 | + | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
170 | + |
github/deemru/w8io/026f985 18.63 ms ◑