tx · ATbsaoPbZ44fzmFhxAoDLAbG7WirHcWwZC78U5U1JpEs 3N2tFXuPD7RpqMyn9fpHGtskKwk3sfhaTpm: -0.01000000 Waves 2022.08.15 22:10 [2185980] smart account 3N2tFXuPD7RpqMyn9fpHGtskKwk3sfhaTpm > SELF 0.00000000 Waves
{ "type": 13, "id": "ATbsaoPbZ44fzmFhxAoDLAbG7WirHcWwZC78U5U1JpEs", "fee": 1000000, "feeAssetId": null, "timestamp": 1660590632709, "version": 2, "chainId": 84, "sender": "3N2tFXuPD7RpqMyn9fpHGtskKwk3sfhaTpm", "senderPublicKey": "HcUsmumFGn9byv1VVamPaWUjvEcdw3oezq6HzbMK1mt1", "proofs": [ "xrztiAm5MFFmpiaaSZnuiyzY2kp1TGhHjFmUupJ7Esw3Gpu3SX7SGT6huKLE2CEgZriMbpQtiHvcc1TaRbu13w8" ], "script": "base64:BgIiCAISAwoBCBIAEgUKAwgIARIDCgEIEgASBQoDCAgIEgASABEABXdhdmVzAIDC1y8ADnRpY2tldFByaWNlSW50AMCEPQALdGlja2V0UHJpY2UFDnRpY2tldFByaWNlSW50AAZpbnZGZWUAoMIeABJ3aXRoZHJhd0ZlZVBlcmNlbnQABQAWZmVlQ29sbGVjdG9yQWRkcmVzc0tleQITZmVlQ29sbGVjdG9yQWRkcmVzcwAOZGVwb3NpdEFzc2V0SWQCLDV1ZTFmaXVWNmo2VUJyNlhmMjhRbXM2eTVGcXpLdHF2YXh4aHd1N2hUUTU4AQ10cnlHZXRJbnRlZ2VyAQNrZXkEByRtYXRjaDAJAJoIAgUEdGhpcwUDa2V5AwkAAQIFByRtYXRjaDACA0ludAQBYgUHJG1hdGNoMAUBYgAAARJnZXRUaWNrZXRzQ291bnRLZXkBDWFkZHJlc3NTdHJpbmcJAKwCAgUNYWRkcmVzc1N0cmluZwINX3RpY2tldHNDb3VudAENZ2FtZVdpbm5lcktleQEGZ2FtZUlkCQCsAgIFBmdhbWVJZAIHX3dpbm5lcgEYYWRkcmVzc0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KwCAgIfVGhlIHBheW1lbnQgbXVzdCBiZSBvZiBleGFjdGx5IAkApAMBBQ50aWNrZXRQcmljZUludAIGIHdhdmVzBA1jYWxsZXJBZGRyU3RyCQDYBAEICAUBaQZjYWxsZXIFYnl0ZXMEE2N1cnJlbnRUaWNrZXRzQ291bnQJAQ10cnlHZXRJbnRlZ2VyAQkBEmdldFRpY2tldHNDb3VudEtleQEFDWNhbGxlckFkZHJTdHIJAJQKAgkAzAgCCQEMSW50ZWdlckVudHJ5AgkBEmdldFRpY2tldHNDb3VudEtleQEFDWNhbGxlckFkZHJTdHIJAGQCBRNjdXJyZW50VGlja2V0c0NvdW50AAEFA25pbAABAQJ0eAEGdmVyaWZ5AAkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAgFAnR4D3NlbmRlclB1YmxpY0tleXBNt+s=", "height": 2185980, "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 currentAvailableFunds = tryGetInteger(addressAvailableFundsKey(playerAddr)) | |
88 | + | let currentGameLockedAmountForPlayer = tryGetInteger(addressLockedFundsForGameKey(playerAddr, gameId)) | |
89 | + | $Tuple2([IntegerEntry(addressAvailableFundsKey(playerAddr), (currentAvailableFunds + exitStackAmount)), IntegerEntry(addressTotalLockedFundsKey(playerAddr), (currentTotalLockedFunds - currentGameLockedAmountForPlayer)), IntegerEntry(addressLockedFundsForGameKey(playerAddr, gameId), 0)], 1) | |
90 | + | } | |
91 | + | ||
92 | + | ||
93 | + | ||
94 | + | @Callable(i) | |
95 | + | func lockFundsForGame (gameId) = { | |
96 | + | let pmt = if ((size(i.payments) == 1)) | |
97 | + | then i.payments[0] | |
98 | + | else throw("Please attach exactly one payment") | |
99 | + | if ((pmt.assetId != fromBase58String(depositAssetId))) | |
100 | + | then throw("You can only deposit USDN") | |
101 | + | else { | |
102 | + | let callerAddrStr = toBase58String(i.caller.bytes) | |
103 | + | let currentTotalLockedFunds = tryGetInteger(addressTotalLockedFundsKey(callerAddrStr)) | |
104 | + | let currentLockedFundsTotalHistory = tryGetInteger(addressLockedFundsTotalHistoryKey(callerAddrStr)) | |
105 | + | $Tuple2([IntegerEntry(addressTotalLockedFundsKey(callerAddrStr), (currentTotalLockedFunds + pmt.amount)), IntegerEntry(addressLockedFundsTotalHistoryKey(callerAddrStr), (currentLockedFundsTotalHistory + pmt.amount)), IntegerEntry(addressLockedFundsForGameKey(callerAddrStr, gameId), pmt.amount)], 1) | |
106 | + | } | |
107 | + | } | |
108 | + | ||
109 | + | ||
110 | + | ||
111 | + | @Callable(i) | |
112 | + | func withdrawFunds () = { | |
113 | + | let callerAddrStr = toBase58String(i.caller.bytes) | |
114 | + | let feeCollectorAddr = addressFromStringValue(getStringValue(feeCollectorAddressKey)) | |
115 | + | let currentAvailableFunds = tryGetInteger(addressAvailableFundsKey(callerAddrStr)) | |
116 | + | let withdrawFee = fraction(currentAvailableFunds, withdrawFeePercent, 100) | |
117 | + | let actualAvailableFunds = (currentAvailableFunds - withdrawFee) | |
118 | + | if ((0 >= actualAvailableFunds)) | |
119 | + | then throw("No available funds to withdraw") | |
120 | + | else [IntegerEntry(addressAvailableFundsKey(callerAddrStr), 0), ScriptTransfer(i.caller, actualAvailableFunds, fromBase58String(depositAssetId)), ScriptTransfer(feeCollectorAddr, withdrawFee, fromBase58String(depositAssetId))] | |
121 | + | } | |
122 | + | ||
123 | + | ||
124 | + | ||
125 | + | @Callable(i) | |
126 | + | func setWinnerHeadsUp (gameId,winnerAddrStr,otherPlayerAddr) = if ((i.caller != this)) | |
127 | + | then throw("Admin Only") | |
128 | + | else { | |
129 | + | let availableRewardsKey = addressAvailableRewardsKey(winnerAddrStr) | |
130 | + | let currentAvailableRewards = tryGetInteger(availableRewardsKey) | |
131 | + | let newTicketCountWinner = consumeTicket(winnerAddrStr) | |
132 | + | let newTicketCountOtherPlayer = consumeTicket(otherPlayerAddr) | |
133 | + | [StringEntry(gameWinnerKey(gameId), winnerAddrStr), IntegerEntry(availableRewardsKey, (currentAvailableRewards + (ticketPrice * 2))), IntegerEntry(getTicketsCountKey(winnerAddrStr), newTicketCountWinner), IntegerEntry(getTicketsCountKey(otherPlayerAddr), newTicketCountOtherPlayer)] | |
134 | + | } | |
135 | + | ||
136 | + | ||
137 | + | ||
138 | + | @Callable(i) | |
139 | + | func withdrawRewards () = { | |
140 | + | let callerAddrStr = toBase58String(i.caller.bytes) | |
141 | + | let feeCollectorAddr = addressFromStringValue(getStringValue(feeCollectorAddressKey)) | |
142 | + | let currentAvailableRewards = tryGetInteger(addressAvailableRewardsKey(callerAddrStr)) | |
143 | + | let withdrawFee = fraction(currentAvailableRewards, withdrawFeePercent, 100) | |
144 | + | let actualAvailableRewards = ((currentAvailableRewards - invFee) - withdrawFee) | |
145 | + | if ((0 >= currentAvailableRewards)) | |
146 | + | then throw("No available rewards to withdraw") | |
147 | + | else [IntegerEntry(addressAvailableRewardsKey(callerAddrStr), 0), ScriptTransfer(i.caller, actualAvailableRewards, unit), ScriptTransfer(feeCollectorAddr, withdrawFee, unit)] | |
148 | + | } | |
149 | + | ||
150 | + | ||
151 | + | ||
152 | + | @Callable(i) | |
153 | + | func buyTickets () = { | |
154 | + | let pmt = if ((size(i.payments) == 1)) | |
155 | + | then i.payments[0] | |
156 | + | else throw("Please attach exactly one payment") | |
157 | + | if (isDefined(pmt.assetId)) | |
158 | + | then throw("Tickets can only ibe purchased in Waves") | |
159 | + | else if ((pmt.amount != ticketPrice)) | |
160 | + | then throw((("The payment must be of exactly " + toString(ticketPriceInt)) + " waves")) | |
161 | + | else { | |
162 | + | let callerAddrStr = toBase58String(i.caller.bytes) | |
163 | + | let currentTicketsCount = tryGetInteger(getTicketsCountKey(callerAddrStr)) | |
164 | + | $Tuple2([IntegerEntry(getTicketsCountKey(callerAddrStr), (currentTicketsCount + 1))], 1) | |
165 | + | } | |
166 | + | } | |
167 | + | ||
168 | + | ||
169 | + | @Verifier(tx) | |
170 | + | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
171 | + |
github/deemru/w8io/026f985 22.19 ms ◑