tx · 3K92hmf8Uj3vdqpZ3seYndg43tegzPuGkPjprZbJiPJR 3MyDGEoKp1gF4LSRknk9vSuDEyrwuYXcQEQ: -0.01000000 Waves 2022.05.11 13:48 [2046900] smart account 3MyDGEoKp1gF4LSRknk9vSuDEyrwuYXcQEQ > SELF 0.00000000 Waves
{ "type": 13, "id": "3K92hmf8Uj3vdqpZ3seYndg43tegzPuGkPjprZbJiPJR", "fee": 1000000, "feeAssetId": null, "timestamp": 1652266135600, "version": 2, "chainId": 84, "sender": "3MyDGEoKp1gF4LSRknk9vSuDEyrwuYXcQEQ", "senderPublicKey": "BhRnrwd6wVHSkSaWXCjQRjaoXcpCdUW2hkJD6V7uVDxN", "proofs": [ "4EVwg6gGgyUDwng2bnxPaJZBUzBhtpf2GisKgD2pgkwYyfLtJyyk5qYdpU7ZUYfCz6yKeZRv5aSJT2cztDemsyXq" ], "script": "base64:AAIFAAAAAAAAADYIAhIAEgQKAggBEgMKAQESBQoDCAgBEgQKAggBEgQKAggBEgASBAoCCAESBAoCCAESBAoCCAEAAAAMAAAAAApzaGlueXdnZ2lkAQAAACCJac8C/7a6udRxltd5uJl2JrB00Hd59HNuhvD0c58GJgAAAAAMYWRtaW5BZGRyZXNzCQEAAAARQGV4dHJOYXRpdmUoMTA2MikAAAABAgAAACMzTXBOdGlQU1JTcTZObmFRWWszOEJmV1N6WmNnQVlUeXJROQAAAAANYXNzZXRzQWRkcmVzcwEAAAAaAVTL5rTBd9cdJy1rFhBLypFI6ymLChqVp5oAAAAADm5hdGlvbnNBZGRyZXNzAQAAABoBVE2F6N70+ERrWRA7cF/Dt7llDlH1REZtoAEAAAANdHJ5R2V0SW50ZWdlcgAAAAEAAAADa2V5BAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAFiBQAAAAckbWF0Y2gwBQAAAAFiAAAAAAAAAAAAAQAAAA10cnlHZXRCb29sZWFuA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hc2VOYXRpb25XYWxsZXQAAAACAAAACU5hdGlvbktleQAAAAZhbW91bnQDCQEAAAABIQAAAAEJAQAAAApjaGVja0FkbWluAAAAAQgFAAAAAWkAAAAGY2FsbGVyCQAAAgAAAAECAAAAMHlvdSBhcmUgbm90IGF1dGhvcml6ZWQgdG8gcGVyZm9ybSB0aGlzIG9wZXJhdGlvbgQAAAADa2V5CQEAAAAOZ2V0VHJlYXN1cnlLZXkAAAABBQAAAAlOYXRpb25LZXkEAAAADnJlc2VydmVkQW1vdW50CQEAAAANdHJ5R2V0SW50ZWdlcgAAAAEFAAAAA2tleQkABRQAAAACCQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACBQAAAANrZXkJAABkAAAAAgUAAAAOcmVzZXJ2ZWRBbW91bnQFAAAABmFtb3VudAUAAAADbmlsCQAAZAAAAAIFAAAADnJlc2VydmVkQW1vdW50BQAAAAZhbW91bnQAAAABaQEAAAAUZGVjcmVhc2VOYXRpb25XYWxsZXQAAAACAAAACU5hdGlvbktleQAAAAZhbW91bnQDCQEAAAABIQAAAAEJAQAAAApjaGVja0FkbWluAAAAAQgFAAAAAWkAAAAGY2FsbGVyCQAAAgAAAAECAAAAMHlvdSBhcmUgbm90IGF1dGhvcml6ZWQgdG8gcGVyZm9ybSB0aGlzIG9wZXJhdGlvbgQAAAADa2V5CQEAAAAOZ2V0VHJlYXN1cnlLZXkAAAABBQAAAAlOYXRpb25LZXkEAAAADnJlc2VydmVkQW1vdW50CQEAAAANdHJ5R2V0SW50ZWdlcgAAAAEFAAAAA2tleQkABRQAAAACCQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACBQAAAANrZXkJAABlAAAAAgUAAAAOcmVzZXJ2ZWRBbW91bnQFAAAABmFtb3VudAUAAAADbmlsCQAAZQAAAAIFAAAADnJlc2VydmVkQW1vdW50BQAAAAZhbW91bnQAAAAA7sb/Kg==", "height": 2046900, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6oKHoYqen3jz29SpjWYHWYtrn3aQcty9Yc9e5kERP2Qv Next: 71MsKjrx7rDqJ9qwAxhKeY59D7SuaycTWjPuHvBz2e57 Diff:
Old | New | Differences | |
---|---|---|---|
25 | 25 | } | |
26 | 26 | ||
27 | 27 | ||
28 | + | func getTreasuryKey (nationid) = (nationid + "_Treasury") | |
29 | + | ||
30 | + | ||
28 | 31 | func internalDeposit (addressStr,amountIn) = { | |
29 | 32 | let amount = tryGetInteger((addressStr + "_Deposit")) | |
30 | 33 | [IntegerEntry((addressStr + "_Deposit"), (amount + amountIn))] | |
50 | 53 | func internalTransfer (fromAddress,toAddress,amount) = (internalPay(fromAddress, amount) ++ internalDeposit(toAddress, amount)) | |
51 | 54 | ||
52 | 55 | ||
53 | - | func | |
54 | - | | |
55 | - | | |
56 | - | | |
57 | - | | |
58 | - | | |
59 | - | | |
56 | + | func checkAdmin (caller) = if (if (if ((caller == adminAddress)) | |
57 | + | then true | |
58 | + | else (caller == this)) | |
59 | + | then true | |
60 | + | else (caller.bytes == nationsAddress)) | |
61 | + | then true | |
62 | + | else (caller.bytes == assetsAddress) | |
60 | 63 | ||
61 | 64 | ||
62 | 65 | @Callable(i) | |
86 | 89 | ||
87 | 90 | ||
88 | 91 | @Callable(i) | |
89 | - | func Pay (addressStr,amount) = if (if (if ((i.caller != this)) | |
90 | - | then (i.caller != adminAddress) | |
91 | - | else false) | |
92 | - | then (i.caller.bytes != assetsAddress) | |
93 | - | else false) | |
92 | + | func Pay (addressStr,amount) = if (!(checkAdmin(i.caller))) | |
94 | 93 | then throw("you are not authorized to perform this operation") | |
95 | 94 | else $Tuple2(internalPay(addressStr, amount), amount) | |
96 | 95 | ||
141 | 140 | ||
142 | 141 | ||
143 | 142 | @Callable(i) | |
144 | - | func setRewards (rewards) = if (if ((i.caller != adminAddress)) | |
145 | - | then (i.caller.bytes != assetsAddress) | |
146 | - | else false) | |
143 | + | func addReward (addressStr,amount) = if (!(checkAdmin(i.caller))) | |
147 | 144 | then throw("you are not authorized to perform this operation") | |
148 | 145 | else { | |
149 | - | let it = size(rewards) | |
150 | - | if ((it > 60)) | |
151 | - | then throw("you can write max 60 records per call") | |
152 | - | else { | |
153 | - | let $l = rewards | |
154 | - | let $s = size($l) | |
155 | - | let $acc0 = nil | |
156 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
157 | - | then $a | |
158 | - | else addRewardEntry($a, $l[$i]) | |
146 | + | let reservedAmount = tryGetInteger((addressStr + "_Reserved")) | |
147 | + | $Tuple2([IntegerEntry((addressStr + "_Reserved"), (reservedAmount + amount))], (reservedAmount + amount)) | |
148 | + | } | |
159 | 149 | ||
160 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
161 | - | then $a | |
162 | - | else throw("List size exceeds 60") | |
163 | 150 | ||
164 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20), 21), 22), 23), 24), 25), 26), 27), 28), 29), 30), 31), 32), 33), 34), 35), 36), 37), 38), 39), 40), 41), 42), 43), 44), 45), 46), 47), 48), 49), 50), 51), 52), 53), 54), 55), 56), 57), 58), 59), 60) | |
165 | - | } | |
151 | + | ||
152 | + | @Callable(i) | |
153 | + | func increaseNationWallet (NationKey,amount) = if (!(checkAdmin(i.caller))) | |
154 | + | then throw("you are not authorized to perform this operation") | |
155 | + | else { | |
156 | + | let key = getTreasuryKey(NationKey) | |
157 | + | let reservedAmount = tryGetInteger(key) | |
158 | + | $Tuple2([IntegerEntry(key, (reservedAmount + amount))], (reservedAmount + amount)) | |
159 | + | } | |
160 | + | ||
161 | + | ||
162 | + | ||
163 | + | @Callable(i) | |
164 | + | func decreaseNationWallet (NationKey,amount) = if (!(checkAdmin(i.caller))) | |
165 | + | then throw("you are not authorized to perform this operation") | |
166 | + | else { | |
167 | + | let key = getTreasuryKey(NationKey) | |
168 | + | let reservedAmount = tryGetInteger(key) | |
169 | + | $Tuple2([IntegerEntry(key, (reservedAmount - amount))], (reservedAmount - amount)) | |
166 | 170 | } | |
167 | 171 | ||
168 | 172 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let shinywggid = base58'AFQS5E4ELtxex3iANtWtUU2V2oWJZSo8VVnK8z3VFmqf' | |
5 | 5 | ||
6 | 6 | let adminAddress = addressFromStringValue("3MpNtiPSRSq6NnaQYk38BfWSzZcgAYTyrQ9") | |
7 | 7 | ||
8 | 8 | let assetsAddress = base58'3N8WDKbqGox5Eky326PHHT7rUyrby5MXdmb' | |
9 | 9 | ||
10 | 10 | let nationsAddress = base58'3MvyzDtzWWV5MZ1GP8JfQhhQqiGU4Nbifdy' | |
11 | 11 | ||
12 | 12 | func tryGetInteger (key) = match getInteger(this, key) { | |
13 | 13 | case b: Int => | |
14 | 14 | b | |
15 | 15 | case _ => | |
16 | 16 | 0 | |
17 | 17 | } | |
18 | 18 | ||
19 | 19 | ||
20 | 20 | func tryGetBoolean (key) = match getBoolean(this, key) { | |
21 | 21 | case b: Boolean => | |
22 | 22 | b | |
23 | 23 | case _ => | |
24 | 24 | false | |
25 | 25 | } | |
26 | 26 | ||
27 | 27 | ||
28 | + | func getTreasuryKey (nationid) = (nationid + "_Treasury") | |
29 | + | ||
30 | + | ||
28 | 31 | func internalDeposit (addressStr,amountIn) = { | |
29 | 32 | let amount = tryGetInteger((addressStr + "_Deposit")) | |
30 | 33 | [IntegerEntry((addressStr + "_Deposit"), (amount + amountIn))] | |
31 | 34 | } | |
32 | 35 | ||
33 | 36 | ||
34 | 37 | func internalPay (addressStr,amount) = { | |
35 | 38 | let deposited = tryGetInteger((addressStr + "_Deposit")) | |
36 | 39 | if ((0 > (deposited - amount))) | |
37 | 40 | then throw("Not enough deposit.") | |
38 | 41 | else if (((deposited - amount) == 0)) | |
39 | 42 | then [DeleteEntry((addressStr + "_Deposit"))] | |
40 | 43 | else [IntegerEntry((addressStr + "_Deposit"), (deposited - amount))] | |
41 | 44 | } | |
42 | 45 | ||
43 | 46 | ||
44 | 47 | func internalReserve (addressStr,amount) = { | |
45 | 48 | let reservedAmount = tryGetInteger((addressStr + "_Reserved")) | |
46 | 49 | [IntegerEntry((addressStr + "_Reserved"), (reservedAmount + amount))] | |
47 | 50 | } | |
48 | 51 | ||
49 | 52 | ||
50 | 53 | func internalTransfer (fromAddress,toAddress,amount) = (internalPay(fromAddress, amount) ++ internalDeposit(toAddress, amount)) | |
51 | 54 | ||
52 | 55 | ||
53 | - | func | |
54 | - | | |
55 | - | | |
56 | - | | |
57 | - | | |
58 | - | | |
59 | - | | |
56 | + | func checkAdmin (caller) = if (if (if ((caller == adminAddress)) | |
57 | + | then true | |
58 | + | else (caller == this)) | |
59 | + | then true | |
60 | + | else (caller.bytes == nationsAddress)) | |
61 | + | then true | |
62 | + | else (caller.bytes == assetsAddress) | |
60 | 63 | ||
61 | 64 | ||
62 | 65 | @Callable(i) | |
63 | 66 | func Deposit () = { | |
64 | 67 | let addressStr = toString(i.originCaller) | |
65 | 68 | let pmt = i.payments[0] | |
66 | 69 | if ((pmt == pmt)) | |
67 | 70 | then { | |
68 | 71 | let amountIn = value(i.payments[0].amount) | |
69 | 72 | if ((amountIn == amountIn)) | |
70 | 73 | then { | |
71 | 74 | let assetIn = pmt.assetId | |
72 | 75 | if ((assetIn == assetIn)) | |
73 | 76 | then if ((assetIn != shinywggid)) | |
74 | 77 | then throw("Only $HEG payments allowed") | |
75 | 78 | else { | |
76 | 79 | let amount = tryGetInteger((addressStr + "_Deposit")) | |
77 | 80 | $Tuple2(internalDeposit(addressStr, (amount + amountIn)), (amount + amountIn)) | |
78 | 81 | } | |
79 | 82 | else throw("Strict value is not equal to itself.") | |
80 | 83 | } | |
81 | 84 | else throw("Strict value is not equal to itself.") | |
82 | 85 | } | |
83 | 86 | else throw("Strict value is not equal to itself.") | |
84 | 87 | } | |
85 | 88 | ||
86 | 89 | ||
87 | 90 | ||
88 | 91 | @Callable(i) | |
89 | - | func Pay (addressStr,amount) = if (if (if ((i.caller != this)) | |
90 | - | then (i.caller != adminAddress) | |
91 | - | else false) | |
92 | - | then (i.caller.bytes != assetsAddress) | |
93 | - | else false) | |
92 | + | func Pay (addressStr,amount) = if (!(checkAdmin(i.caller))) | |
94 | 93 | then throw("you are not authorized to perform this operation") | |
95 | 94 | else $Tuple2(internalPay(addressStr, amount), amount) | |
96 | 95 | ||
97 | 96 | ||
98 | 97 | ||
99 | 98 | @Callable(i) | |
100 | 99 | func CallerPay (amount) = { | |
101 | 100 | let callerAddr = toString(i.caller) | |
102 | 101 | internalPay(callerAddr, amount) | |
103 | 102 | } | |
104 | 103 | ||
105 | 104 | ||
106 | 105 | ||
107 | 106 | @Callable(i) | |
108 | 107 | func transferCoins (fromAddress,toAddress,amount) = if (if ((i.caller != adminAddress)) | |
109 | 108 | then (i.caller.bytes != assetsAddress) | |
110 | 109 | else false) | |
111 | 110 | then throw("you are not authorized to perform this operation") | |
112 | 111 | else internalTransfer(fromAddress, toAddress, amount) | |
113 | 112 | ||
114 | 113 | ||
115 | 114 | ||
116 | 115 | @Callable(i) | |
117 | 116 | func callerTransferCoins (toAddress,amount) = internalTransfer(toString(i.caller), toAddress, amount) | |
118 | 117 | ||
119 | 118 | ||
120 | 119 | ||
121 | 120 | @Callable(i) | |
122 | 121 | func arbitraryAddCoins (toAddress,amount) = if (if (if ((i.caller != adminAddress)) | |
123 | 122 | then (i.caller.bytes != assetsAddress) | |
124 | 123 | else false) | |
125 | 124 | then (i.caller.bytes != nationsAddress) | |
126 | 125 | else false) | |
127 | 126 | then throw("you are not authorized to perform this operation") | |
128 | 127 | else internalDeposit(toAddress, amount) | |
129 | 128 | ||
130 | 129 | ||
131 | 130 | ||
132 | 131 | @Callable(i) | |
133 | 132 | func Redeem () = { | |
134 | 133 | let addressStr = toString(i.caller) | |
135 | 134 | let reservedAmount = tryGetInteger((addressStr + "_Reserved")) | |
136 | 135 | if ((reservedAmount == 0)) | |
137 | 136 | then throw("Nothing to redeem") | |
138 | 137 | else [DeleteEntry((addressStr + "_Reserved")), ScriptTransfer(i.caller, reservedAmount, shinywggid)] | |
139 | 138 | } | |
140 | 139 | ||
141 | 140 | ||
142 | 141 | ||
143 | 142 | @Callable(i) | |
144 | - | func setRewards (rewards) = if (if ((i.caller != adminAddress)) | |
145 | - | then (i.caller.bytes != assetsAddress) | |
146 | - | else false) | |
143 | + | func addReward (addressStr,amount) = if (!(checkAdmin(i.caller))) | |
147 | 144 | then throw("you are not authorized to perform this operation") | |
148 | 145 | else { | |
149 | - | let it = size(rewards) | |
150 | - | if ((it > 60)) | |
151 | - | then throw("you can write max 60 records per call") | |
152 | - | else { | |
153 | - | let $l = rewards | |
154 | - | let $s = size($l) | |
155 | - | let $acc0 = nil | |
156 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
157 | - | then $a | |
158 | - | else addRewardEntry($a, $l[$i]) | |
146 | + | let reservedAmount = tryGetInteger((addressStr + "_Reserved")) | |
147 | + | $Tuple2([IntegerEntry((addressStr + "_Reserved"), (reservedAmount + amount))], (reservedAmount + amount)) | |
148 | + | } | |
159 | 149 | ||
160 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
161 | - | then $a | |
162 | - | else throw("List size exceeds 60") | |
163 | 150 | ||
164 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20), 21), 22), 23), 24), 25), 26), 27), 28), 29), 30), 31), 32), 33), 34), 35), 36), 37), 38), 39), 40), 41), 42), 43), 44), 45), 46), 47), 48), 49), 50), 51), 52), 53), 54), 55), 56), 57), 58), 59), 60) | |
165 | - | } | |
151 | + | ||
152 | + | @Callable(i) | |
153 | + | func increaseNationWallet (NationKey,amount) = if (!(checkAdmin(i.caller))) | |
154 | + | then throw("you are not authorized to perform this operation") | |
155 | + | else { | |
156 | + | let key = getTreasuryKey(NationKey) | |
157 | + | let reservedAmount = tryGetInteger(key) | |
158 | + | $Tuple2([IntegerEntry(key, (reservedAmount + amount))], (reservedAmount + amount)) | |
159 | + | } | |
160 | + | ||
161 | + | ||
162 | + | ||
163 | + | @Callable(i) | |
164 | + | func decreaseNationWallet (NationKey,amount) = if (!(checkAdmin(i.caller))) | |
165 | + | then throw("you are not authorized to perform this operation") | |
166 | + | else { | |
167 | + | let key = getTreasuryKey(NationKey) | |
168 | + | let reservedAmount = tryGetInteger(key) | |
169 | + | $Tuple2([IntegerEntry(key, (reservedAmount - amount))], (reservedAmount - amount)) | |
166 | 170 | } | |
167 | 171 | ||
168 | 172 |
github/deemru/w8io/169f3d6 54.08 ms ◑