tx · 8bP27cBvTuTg9QpT89hwg1XT8wCrn9f3rau2sSm1eDiQ 3Mz7AZHqAeMecF7aaE9HVsK94XVQKf1QCKg: -0.01400000 Waves 2022.03.11 17:01 [1959379] smart account 3Mz7AZHqAeMecF7aaE9HVsK94XVQKf1QCKg > SELF 0.00000000 Waves
{ "type": 13, "id": "8bP27cBvTuTg9QpT89hwg1XT8wCrn9f3rau2sSm1eDiQ", "fee": 1400000, "feeAssetId": null, "timestamp": 1647007342122, "version": 1, "sender": "3Mz7AZHqAeMecF7aaE9HVsK94XVQKf1QCKg", "senderPublicKey": "9o6mYaNcbcTi647J8XhDQg2VsHJCv5Jon1QFPCbFPoFh", "proofs": [ "53xgWo7yFbP97gM7nsyfcSMKR9B1Ci4iwCAL919LgHS4WRuanUD1Ay5JGyqEdm9Na1BxmHvkRvU9EKooRMTWsRKq" ], "script": "base64:AAIFAAAAAAAAABcIAhIFCgMBAQgSABIDCgEIEgMKAQgSAAAAABIBAAAAE2tleU1hbmFnZXJQdWJsaWNLZXkAAAAAAgAAABQlc19fbWFuYWdlclB1YmxpY0tleQEAAAAaa2V5UGVuZGluZ01hbmFnZXJQdWJsaWNLZXkAAAAAAgAAABslc19fcGVuZGluZ01hbmFnZXJQdWJsaWNLZXkAAAAACXNlcGFyYXRvcgIAAAACX18BAAAAD2dldFN0cmluZ09yRmFpbAAAAAIAAAAHYWRkcmVzcwAAAANrZXkJAQAAABN2YWx1ZU9yRXJyb3JNZXNzYWdlAAAAAgkABB0AAAACBQAAAAdhZGRyZXNzBQAAAANrZXkJAAEsAAAAAgkAASwAAAACCQABLAAAAAIJAAEsAAAAAgIAAAAKbWFuZGF0b3J5IAkABCUAAAABBQAAAAdhZGRyZXNzAgAAAAEuBQAAAANrZXkCAAAADyBpcyBub3QgZGVmaW5lZAAAAAAIa2V5U3RhcnQJAAS5AAAAAgkABEwAAAACAgAAAAIlcwkABEwAAAACAgAAAAVzdGFydAUAAAADbmlsBQAAAAlzZXBhcmF0b3IAAA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1hbmFnZXJQdWJsaWNLZXlPclVuaXQAAAAAAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAApCeXRlVmVjdG9yBAAAAAJwawUAAAAHJG1hdGNoMAUAAAACcGsDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABFVuaXQIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXkJAAACAAAAAQIAAAALTWF0Y2ggZXJyb3IJAAH0AAAAAwgFAAAAAnR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAACdHgAAAAGcHJvb2ZzAAAAAAAAAAAABQAAAA90YXJnZXRQdWJsaWNLZXmx4s+t", "chainId": 84, "height": 1959379, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: FJpctF1YcHbZMrtBTDWsD1Bw9rzggSVn4Z6BST5erE9k Next: BftZoJ9A1HJVoXugiK3WneSojGCKKXCpRGr318jUfmY6 Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | func keyManagerPublicKey () = "%s__managerPublicKey" | |
5 | + | ||
6 | + | ||
7 | + | func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey" | |
8 | + | ||
9 | + | ||
4 | 10 | let separator = "__" | |
5 | 11 | ||
6 | 12 | func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), (((("mandatory " + toString(address)) + ".") + key) + " is not defined")) | |
49 | 55 | } | |
50 | 56 | ||
51 | 57 | ||
58 | + | func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) { | |
59 | + | case s: String => | |
60 | + | fromBase58String(s) | |
61 | + | case _: Unit => | |
62 | + | unit | |
63 | + | case _ => | |
64 | + | throw("Match error") | |
65 | + | } | |
66 | + | ||
67 | + | ||
68 | + | func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) { | |
69 | + | case s: String => | |
70 | + | fromBase58String(s) | |
71 | + | case _: Unit => | |
72 | + | unit | |
73 | + | case _ => | |
74 | + | throw("Match error") | |
75 | + | } | |
76 | + | ||
77 | + | ||
78 | + | func mustManager (i) = { | |
79 | + | let pd = throw("Permission denied") | |
80 | + | match managerPublicKeyOrUnit() { | |
81 | + | case pk: ByteVector => | |
82 | + | if ((i.callerPublicKey == pk)) | |
83 | + | then true | |
84 | + | else pd | |
85 | + | case _: Unit => | |
86 | + | if ((i.caller == this)) | |
87 | + | then true | |
88 | + | else pd | |
89 | + | case _ => | |
90 | + | throw("Match error") | |
91 | + | } | |
92 | + | } | |
93 | + | ||
94 | + | ||
52 | 95 | @Callable(i) | |
53 | 96 | func constructor (start,duration,assetId) = { | |
54 | - | let checks = [if ((i.caller == this)) | |
55 | - | then true | |
56 | - | else throw("Access denied")] | |
57 | - | if ((checks == checks)) | |
97 | + | let checkCaller = mustManager(i) | |
98 | + | if ((checkCaller == checkCaller)) | |
58 | 99 | then [IntegerEntry(keyStart, start), IntegerEntry(keyDuration, duration), StringEntry(keyAsset, assetId), BooleanEntry(keyIsDataReady, false)] | |
59 | 100 | else throw("Strict value is not equal to itself.") | |
60 | 101 | } | |
63 | 104 | ||
64 | 105 | @Callable(i) | |
65 | 106 | func claim () = { | |
66 | - | let $ | |
67 | - | let total = $ | |
68 | - | let claimed = $ | |
69 | - | let available = $ | |
107 | + | let $t030183077 = getUserRewards(i.caller) | |
108 | + | let total = $t030183077._1 | |
109 | + | let claimed = $t030183077._2 | |
110 | + | let available = $t030183077._3 | |
70 | 111 | let asset = fromBase58String(getStringOrFail(this, keyAsset)) | |
71 | 112 | let balance = assetBalance(this, asset) | |
72 | 113 | let checks = [checkIfDataIsReady(), if ((available > 0)) | |
86 | 127 | let checks = [checkIfDataIsReady()] | |
87 | 128 | if ((checks == checks)) | |
88 | 129 | then { | |
89 | - | let $ | |
90 | - | let total = $ | |
91 | - | let claimed = $ | |
92 | - | let available = $ | |
130 | + | let $t037563839 = getUserRewards(addressFromStringValue(address)) | |
131 | + | let total = $t037563839._1 | |
132 | + | let claimed = $t037563839._2 | |
133 | + | let available = $t037563839._3 | |
93 | 134 | $Tuple2(nil, makeString(["%d%d%d", toString(total), toString(claimed), toString(available)], separator)) | |
94 | 135 | } | |
95 | 136 | else throw("Strict value is not equal to itself.") | |
96 | 137 | } | |
97 | 138 | ||
98 | 139 | ||
140 | + | ||
141 | + | @Callable(i) | |
142 | + | func setManager (pendingManagerPublicKey) = { | |
143 | + | let checkCaller = mustManager(i) | |
144 | + | if ((checkCaller == checkCaller)) | |
145 | + | then { | |
146 | + | let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey) | |
147 | + | if ((checkManagerPublicKey == checkManagerPublicKey)) | |
148 | + | then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)] | |
149 | + | else throw("Strict value is not equal to itself.") | |
150 | + | } | |
151 | + | else throw("Strict value is not equal to itself.") | |
152 | + | } | |
153 | + | ||
154 | + | ||
155 | + | ||
156 | + | @Callable(i) | |
157 | + | func confirmManager () = { | |
158 | + | let pm = pendingManagerPublicKeyOrUnit() | |
159 | + | let hasPM = if (isDefined(pm)) | |
160 | + | then true | |
161 | + | else throw("No pending manager") | |
162 | + | if ((hasPM == hasPM)) | |
163 | + | then { | |
164 | + | let checkPM = if ((i.callerPublicKey == value(pm))) | |
165 | + | then true | |
166 | + | else throw("You are not pending manager") | |
167 | + | if ((checkPM == checkPM)) | |
168 | + | then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())] | |
169 | + | else throw("Strict value is not equal to itself.") | |
170 | + | } | |
171 | + | else throw("Strict value is not equal to itself.") | |
172 | + | } | |
173 | + | ||
174 | + | ||
175 | + | @Verifier(tx) | |
176 | + | func verify () = { | |
177 | + | let targetPublicKey = match managerPublicKeyOrUnit() { | |
178 | + | case pk: ByteVector => | |
179 | + | pk | |
180 | + | case _: Unit => | |
181 | + | tx.senderPublicKey | |
182 | + | case _ => | |
183 | + | throw("Match error") | |
184 | + | } | |
185 | + | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
186 | + | } | |
187 | + |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | func keyManagerPublicKey () = "%s__managerPublicKey" | |
5 | + | ||
6 | + | ||
7 | + | func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey" | |
8 | + | ||
9 | + | ||
4 | 10 | let separator = "__" | |
5 | 11 | ||
6 | 12 | func getStringOrFail (address,key) = valueOrErrorMessage(getString(address, key), (((("mandatory " + toString(address)) + ".") + key) + " is not defined")) | |
7 | 13 | ||
8 | 14 | ||
9 | 15 | let keyStart = makeString(["%s", "start"], separator) | |
10 | 16 | ||
11 | 17 | let keyDuration = makeString(["%s", "duration"], separator) | |
12 | 18 | ||
13 | 19 | let keyAsset = makeString(["%s", "asset"], separator) | |
14 | 20 | ||
15 | 21 | let keyIsDataReady = makeString(["%s", "isDataReady"], separator) | |
16 | 22 | ||
17 | 23 | func keyUserRewardInfo (address) = makeString(["%s%s", "userRewardInfo", toString(address)], separator) | |
18 | 24 | ||
19 | 25 | ||
20 | 26 | func keyClaimHistoryRecord (address,txId) = makeString(["%s%s%s", "claimHistoryRecord", toString(address), toBase58String(txId)], separator) | |
21 | 27 | ||
22 | 28 | ||
23 | 29 | func formatHistoryRecord (amount) = makeString(["%d%d%d", toString(height), toString(lastBlock.timestamp), toString(amount)], separator) | |
24 | 30 | ||
25 | 31 | ||
26 | 32 | func dataUserRewardInfo (totalAmt,claimedAmt) = makeString(["%d%d", toString(totalAmt), toString(claimedAmt)], separator) | |
27 | 33 | ||
28 | 34 | ||
29 | 35 | func readUserRewardInfo (userAddr) = split(getStringOrFail(this, keyUserRewardInfo(userAddr)), separator) | |
30 | 36 | ||
31 | 37 | ||
32 | 38 | func checkIfDataIsReady () = { | |
33 | 39 | let isDataReady = valueOrElse(getBoolean(this, keyIsDataReady), false) | |
34 | 40 | if (isDataReady) | |
35 | 41 | then true | |
36 | 42 | else throw("Data is not ready") | |
37 | 43 | } | |
38 | 44 | ||
39 | 45 | ||
40 | 46 | func getUserRewards (address) = { | |
41 | 47 | let start = valueOrErrorMessage(getInteger(this, keyStart), "Start block is not specified") | |
42 | 48 | let duration = valueOrErrorMessage(getInteger(this, keyDuration), "Duration is not specified") | |
43 | 49 | let userRewardInfo = readUserRewardInfo(address) | |
44 | 50 | let total = parseIntValue(userRewardInfo[1]) | |
45 | 51 | let claimed = parseIntValue(userRewardInfo[2]) | |
46 | 52 | let availableTotal = fraction(total, min([duration, max([0, (height - start)])]), duration) | |
47 | 53 | let available = max([0, (availableTotal - claimed)]) | |
48 | 54 | $Tuple3(total, claimed, available) | |
49 | 55 | } | |
50 | 56 | ||
51 | 57 | ||
58 | + | func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) { | |
59 | + | case s: String => | |
60 | + | fromBase58String(s) | |
61 | + | case _: Unit => | |
62 | + | unit | |
63 | + | case _ => | |
64 | + | throw("Match error") | |
65 | + | } | |
66 | + | ||
67 | + | ||
68 | + | func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) { | |
69 | + | case s: String => | |
70 | + | fromBase58String(s) | |
71 | + | case _: Unit => | |
72 | + | unit | |
73 | + | case _ => | |
74 | + | throw("Match error") | |
75 | + | } | |
76 | + | ||
77 | + | ||
78 | + | func mustManager (i) = { | |
79 | + | let pd = throw("Permission denied") | |
80 | + | match managerPublicKeyOrUnit() { | |
81 | + | case pk: ByteVector => | |
82 | + | if ((i.callerPublicKey == pk)) | |
83 | + | then true | |
84 | + | else pd | |
85 | + | case _: Unit => | |
86 | + | if ((i.caller == this)) | |
87 | + | then true | |
88 | + | else pd | |
89 | + | case _ => | |
90 | + | throw("Match error") | |
91 | + | } | |
92 | + | } | |
93 | + | ||
94 | + | ||
52 | 95 | @Callable(i) | |
53 | 96 | func constructor (start,duration,assetId) = { | |
54 | - | let checks = [if ((i.caller == this)) | |
55 | - | then true | |
56 | - | else throw("Access denied")] | |
57 | - | if ((checks == checks)) | |
97 | + | let checkCaller = mustManager(i) | |
98 | + | if ((checkCaller == checkCaller)) | |
58 | 99 | then [IntegerEntry(keyStart, start), IntegerEntry(keyDuration, duration), StringEntry(keyAsset, assetId), BooleanEntry(keyIsDataReady, false)] | |
59 | 100 | else throw("Strict value is not equal to itself.") | |
60 | 101 | } | |
61 | 102 | ||
62 | 103 | ||
63 | 104 | ||
64 | 105 | @Callable(i) | |
65 | 106 | func claim () = { | |
66 | - | let $ | |
67 | - | let total = $ | |
68 | - | let claimed = $ | |
69 | - | let available = $ | |
107 | + | let $t030183077 = getUserRewards(i.caller) | |
108 | + | let total = $t030183077._1 | |
109 | + | let claimed = $t030183077._2 | |
110 | + | let available = $t030183077._3 | |
70 | 111 | let asset = fromBase58String(getStringOrFail(this, keyAsset)) | |
71 | 112 | let balance = assetBalance(this, asset) | |
72 | 113 | let checks = [checkIfDataIsReady(), if ((available > 0)) | |
73 | 114 | then true | |
74 | 115 | else throw("No reward available"), if ((balance >= available)) | |
75 | 116 | then true | |
76 | 117 | else throw("Insufficient funds. Contact support")] | |
77 | 118 | if ((checks == checks)) | |
78 | 119 | then [ScriptTransfer(i.caller, available, asset), StringEntry(keyUserRewardInfo(i.caller), dataUserRewardInfo(total, (claimed + available))), StringEntry(keyClaimHistoryRecord(i.caller, i.transactionId), formatHistoryRecord(available))] | |
79 | 120 | else throw("Strict value is not equal to itself.") | |
80 | 121 | } | |
81 | 122 | ||
82 | 123 | ||
83 | 124 | ||
84 | 125 | @Callable(i) | |
85 | 126 | func getUserRewardsREADONLY (address) = { | |
86 | 127 | let checks = [checkIfDataIsReady()] | |
87 | 128 | if ((checks == checks)) | |
88 | 129 | then { | |
89 | - | let $ | |
90 | - | let total = $ | |
91 | - | let claimed = $ | |
92 | - | let available = $ | |
130 | + | let $t037563839 = getUserRewards(addressFromStringValue(address)) | |
131 | + | let total = $t037563839._1 | |
132 | + | let claimed = $t037563839._2 | |
133 | + | let available = $t037563839._3 | |
93 | 134 | $Tuple2(nil, makeString(["%d%d%d", toString(total), toString(claimed), toString(available)], separator)) | |
94 | 135 | } | |
95 | 136 | else throw("Strict value is not equal to itself.") | |
96 | 137 | } | |
97 | 138 | ||
98 | 139 | ||
140 | + | ||
141 | + | @Callable(i) | |
142 | + | func setManager (pendingManagerPublicKey) = { | |
143 | + | let checkCaller = mustManager(i) | |
144 | + | if ((checkCaller == checkCaller)) | |
145 | + | then { | |
146 | + | let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey) | |
147 | + | if ((checkManagerPublicKey == checkManagerPublicKey)) | |
148 | + | then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)] | |
149 | + | else throw("Strict value is not equal to itself.") | |
150 | + | } | |
151 | + | else throw("Strict value is not equal to itself.") | |
152 | + | } | |
153 | + | ||
154 | + | ||
155 | + | ||
156 | + | @Callable(i) | |
157 | + | func confirmManager () = { | |
158 | + | let pm = pendingManagerPublicKeyOrUnit() | |
159 | + | let hasPM = if (isDefined(pm)) | |
160 | + | then true | |
161 | + | else throw("No pending manager") | |
162 | + | if ((hasPM == hasPM)) | |
163 | + | then { | |
164 | + | let checkPM = if ((i.callerPublicKey == value(pm))) | |
165 | + | then true | |
166 | + | else throw("You are not pending manager") | |
167 | + | if ((checkPM == checkPM)) | |
168 | + | then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())] | |
169 | + | else throw("Strict value is not equal to itself.") | |
170 | + | } | |
171 | + | else throw("Strict value is not equal to itself.") | |
172 | + | } | |
173 | + | ||
174 | + | ||
175 | + | @Verifier(tx) | |
176 | + | func verify () = { | |
177 | + | let targetPublicKey = match managerPublicKeyOrUnit() { | |
178 | + | case pk: ByteVector => | |
179 | + | pk | |
180 | + | case _: Unit => | |
181 | + | tx.senderPublicKey | |
182 | + | case _ => | |
183 | + | throw("Match error") | |
184 | + | } | |
185 | + | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
186 | + | } | |
187 | + |
github/deemru/w8io/169f3d6 37.88 ms ◑