tx · 7cWZP3KNhs3MRv6wshu5PyQqnqZ1EyNatNY5hbh8Ywwj

3P54B92RNzMrgqPmKhsqL413NjAGwf4q9ep:  -0.01300000 Waves

2022.10.06 15:29 [3325946] smart account 3P54B92RNzMrgqPmKhsqL413NjAGwf4q9ep > SELF 0.00000000 Waves

{ "type": 13, "id": "7cWZP3KNhs3MRv6wshu5PyQqnqZ1EyNatNY5hbh8Ywwj", "fee": 1300000, "feeAssetId": null, "timestamp": 1665058895712, "version": 1, "sender": "3P54B92RNzMrgqPmKhsqL413NjAGwf4q9ep", "senderPublicKey": "MuJFxUBAQVpXXraxYbYJEzWYG8NukYhQEQFm7CaZLcT", "proofs": [ "5h7CetKSYyqTZut8fMN71uEf7gqhTJE43PU6tWw2Hisw6d1t5v92TcENDb1qqc3wh9hxKu8WT11jymC5exaQL9H5" ], "script": "base64:AAIFAAAAAAAAAAkIAhIDCgEIEgAAAAAFAQAAABNrZXlNYW5hZ2VyUHVibGljS2V5AAAAAAIAAAAUJXNfX21hbmFnZXJQdWJsaWNLZXkBAAAAGmtleVBlbmRpbmdNYW5hZ2VyUHVibGljS2V5AAAAAAIAAAAbJXNfX3BlbmRpbmdNYW5hZ2VyUHVibGljS2V5AQAAABZtYW5hZ2VyUHVibGljS2V5T3JVbml0AAAAAAQAAAAHJG1hdGNoMAkABCIAAAABCQEAAAATa2V5TWFuYWdlclB1YmxpY0tleQAAAAADCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABcwUAAAAHJG1hdGNoMAkAAlkAAAABBQAAAAFzAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAARVbml0BQAAAAR1bml0CQAAAgAAAAECAAAAC01hdGNoIGVycm9yAQAAAB1wZW5kaW5nTWFuYWdlclB1YmxpY0tleU9yVW5pdAAAAAAEAAAAByRtYXRjaDAJAAQiAAAAAQkBAAAAGmtleVBlbmRpbmdNYW5hZ2VyUHVibGljS2V5AAAAAAMJAAABAAAAAgUAAAAHJG1hdG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AAAAIFAAAAByRtYXRjaDACAAAABFVuaXQIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXkJAAACAAAAAQIAAAALTWF0Y2ggZXJyb3IJAAH0AAAAAwgFAAAAAnR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAACdHgAAAAGcHJvb2ZzAAAAAAAAAAAABQAAAA90YXJnZXRQdWJsaWNLZXmq8YBh", "chainId": 87, "height": 3325946, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: Bp5D7z8bYF8hh5NtFx2eTMTtnHid5ZckhToRtJt4aNoo Next: EcPs2LmtdHdsZ1S5f4f1iVXGDHvZmVvePp3tGqeJuYzd Diff:
OldNewDifferences
1-{-# STDLIB_VERSION 6 #-}
1+{-# STDLIB_VERSION 5 #-}
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-
264 func keyManagerPublicKey () = "%s__managerPublicKey"
275
286
297 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())))
488
499
5010 func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) {
6727 }
6828
6929
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-
12030 func mustManager (i) = {
12131 let pd = throw("Permission denied")
12232 match managerPublicKeyOrUnit() {
13242 throw("Match error")
13343 }
13444 }
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-
25445
25546
25647 @Callable(i)
Full:
OldNewDifferences
1-{-# STDLIB_VERSION 6 #-}
1+{-# STDLIB_VERSION 5 #-}
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-
264 func keyManagerPublicKey () = "%s__managerPublicKey"
275
286
297 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())))
488
499
5010 func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) {
5111 case s: String =>
5212 fromBase58String(s)
5313 case _: Unit =>
5414 unit
5515 case _ =>
5616 throw("Match error")
5717 }
5818
5919
6020 func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) {
6121 case s: String =>
6222 fromBase58String(s)
6323 case _: Unit =>
6424 unit
6525 case _ =>
6626 throw("Match error")
6727 }
6828
6929
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-
12030 func mustManager (i) = {
12131 let pd = throw("Permission denied")
12232 match managerPublicKeyOrUnit() {
12333 case pk: ByteVector =>
12434 if ((i.callerPublicKey == pk))
12535 then true
12636 else pd
12737 case _: Unit =>
12838 if ((i.caller == this))
12939 then true
13040 else pd
13141 case _ =>
13242 throw("Match error")
13343 }
13444 }
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-
25445
25546
25647 @Callable(i)
25748 func setManager (pendingManagerPublicKey) = {
25849 let checkCaller = mustManager(i)
25950 if ((checkCaller == checkCaller))
26051 then {
26152 let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey)
26253 if ((checkManagerPublicKey == checkManagerPublicKey))
26354 then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)]
26455 else throw("Strict value is not equal to itself.")
26556 }
26657 else throw("Strict value is not equal to itself.")
26758 }
26859
26960
27061
27162 @Callable(i)
27263 func confirmManager () = {
27364 let pm = pendingManagerPublicKeyOrUnit()
27465 let hasPM = if (isDefined(pm))
27566 then true
27667 else throw("No pending manager")
27768 if ((hasPM == hasPM))
27869 then {
27970 let checkPM = if ((i.callerPublicKey == value(pm)))
28071 then true
28172 else throw("You are not pending manager")
28273 if ((checkPM == checkPM))
28374 then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())]
28475 else throw("Strict value is not equal to itself.")
28576 }
28677 else throw("Strict value is not equal to itself.")
28778 }
28879
28980
29081 @Verifier(tx)
29182 func verify () = {
29283 let targetPublicKey = match managerPublicKeyOrUnit() {
29384 case pk: ByteVector =>
29485 pk
29586 case _: Unit =>
29687 tx.senderPublicKey
29788 case _ =>
29889 throw("Match error")
29990 }
30091 sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
30192 }
30293

github/deemru/w8io/3ef1775 
35.72 ms