tx · Gq3EjRnmETyUCvUVkuhe91aMDGXT5kiWKNPJAhoi2qXK

3Mzj8MyE3E3G55SLVE6Dgd6ew2uERLxiE4U:  -0.01300000 Waves

2022.10.27 10:23 [2290524] smart account 3Mzj8MyE3E3G55SLVE6Dgd6ew2uERLxiE4U > SELF 0.00000000 Waves

{ "type": 13, "id": "Gq3EjRnmETyUCvUVkuhe91aMDGXT5kiWKNPJAhoi2qXK", "fee": 1300000, "feeAssetId": null, "timestamp": 1666855364441, "version": 1, "sender": "3Mzj8MyE3E3G55SLVE6Dgd6ew2uERLxiE4U", "senderPublicKey": "8E1ZoUTJyyA7ybXtP2NxUZKdAwvR1ruiQUxZD2bYJJMF", "proofs": [ "3hz8RA6GteRjgH87y9XaqA2DxkGx9gh1obP5bCCPkVURPgJgDQmoswqmwcbtDbj9iJjq9BhUwnMWf4DRa6XR4UyF" ], "script": "base64:BgKBCQgCEgMKAQESAwoBARIDCgEBEgMKAQESAwoBARIECgIICBIAEgASBAoCAQESAwoBCBIAIg9kZWNpbWFsUGFydFVTRE4iD2RlY2ltYWxQYXJ0VVNEVCIQa2V5V2l0aGRyYXdEZWxheSINd2l0aGRyYXdEZWxheSIaa2V5TWluaW1hbEFtb3VudFRvU3dhcFVzZHQiGmtleU1pbmltYWxBbW91bnRUb1N3YXBVc2RuIgdtaW5Vc2R0IgdtaW5Vc2RuIhNrZXlNYW5hZ2VyUHVibGljS2V5IhprZXlQZW5kaW5nTWFuYWdlclB1YmxpY0tleSIOa2V5VXNkdEFzc2V0SWQiDmtleVVzZG5Bc3NldElkIg1rZXlEZXBvc2l0RmVlIg5rZXlXaXRoZHJhd0ZlZSIEdXNkdCIEdXNkbiIWbWFuYWdlclB1YmxpY0tleU9yVW5pdCIHJG1hdGNoMCIBcyIdcGVuZGluZ01hbmFnZXJQdWJsaWNLZXlPclVuaXQiCmNvbGxlY3RLZXkiB2FkZHJlc3MiEWFtb3VudFRvU3dhcEluS2V5IhVhbGxvd1RvV2l0aGRyYXdI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maXJtTWFuYWdlcgAEAmFyCQEBdAAEAmFzAwkBCWlzRGVmaW5lZAEFAmFyBgkAAgECEk5vIHBlbmRpbmcgbWFuYWdlcgMJAAACBQJhcwUCYXMEAmF0AwkAAAIIBQFXD2NhbGxlclB1YmxpY0tleQkBBXZhbHVlAQUCYXIGCQACAQIbWW91IGFyZSBub3QgcGVuZGluZyBtYW5hZ2VyAwkAAAIFAmF0BQJhdAkAzAgCCQELU3RyaW5nRW50cnkCCQEBaQAJANgEAQkBBXZhbHVlAQUCYXIJAMwIAgkBC0RlbGV0ZUVudHJ5AQkBAWoABQNuaWwJAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4JAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4BAmF1AQJhdgAEAmF3BAFyCQEBcQADCQABAgUBcgIKQnl0ZVZlY3RvcgQBWQUBcgUBWQMJAAECBQFyAgRVbml0CAUCYXUPc2VuZGVyUHVibGljS2V5CQACAQILTWF0Y2ggZXJyb3IJAPQDAwgFAmF1CWJvZHlCeXRlcwkAkQMCCAUCYXUGcHJvb2ZzAAAFAmF3TaG9jA==", "chainId": 84, "height": 2290524, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 5CbWP6npU5HkvemdY48ChsjY3PB9cyKFv7LyREAF6Xz3 Next: 9pMYz7CQRLwS2gJzuWaDjREjmhPkzEZBdY14jSGWnA9M Diff:
OldNewDifferences
1-{-# STDLIB_VERSION 5 #-}
1+{-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4+let decimalPartUSDN = 1000000
5+
6+let decimalPartUSDT = 1000000
7+
8+func keyWithdrawDelay () = "%s__withdrawDelay"
9+
10+
11+func withdrawDelay () = value(getInteger(keyWithdrawDelay()))
12+
13+
14+func keyMinimalAmountToSwapUsdt () = "%s__minimalAmountToSwapUsdt"
15+
16+
17+func keyMinimalAmountToSwapUsdn () = "%s__minimalAmountToSwapUsdn"
18+
19+
20+func minUsdt () = value(getInteger(keyMinimalAmountToSwapUsdt()))
21+
22+
23+func minUsdn () = value(getInteger(keyMinimalAmountToSwapUsdn()))
24+
25+
426 func keyManagerPublicKey () = "%s__managerPublicKey"
527
628
729 func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey"
30+
31+
32+func keyUsdtAssetId () = "%s__usdtAssetId"
33+
34+
35+func keyUsdnAssetId () = "%s__usdnAssetId"
36+
37+
38+func keyDepositFee () = "%s__depositFee"
39+
40+
41+func keyWithdrawFee () = "%s__withdrawFee"
42+
43+
44+func usdt () = fromBase58String(value(getString(keyUsdtAssetId())))
45+
46+
47+func usdn () = fromBase58String(value(getString(keyUsdnAssetId())))
848
949
1050 func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) {
2767 }
2868
2969
70+func collectKey (address,amountToSwapInKey,allowToWithdrawHeight) = makeString([address, "WITHDRAW", toString(amountToSwapInKey), "HEIGHT", toString(allowToWithdrawHeight)], "_")
71+
72+
73+func collectBalanceKey (address) = makeString([address, "balance"], "_")
74+
75+
76+func collectBalanceKeyWithFee (address) = makeString([address, "balance_with_fee"], "_")
77+
78+
79+func usdtToUsdnAssetError () = throw("To swap USDT to USDN you need attach payment in USDT")
80+
81+
82+func usdnToUsdtAssetError () = throw("To swap USDN to USDT you need attach payment in USDN")
83+
84+
85+func usdtToUsdnLowLimitError () = throw((("you can swap at least " + toString((minUsdt() / decimalPartUSDT))) + " tokens"))
86+
87+
88+func abs (n) = if ((0 > n))
89+ then (n * -1)
90+ else n
91+
92+
93+func getWithoutFeeWithdraw (amount,balanceWithoutFee) = min([amount, balanceWithoutFee])
94+
95+
96+func getListElementOrDefault (list,index,default) = if ((size(list) > index))
97+ then list[index]
98+ else default
99+
100+
101+func currentWithdrawals (address,amount) = {
102+ let balanceKey = collectBalanceKey(address)
103+ let balanceWithFeeKey = collectBalanceKeyWithFee(address)
104+ let currentClientBalance = valueOrElse(getInteger(this, balanceKey), 0)
105+ let currentClientBalanceWithFee = valueOrElse(getInteger(this, balanceWithFeeKey), 0)
106+ let userBalance = (currentClientBalance + currentClientBalanceWithFee)
107+ if (if ((amount > userBalance))
108+ then true
109+ else (minUsdn() > amount))
110+ then throw("Swap amount fail, amount is to small or to big.")
111+ else {
112+ let toWithdrawWithoutFee = getWithoutFeeWithdraw(amount, currentClientBalance)
113+ let toWithdrawWithFee = (amount - toWithdrawWithoutFee)
114+ let fee = ((toWithdrawWithFee / 100) * value(getInteger(keyWithdrawFee())))
115+[toWithdrawWithoutFee, toWithdrawWithFee, fee]
116+ }
117+ }
118+
119+
30120 func mustManager (i) = {
31121 let pd = throw("Permission denied")
32122 match managerPublicKeyOrUnit() {
42132 throw("Match error")
43133 }
44134 }
135+
136+
137+@Callable(i)
138+func setWithdrawDelay (newWithdrawDelay) = {
139+ let checkCaller = mustManager(i)
140+ if ((checkCaller == checkCaller))
141+ then [IntegerEntry(keyWithdrawDelay(), newWithdrawDelay)]
142+ else throw("Strict value is not equal to itself.")
143+ }
144+
145+
146+
147+@Callable(i)
148+func setMinimalAmountToSwapUsdt (newMinimalAmount) = {
149+ let checkCaller = mustManager(i)
150+ if ((checkCaller == checkCaller))
151+ then [IntegerEntry(keyMinimalAmountToSwapUsdt(), newMinimalAmount)]
152+ else throw("Strict value is not equal to itself.")
153+ }
154+
155+
156+
157+@Callable(i)
158+func setMinimalAmountToSwapUsdn (newMinimalAmount) = {
159+ let checkCaller = mustManager(i)
160+ if ((checkCaller == checkCaller))
161+ then [IntegerEntry(keyMinimalAmountToSwapUsdn(), newMinimalAmount)]
162+ else throw("Strict value is not equal to itself.")
163+ }
164+
165+
166+
167+@Callable(i)
168+func setWithdrawFee (newFee) = {
169+ let checkCaller = mustManager(i)
170+ if ((checkCaller == checkCaller))
171+ then [IntegerEntry(keyWithdrawFee(), newFee)]
172+ else throw("Strict value is not equal to itself.")
173+ }
174+
175+
176+
177+@Callable(i)
178+func setDepositFee (newFee) = {
179+ let checkCaller = mustManager(i)
180+ if ((checkCaller == checkCaller))
181+ then [IntegerEntry(keyDepositFee(), newFee)]
182+ else throw("Strict value is not equal to itself.")
183+ }
184+
185+
186+
187+@Callable(i)
188+func constructor (usdtAssetId,usdnAssetId) = {
189+ let checkCaller = mustManager(i)
190+ if ((checkCaller == checkCaller))
191+ then [StringEntry(keyUsdtAssetId(), usdtAssetId), StringEntry(keyUsdnAssetId(), usdnAssetId)]
192+ else throw("Strict value is not equal to itself.")
193+ }
194+
195+
196+
197+@Callable(invoke)
198+func swapUSDTtoUSDN () = {
199+ let balanceKey = collectBalanceKeyWithFee(toString(invoke.caller))
200+ let payment = value(invoke.payments[0])
201+ if ((payment.assetId != usdt()))
202+ then usdtToUsdnAssetError()
203+ else {
204+ let amount = payment.amount
205+ let fee = ((amount / 100) * value(getInteger(keyDepositFee())))
206+ let currentClientBalanceUSDT = valueOrElse(getInteger(this, balanceKey), 0)
207+ if ((minUsdt() > amount))
208+ then usdtToUsdnLowLimitError()
209+ else [IntegerEntry(balanceKey, (currentClientBalanceUSDT + amount)), ScriptTransfer(invoke.caller, (amount - fee), usdn())]
210+ }
211+ }
212+
213+
214+
215+@Callable(invoke)
216+func initializationUSDNtoUSDTswap () = {
217+ let payment = value(invoke.payments[0])
218+ let address = toString(invoke.caller)
219+ if ((payment.assetId != usdn()))
220+ then usdnToUsdtAssetError()
221+ else {
222+ let amount = payment.amount
223+ let balanceKey = collectBalanceKey(address)
224+ let balanceWithFeeKey = collectBalanceKeyWithFee(address)
225+ let currentClientBalance = valueOrElse(getInteger(this, balanceKey), 0)
226+ let currentClientBalanceWithFee = valueOrElse(getInteger(this, balanceWithFeeKey), 0)
227+ let userBalance = (currentClientBalance + currentClientBalanceWithFee)
228+ let data = currentWithdrawals(toString(invoke.caller), amount)
229+ let toWithdrawWithoutFee = valueOrErrorMessage(data[0], "Wrong 'currentWithdrawals' method!")
230+ let toWithdrawWithFee = valueOrErrorMessage(data[1], "Wrong 'currentWithdrawals' method!")
231+ let fee = valueOrErrorMessage(data[2], "Wrong 'currentWithdrawals' method!")
232+ let total = ((toWithdrawWithFee + toWithdrawWithoutFee) - fee)
233+ let allowToWithDrawHeight = (height + withdrawDelay())
234+ if (isDefined(getString(this, collectKey(toString(invoke.caller), amount, allowToWithDrawHeight))))
235+ then throw("You have already started withdrawal process, wait next block.")
236+ else [IntegerEntry(balanceKey, (currentClientBalance - toWithdrawWithoutFee)), IntegerEntry(balanceWithFeeKey, (currentClientBalanceWithFee - toWithdrawWithFee)), StringEntry(collectKey(toString(invoke.caller), amount, allowToWithDrawHeight), makeString(["not_withdrawn", toString((amount - fee))], "_"))]
237+ }
238+ }
239+
240+
241+
242+@Callable(invoke)
243+func swapUSDNtoUSDT (amount,heightInKey) = {
244+ let key = collectKey(toString(invoke.caller), amount, heightInKey)
245+ let withdrawnInfo = valueOrErrorMessage(getString(this, key), ((("This key doesn't exists " + key) + " at address ") + toString(this)))
246+ let toWithdraw = getListElementOrDefault(split(withdrawnInfo, "_"), 2, toString(amount))
247+ if (if ((height >= heightInKey))
248+ then contains(withdrawnInfo, "not_withdrawn")
249+ else false)
250+ then [DeleteEntry(key), ScriptTransfer(invoke.caller, valueOrErrorMessage(parseInt(toWithdraw), "Wrong withdraw data!"), usdt())]
251+ else throw((("Withdrawal is possible after " + toString(heightInKey)) + " height or you have already withdrawn USDT."))
252+ }
253+
45254
46255
47256 @Callable(i)
Full:
OldNewDifferences
1-{-# STDLIB_VERSION 5 #-}
1+{-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4+let decimalPartUSDN = 1000000
5+
6+let decimalPartUSDT = 1000000
7+
8+func keyWithdrawDelay () = "%s__withdrawDelay"
9+
10+
11+func withdrawDelay () = value(getInteger(keyWithdrawDelay()))
12+
13+
14+func keyMinimalAmountToSwapUsdt () = "%s__minimalAmountToSwapUsdt"
15+
16+
17+func keyMinimalAmountToSwapUsdn () = "%s__minimalAmountToSwapUsdn"
18+
19+
20+func minUsdt () = value(getInteger(keyMinimalAmountToSwapUsdt()))
21+
22+
23+func minUsdn () = value(getInteger(keyMinimalAmountToSwapUsdn()))
24+
25+
426 func keyManagerPublicKey () = "%s__managerPublicKey"
527
628
729 func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey"
30+
31+
32+func keyUsdtAssetId () = "%s__usdtAssetId"
33+
34+
35+func keyUsdnAssetId () = "%s__usdnAssetId"
36+
37+
38+func keyDepositFee () = "%s__depositFee"
39+
40+
41+func keyWithdrawFee () = "%s__withdrawFee"
42+
43+
44+func usdt () = fromBase58String(value(getString(keyUsdtAssetId())))
45+
46+
47+func usdn () = fromBase58String(value(getString(keyUsdnAssetId())))
848
949
1050 func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) {
1151 case s: String =>
1252 fromBase58String(s)
1353 case _: Unit =>
1454 unit
1555 case _ =>
1656 throw("Match error")
1757 }
1858
1959
2060 func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) {
2161 case s: String =>
2262 fromBase58String(s)
2363 case _: Unit =>
2464 unit
2565 case _ =>
2666 throw("Match error")
2767 }
2868
2969
70+func collectKey (address,amountToSwapInKey,allowToWithdrawHeight) = makeString([address, "WITHDRAW", toString(amountToSwapInKey), "HEIGHT", toString(allowToWithdrawHeight)], "_")
71+
72+
73+func collectBalanceKey (address) = makeString([address, "balance"], "_")
74+
75+
76+func collectBalanceKeyWithFee (address) = makeString([address, "balance_with_fee"], "_")
77+
78+
79+func usdtToUsdnAssetError () = throw("To swap USDT to USDN you need attach payment in USDT")
80+
81+
82+func usdnToUsdtAssetError () = throw("To swap USDN to USDT you need attach payment in USDN")
83+
84+
85+func usdtToUsdnLowLimitError () = throw((("you can swap at least " + toString((minUsdt() / decimalPartUSDT))) + " tokens"))
86+
87+
88+func abs (n) = if ((0 > n))
89+ then (n * -1)
90+ else n
91+
92+
93+func getWithoutFeeWithdraw (amount,balanceWithoutFee) = min([amount, balanceWithoutFee])
94+
95+
96+func getListElementOrDefault (list,index,default) = if ((size(list) > index))
97+ then list[index]
98+ else default
99+
100+
101+func currentWithdrawals (address,amount) = {
102+ let balanceKey = collectBalanceKey(address)
103+ let balanceWithFeeKey = collectBalanceKeyWithFee(address)
104+ let currentClientBalance = valueOrElse(getInteger(this, balanceKey), 0)
105+ let currentClientBalanceWithFee = valueOrElse(getInteger(this, balanceWithFeeKey), 0)
106+ let userBalance = (currentClientBalance + currentClientBalanceWithFee)
107+ if (if ((amount > userBalance))
108+ then true
109+ else (minUsdn() > amount))
110+ then throw("Swap amount fail, amount is to small or to big.")
111+ else {
112+ let toWithdrawWithoutFee = getWithoutFeeWithdraw(amount, currentClientBalance)
113+ let toWithdrawWithFee = (amount - toWithdrawWithoutFee)
114+ let fee = ((toWithdrawWithFee / 100) * value(getInteger(keyWithdrawFee())))
115+[toWithdrawWithoutFee, toWithdrawWithFee, fee]
116+ }
117+ }
118+
119+
30120 func mustManager (i) = {
31121 let pd = throw("Permission denied")
32122 match managerPublicKeyOrUnit() {
33123 case pk: ByteVector =>
34124 if ((i.callerPublicKey == pk))
35125 then true
36126 else pd
37127 case _: Unit =>
38128 if ((i.caller == this))
39129 then true
40130 else pd
41131 case _ =>
42132 throw("Match error")
43133 }
44134 }
135+
136+
137+@Callable(i)
138+func setWithdrawDelay (newWithdrawDelay) = {
139+ let checkCaller = mustManager(i)
140+ if ((checkCaller == checkCaller))
141+ then [IntegerEntry(keyWithdrawDelay(), newWithdrawDelay)]
142+ else throw("Strict value is not equal to itself.")
143+ }
144+
145+
146+
147+@Callable(i)
148+func setMinimalAmountToSwapUsdt (newMinimalAmount) = {
149+ let checkCaller = mustManager(i)
150+ if ((checkCaller == checkCaller))
151+ then [IntegerEntry(keyMinimalAmountToSwapUsdt(), newMinimalAmount)]
152+ else throw("Strict value is not equal to itself.")
153+ }
154+
155+
156+
157+@Callable(i)
158+func setMinimalAmountToSwapUsdn (newMinimalAmount) = {
159+ let checkCaller = mustManager(i)
160+ if ((checkCaller == checkCaller))
161+ then [IntegerEntry(keyMinimalAmountToSwapUsdn(), newMinimalAmount)]
162+ else throw("Strict value is not equal to itself.")
163+ }
164+
165+
166+
167+@Callable(i)
168+func setWithdrawFee (newFee) = {
169+ let checkCaller = mustManager(i)
170+ if ((checkCaller == checkCaller))
171+ then [IntegerEntry(keyWithdrawFee(), newFee)]
172+ else throw("Strict value is not equal to itself.")
173+ }
174+
175+
176+
177+@Callable(i)
178+func setDepositFee (newFee) = {
179+ let checkCaller = mustManager(i)
180+ if ((checkCaller == checkCaller))
181+ then [IntegerEntry(keyDepositFee(), newFee)]
182+ else throw("Strict value is not equal to itself.")
183+ }
184+
185+
186+
187+@Callable(i)
188+func constructor (usdtAssetId,usdnAssetId) = {
189+ let checkCaller = mustManager(i)
190+ if ((checkCaller == checkCaller))
191+ then [StringEntry(keyUsdtAssetId(), usdtAssetId), StringEntry(keyUsdnAssetId(), usdnAssetId)]
192+ else throw("Strict value is not equal to itself.")
193+ }
194+
195+
196+
197+@Callable(invoke)
198+func swapUSDTtoUSDN () = {
199+ let balanceKey = collectBalanceKeyWithFee(toString(invoke.caller))
200+ let payment = value(invoke.payments[0])
201+ if ((payment.assetId != usdt()))
202+ then usdtToUsdnAssetError()
203+ else {
204+ let amount = payment.amount
205+ let fee = ((amount / 100) * value(getInteger(keyDepositFee())))
206+ let currentClientBalanceUSDT = valueOrElse(getInteger(this, balanceKey), 0)
207+ if ((minUsdt() > amount))
208+ then usdtToUsdnLowLimitError()
209+ else [IntegerEntry(balanceKey, (currentClientBalanceUSDT + amount)), ScriptTransfer(invoke.caller, (amount - fee), usdn())]
210+ }
211+ }
212+
213+
214+
215+@Callable(invoke)
216+func initializationUSDNtoUSDTswap () = {
217+ let payment = value(invoke.payments[0])
218+ let address = toString(invoke.caller)
219+ if ((payment.assetId != usdn()))
220+ then usdnToUsdtAssetError()
221+ else {
222+ let amount = payment.amount
223+ let balanceKey = collectBalanceKey(address)
224+ let balanceWithFeeKey = collectBalanceKeyWithFee(address)
225+ let currentClientBalance = valueOrElse(getInteger(this, balanceKey), 0)
226+ let currentClientBalanceWithFee = valueOrElse(getInteger(this, balanceWithFeeKey), 0)
227+ let userBalance = (currentClientBalance + currentClientBalanceWithFee)
228+ let data = currentWithdrawals(toString(invoke.caller), amount)
229+ let toWithdrawWithoutFee = valueOrErrorMessage(data[0], "Wrong 'currentWithdrawals' method!")
230+ let toWithdrawWithFee = valueOrErrorMessage(data[1], "Wrong 'currentWithdrawals' method!")
231+ let fee = valueOrErrorMessage(data[2], "Wrong 'currentWithdrawals' method!")
232+ let total = ((toWithdrawWithFee + toWithdrawWithoutFee) - fee)
233+ let allowToWithDrawHeight = (height + withdrawDelay())
234+ if (isDefined(getString(this, collectKey(toString(invoke.caller), amount, allowToWithDrawHeight))))
235+ then throw("You have already started withdrawal process, wait next block.")
236+ else [IntegerEntry(balanceKey, (currentClientBalance - toWithdrawWithoutFee)), IntegerEntry(balanceWithFeeKey, (currentClientBalanceWithFee - toWithdrawWithFee)), StringEntry(collectKey(toString(invoke.caller), amount, allowToWithDrawHeight), makeString(["not_withdrawn", toString((amount - fee))], "_"))]
237+ }
238+ }
239+
240+
241+
242+@Callable(invoke)
243+func swapUSDNtoUSDT (amount,heightInKey) = {
244+ let key = collectKey(toString(invoke.caller), amount, heightInKey)
245+ let withdrawnInfo = valueOrErrorMessage(getString(this, key), ((("This key doesn't exists " + key) + " at address ") + toString(this)))
246+ let toWithdraw = getListElementOrDefault(split(withdrawnInfo, "_"), 2, toString(amount))
247+ if (if ((height >= heightInKey))
248+ then contains(withdrawnInfo, "not_withdrawn")
249+ else false)
250+ then [DeleteEntry(key), ScriptTransfer(invoke.caller, valueOrErrorMessage(parseInt(toWithdraw), "Wrong withdraw data!"), usdt())]
251+ else throw((("Withdrawal is possible after " + toString(heightInKey)) + " height or you have already withdrawn USDT."))
252+ }
253+
45254
46255
47256 @Callable(i)
48257 func setManager (pendingManagerPublicKey) = {
49258 let checkCaller = mustManager(i)
50259 if ((checkCaller == checkCaller))
51260 then {
52261 let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey)
53262 if ((checkManagerPublicKey == checkManagerPublicKey))
54263 then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)]
55264 else throw("Strict value is not equal to itself.")
56265 }
57266 else throw("Strict value is not equal to itself.")
58267 }
59268
60269
61270
62271 @Callable(i)
63272 func confirmManager () = {
64273 let pm = pendingManagerPublicKeyOrUnit()
65274 let hasPM = if (isDefined(pm))
66275 then true
67276 else throw("No pending manager")
68277 if ((hasPM == hasPM))
69278 then {
70279 let checkPM = if ((i.callerPublicKey == value(pm)))
71280 then true
72281 else throw("You are not pending manager")
73282 if ((checkPM == checkPM))
74283 then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())]
75284 else throw("Strict value is not equal to itself.")
76285 }
77286 else throw("Strict value is not equal to itself.")
78287 }
79288
80289
81290 @Verifier(tx)
82291 func verify () = {
83292 let targetPublicKey = match managerPublicKeyOrUnit() {
84293 case pk: ByteVector =>
85294 pk
86295 case _: Unit =>
87296 tx.senderPublicKey
88297 case _ =>
89298 throw("Match error")
90299 }
91300 sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
92301 }
93302

github/deemru/w8io/026f985 
38.36 ms