tx · 47dKp2G1rfvCbfPJBhXqCabjJy3e7ee4bbzhCEUSTdmF 3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq: -0.01300000 Waves 2023.02.08 11:04 [2440377] smart account 3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq > SELF 0.00000000 Waves
{ "type": 13, "id": "47dKp2G1rfvCbfPJBhXqCabjJy3e7ee4bbzhCEUSTdmF", "fee": 1300000, "feeAssetId": null, "timestamp": 1675843434176, "version": 1, "sender": "3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq", "senderPublicKey": "2u2wYYcVBQv43Cc71zkhHPPitkqgg6dqTZ3nUMvYJ1uq", "proofs": [ "5wtrQnyZ1YrqtiARjk1mDZ65Xztv72B3a5cDqenMfKzTRCTdddd2VvVY1CfRGArkZUc4pPfxS9DtPG2xT5MA86AU" ], "script": "base64:BgIXCAISBQoDAQgIEgUKAwEICBIDCgEIEgAUAANTRVACAl9fAAhmZWVTY2FsZQkAtgIBAKCNBgEPZ2V0U3RyaW5nT3JGYWlsAQNrZXkJARN2YWx1ZU9yRXJyb3JNZXNzYWdlAgkAnQgCBQR0aGlzBQNrZXkJAKwCAgIVTm8gZGF0YSBmb3IgdGhpcy5rZXk9BQNrZXkADHBvb2xEaXNhYmxlZAkAAgECDVBvb2wgZGlzYWJsZWQADHBvb2xOb3RFeGlzdAkAAgECEVBvb2wgaXMgbm90IGV4aXN0AA5zbGlwcGFnZVRvb0JpZwkAAgECE1NsaXBwYWdlIGlzIHRvbyBiaWcBE2tleU1hbmFnZXJQdWJsaWNLZXkAAhQlc19fbWFuYWdlclB1YmxpY0tleQEaa2V5UGVuZGluZ01hbmFnZXJQdWJsaWNLZXkAAhslc19fcGVuZGluZ01hbmFnZXJQdWJsaWNLZXkBAmZjAAITJXNfX2ZhY3RvcnlDb250cmFjdAAPZmFjdG9yeUNvbnRyYWN0CQERQGV4dHJOYXRpdmUoMTA2MikBCQEPZ2V0U3RyaW5nT3JGYWlsA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JwbQkBHXBlbmRpbmdNYW5hZ2VyUHVibGljS2V5T3JVbml0AAQFaGFzUE0DCQEJaXNEZWZpbmVkAQUCcG0GCQACAQISbm8gcGVuZGluZyBtYW5hZ2VyAwkAAAIFBWhhc1BNBQVoYXNQTQQHY2hlY2tQTQMJAAACCAUBaQ9jYWxsZXJQdWJsaWNLZXkJAQV2YWx1ZQEFAnBtBgkAAgECG3lvdSBhcmUgbm90IHBlbmRpbmcgbWFuYWdlcgMJAAACBQdjaGVja1BNBQdjaGVja1BNCQDMCAIJAQtTdHJpbmdFbnRyeQIJARNrZXlNYW5hZ2VyUHVibGljS2V5AAkA2AQBCQEFdmFsdWUBBQJwbQkAzAgCCQELRGVsZXRlRW50cnkBCQEaa2V5UGVuZGluZ01hbmFnZXJQdWJsaWNLZXkABQNuaWwJAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4JAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4BAnR4AQZ2ZXJpZnkABA90YXJnZXRQdWJsaWNLZXkEByRtYXRjaDAJARZtYW5hZ2VyUHVibGljS2V5T3JVbml0AAMJAAECBQckbWF0Y2gwAgpCeXRlVmVjdG9yBAJwawUHJG1hdGNoMAUCcGsDCQABAgUHJG1hdGNoMAIEVW5pdAgFAnR4D3NlbmRlclB1YmxpY0tleQkAAgECC01hdGNoIGVycm9yCQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAABQ90YXJnZXRQdWJsaWNLZXkU+zT3", "chainId": 84, "height": 2440377, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 33MSPGrFxtMnbcVYSL7zRpjJWGNhAsy8VmSsK22dinba Next: 4t1pmk28DsRaH8KiUAm274kzrrNJSHucKZ3u7KPK3dWF Diff:
Old | New | Differences | |
---|---|---|---|
25 | 25 | ||
26 | 26 | let factoryContract = addressFromStringValue(getStringOrFail(fc())) | |
27 | 27 | ||
28 | - | func | |
28 | + | func feeProtocolContractAddress () = makeString(["%s", "feeProtocolContractAddress"], SEP) | |
29 | 29 | ||
30 | 30 | ||
31 | - | ||
31 | + | let feeContract = addressFromStringValue(getStringOrFail(feeProtocolContractAddress())) | |
32 | 32 | ||
33 | - | ||
34 | - | func protocolFee () = makeString(["%d", "protocolFee"], SEP) | |
33 | + | func protocolFee () = makeString(["%s", "protocolFee"], SEP) | |
35 | 34 | ||
36 | 35 | ||
37 | 36 | func asInt (val) = match val { | |
89 | 88 | func swapCalculateREADONLY (amountIn,assetIn,assetOut) = { | |
90 | 89 | let prFee = value(getInteger(protocolFee())) | |
91 | 90 | let feeProtocolAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale) | |
92 | - | let | |
93 | - | | |
94 | - | | |
91 | + | let cleanAmountIn = if ((toInt(feeProtocolAmount) == 0)) | |
92 | + | then toBigInt(1) | |
93 | + | else (toBigInt(amountIn) - feeProtocolAmount) | |
95 | 94 | let lpNonReverese = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil) | |
96 | 95 | let lpReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil) | |
97 | - | let $ | |
96 | + | let $t025613066 = if ((lpNonReverese != unit)) | |
98 | 97 | then { | |
99 | 98 | let isReverse = false | |
100 | 99 | let pool = { | |
117 | 116 | $Tuple2(isReverse, pool) | |
118 | 117 | } | |
119 | 118 | else poolNotExist | |
120 | - | let isReverse = $ | |
121 | - | let pool = $ | |
119 | + | let isReverse = $t025613066._1 | |
120 | + | let pool = $t025613066._2 | |
122 | 121 | let poolStatus = { | |
123 | 122 | let @ = invoke(factoryContract, "getPoolStatusREADONLY", [pool], nil) | |
124 | 123 | if ($isInstanceOf(@, "Int")) | |
153 | 152 | let amountIn = value(pmt.amount) | |
154 | 153 | let prFee = value(getInteger(protocolFee())) | |
155 | 154 | let feeProtocolAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale) | |
156 | - | let feeLiquidityAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale) | |
157 | - | let amountInToPool = (toBigInt(amountIn) - feeProtocolAmount) | |
158 | - | let cleanAmountIn = (amountInToPool - feeLiquidityAmount) | |
155 | + | let cleanAmountIn = (toBigInt(amountIn) - feeProtocolAmount) | |
159 | 156 | let checks = [if ((size(i.payments) == 1)) | |
160 | 157 | then true | |
161 | 158 | else throw("exactly 1 payment are expected")] | |
163 | 160 | then { | |
164 | 161 | let lpNonReverese = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil) | |
165 | 162 | let lpReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil) | |
166 | - | let $ | |
163 | + | let $t042474737 = if ((lpNonReverese != unit)) | |
167 | 164 | then { | |
168 | 165 | let isReverse = false | |
169 | 166 | let pool = { | |
181 | 178 | $Tuple2(isReverse, pool) | |
182 | 179 | } | |
183 | 180 | else poolNotExist | |
184 | - | let isReverse = $ | |
185 | - | let pool = $ | |
181 | + | let isReverse = $t042474737._1 | |
182 | + | let pool = $t042474737._2 | |
186 | 183 | let isPoolOneTokenOperationsDisabled = { | |
187 | 184 | let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [pool], nil) | |
188 | 185 | if ($isInstanceOf(@, "Boolean")) | |
196 | 193 | then { | |
197 | 194 | let poolAdr = addressFromStringValue(valueOrElse(pool, "")) | |
198 | 195 | let res = { | |
199 | - | let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, addressTo], [AttachedPayment(assetIn, toInt( | |
196 | + | let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, addressTo], [AttachedPayment(assetIn, toInt(cleanAmountIn))]) | |
200 | 197 | if ($isInstanceOf(@, "Boolean")) | |
201 | 198 | then @ | |
202 | 199 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
203 | 200 | } | |
204 | - | $Tuple2( | |
201 | + | $Tuple2([ScriptTransfer(feeContract, toInt(feeProtocolAmount), assetIn)], res) | |
205 | 202 | } | |
206 | 203 | else throw("Strict value is not equal to itself.") | |
207 | 204 | } |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let SEP = "__" | |
5 | 5 | ||
6 | 6 | let feeScale = toBigInt(100000) | |
7 | 7 | ||
8 | 8 | func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), ("No data for this.key=" + key)) | |
9 | 9 | ||
10 | 10 | ||
11 | 11 | let poolDisabled = throw("Pool disabled") | |
12 | 12 | ||
13 | 13 | let poolNotExist = throw("Pool is not exist") | |
14 | 14 | ||
15 | 15 | let slippageTooBig = throw("Slippage is too big") | |
16 | 16 | ||
17 | 17 | func keyManagerPublicKey () = "%s__managerPublicKey" | |
18 | 18 | ||
19 | 19 | ||
20 | 20 | func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey" | |
21 | 21 | ||
22 | 22 | ||
23 | 23 | func fc () = "%s__factoryContract" | |
24 | 24 | ||
25 | 25 | ||
26 | 26 | let factoryContract = addressFromStringValue(getStringOrFail(fc())) | |
27 | 27 | ||
28 | - | func | |
28 | + | func feeProtocolContractAddress () = makeString(["%s", "feeProtocolContractAddress"], SEP) | |
29 | 29 | ||
30 | 30 | ||
31 | - | ||
31 | + | let feeContract = addressFromStringValue(getStringOrFail(feeProtocolContractAddress())) | |
32 | 32 | ||
33 | - | ||
34 | - | func protocolFee () = makeString(["%d", "protocolFee"], SEP) | |
33 | + | func protocolFee () = makeString(["%s", "protocolFee"], SEP) | |
35 | 34 | ||
36 | 35 | ||
37 | 36 | func asInt (val) = match val { | |
38 | 37 | case valInt: Int => | |
39 | 38 | valInt | |
40 | 39 | case _ => | |
41 | 40 | throw("fail to cast into Int") | |
42 | 41 | } | |
43 | 42 | ||
44 | 43 | ||
45 | 44 | func dataMappingPoolAssets (internalAmountAssetStr,internalPriceAssetStr) = makeString(["%d%d", toString(internalAmountAssetStr), toString(internalPriceAssetStr)], SEP) | |
46 | 45 | ||
47 | 46 | ||
48 | 47 | func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) { | |
49 | 48 | case s: String => | |
50 | 49 | fromBase58String(s) | |
51 | 50 | case _: Unit => | |
52 | 51 | unit | |
53 | 52 | case _ => | |
54 | 53 | throw("Match error") | |
55 | 54 | } | |
56 | 55 | ||
57 | 56 | ||
58 | 57 | func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) { | |
59 | 58 | case s: String => | |
60 | 59 | fromBase58String(s) | |
61 | 60 | case _: Unit => | |
62 | 61 | unit | |
63 | 62 | case _ => | |
64 | 63 | throw("Match error") | |
65 | 64 | } | |
66 | 65 | ||
67 | 66 | ||
68 | 67 | func isManager (i) = match managerPublicKeyOrUnit() { | |
69 | 68 | case pk: ByteVector => | |
70 | 69 | (i.callerPublicKey == pk) | |
71 | 70 | case _: Unit => | |
72 | 71 | (i.caller == this) | |
73 | 72 | case _ => | |
74 | 73 | throw("Match error") | |
75 | 74 | } | |
76 | 75 | ||
77 | 76 | ||
78 | 77 | func mustManager (i) = if (isManager(i)) | |
79 | 78 | then true | |
80 | 79 | else throw("permission denied") | |
81 | 80 | ||
82 | 81 | ||
83 | 82 | func getAccBalance (assetId) = if ((assetId == "WAVES")) | |
84 | 83 | then wavesBalance(this).available | |
85 | 84 | else assetBalance(this, fromBase58String(assetId)) | |
86 | 85 | ||
87 | 86 | ||
88 | 87 | @Callable(i) | |
89 | 88 | func swapCalculateREADONLY (amountIn,assetIn,assetOut) = { | |
90 | 89 | let prFee = value(getInteger(protocolFee())) | |
91 | 90 | let feeProtocolAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale) | |
92 | - | let | |
93 | - | | |
94 | - | | |
91 | + | let cleanAmountIn = if ((toInt(feeProtocolAmount) == 0)) | |
92 | + | then toBigInt(1) | |
93 | + | else (toBigInt(amountIn) - feeProtocolAmount) | |
95 | 94 | let lpNonReverese = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil) | |
96 | 95 | let lpReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil) | |
97 | - | let $ | |
96 | + | let $t025613066 = if ((lpNonReverese != unit)) | |
98 | 97 | then { | |
99 | 98 | let isReverse = false | |
100 | 99 | let pool = { | |
101 | 100 | let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpNonReverese], nil) | |
102 | 101 | if ($isInstanceOf(@, "String")) | |
103 | 102 | then @ | |
104 | 103 | else throw(($getType(@) + " couldn't be cast to String")) | |
105 | 104 | } | |
106 | 105 | $Tuple2(isReverse, pool) | |
107 | 106 | } | |
108 | 107 | else if ((lpReverse != unit)) | |
109 | 108 | then { | |
110 | 109 | let isReverse = true | |
111 | 110 | let pool = { | |
112 | 111 | let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpReverse], nil) | |
113 | 112 | if ($isInstanceOf(@, "String")) | |
114 | 113 | then @ | |
115 | 114 | else throw(($getType(@) + " couldn't be cast to String")) | |
116 | 115 | } | |
117 | 116 | $Tuple2(isReverse, pool) | |
118 | 117 | } | |
119 | 118 | else poolNotExist | |
120 | - | let isReverse = $ | |
121 | - | let pool = $ | |
119 | + | let isReverse = $t025613066._1 | |
120 | + | let pool = $t025613066._2 | |
122 | 121 | let poolStatus = { | |
123 | 122 | let @ = invoke(factoryContract, "getPoolStatusREADONLY", [pool], nil) | |
124 | 123 | if ($isInstanceOf(@, "Int")) | |
125 | 124 | then @ | |
126 | 125 | else throw(($getType(@) + " couldn't be cast to Int")) | |
127 | 126 | } | |
128 | 127 | let check = if ((poolStatus == 1)) | |
129 | 128 | then true | |
130 | 129 | else poolDisabled | |
131 | 130 | if ((check == check)) | |
132 | 131 | then { | |
133 | 132 | let poolAdr = addressFromStringValue(valueOrElse(pool, "")) | |
134 | 133 | let res = { | |
135 | 134 | let @ = invoke(poolAdr, "calculateAmountOutForSwapREADONLY", [toInt(cleanAmountIn), isReverse], nil) | |
136 | 135 | if ($isInstanceOf(@, "Int")) | |
137 | 136 | then @ | |
138 | 137 | else throw(($getType(@) + " couldn't be cast to Int")) | |
139 | 138 | } | |
140 | 139 | $Tuple2(nil, res) | |
141 | 140 | } | |
142 | 141 | else throw("Strict value is not equal to itself.") | |
143 | 142 | } | |
144 | 143 | ||
145 | 144 | ||
146 | 145 | ||
147 | 146 | @Callable(i) | |
148 | 147 | func swap (amountOutMin,assetOut,addressTo) = { | |
149 | 148 | let pmt = value(i.payments[0]) | |
150 | 149 | let assetIn = if ((pmt.assetId == unit)) | |
151 | 150 | then toBytes("WAVES") | |
152 | 151 | else value(pmt.assetId) | |
153 | 152 | let amountIn = value(pmt.amount) | |
154 | 153 | let prFee = value(getInteger(protocolFee())) | |
155 | 154 | let feeProtocolAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale) | |
156 | - | let feeLiquidityAmount = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale) | |
157 | - | let amountInToPool = (toBigInt(amountIn) - feeProtocolAmount) | |
158 | - | let cleanAmountIn = (amountInToPool - feeLiquidityAmount) | |
155 | + | let cleanAmountIn = (toBigInt(amountIn) - feeProtocolAmount) | |
159 | 156 | let checks = [if ((size(i.payments) == 1)) | |
160 | 157 | then true | |
161 | 158 | else throw("exactly 1 payment are expected")] | |
162 | 159 | if ((checks == checks)) | |
163 | 160 | then { | |
164 | 161 | let lpNonReverese = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil) | |
165 | 162 | let lpReverse = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil) | |
166 | - | let $ | |
163 | + | let $t042474737 = if ((lpNonReverese != unit)) | |
167 | 164 | then { | |
168 | 165 | let isReverse = false | |
169 | 166 | let pool = { | |
170 | 167 | let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpNonReverese], nil) | |
171 | 168 | if ($isInstanceOf(@, "Address")) | |
172 | 169 | then @ | |
173 | 170 | else throw(($getType(@) + " couldn't be cast to Address")) | |
174 | 171 | } | |
175 | 172 | $Tuple2(isReverse, pool) | |
176 | 173 | } | |
177 | 174 | else if ((lpReverse != unit)) | |
178 | 175 | then { | |
179 | 176 | let isReverse = true | |
180 | 177 | let pool = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [lpReverse], nil) | |
181 | 178 | $Tuple2(isReverse, pool) | |
182 | 179 | } | |
183 | 180 | else poolNotExist | |
184 | - | let isReverse = $ | |
185 | - | let pool = $ | |
181 | + | let isReverse = $t042474737._1 | |
182 | + | let pool = $t042474737._2 | |
186 | 183 | let isPoolOneTokenOperationsDisabled = { | |
187 | 184 | let @ = invoke(factoryContract, "isPoolOneTokenOperationsDisabledREADONLY", [pool], nil) | |
188 | 185 | if ($isInstanceOf(@, "Boolean")) | |
189 | 186 | then @ | |
190 | 187 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
191 | 188 | } | |
192 | 189 | let check = if (isPoolOneTokenOperationsDisabled) | |
193 | 190 | then true | |
194 | 191 | else poolDisabled | |
195 | 192 | if ((check == check)) | |
196 | 193 | then { | |
197 | 194 | let poolAdr = addressFromStringValue(valueOrElse(pool, "")) | |
198 | 195 | let res = { | |
199 | - | let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, addressTo], [AttachedPayment(assetIn, toInt( | |
196 | + | let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, addressTo], [AttachedPayment(assetIn, toInt(cleanAmountIn))]) | |
200 | 197 | if ($isInstanceOf(@, "Boolean")) | |
201 | 198 | then @ | |
202 | 199 | else throw(($getType(@) + " couldn't be cast to Boolean")) | |
203 | 200 | } | |
204 | - | $Tuple2( | |
201 | + | $Tuple2([ScriptTransfer(feeContract, toInt(feeProtocolAmount), assetIn)], res) | |
205 | 202 | } | |
206 | 203 | else throw("Strict value is not equal to itself.") | |
207 | 204 | } | |
208 | 205 | else throw("Strict value is not equal to itself.") | |
209 | 206 | } | |
210 | 207 | ||
211 | 208 | ||
212 | 209 | ||
213 | 210 | @Callable(i) | |
214 | 211 | func setManager (pendingManagerPublicKey) = { | |
215 | 212 | let checkCaller = mustManager(i) | |
216 | 213 | if ((checkCaller == checkCaller)) | |
217 | 214 | then { | |
218 | 215 | let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey) | |
219 | 216 | if ((checkManagerPublicKey == checkManagerPublicKey)) | |
220 | 217 | then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)] | |
221 | 218 | else throw("Strict value is not equal to itself.") | |
222 | 219 | } | |
223 | 220 | else throw("Strict value is not equal to itself.") | |
224 | 221 | } | |
225 | 222 | ||
226 | 223 | ||
227 | 224 | ||
228 | 225 | @Callable(i) | |
229 | 226 | func confirmManager () = { | |
230 | 227 | let pm = pendingManagerPublicKeyOrUnit() | |
231 | 228 | let hasPM = if (isDefined(pm)) | |
232 | 229 | then true | |
233 | 230 | else throw("no pending manager") | |
234 | 231 | if ((hasPM == hasPM)) | |
235 | 232 | then { | |
236 | 233 | let checkPM = if ((i.callerPublicKey == value(pm))) | |
237 | 234 | then true | |
238 | 235 | else throw("you are not pending manager") | |
239 | 236 | if ((checkPM == checkPM)) | |
240 | 237 | then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())] | |
241 | 238 | else throw("Strict value is not equal to itself.") | |
242 | 239 | } | |
243 | 240 | else throw("Strict value is not equal to itself.") | |
244 | 241 | } | |
245 | 242 | ||
246 | 243 | ||
247 | 244 | @Verifier(tx) | |
248 | 245 | func verify () = { | |
249 | 246 | let targetPublicKey = match managerPublicKeyOrUnit() { | |
250 | 247 | case pk: ByteVector => | |
251 | 248 | pk | |
252 | 249 | case _: Unit => | |
253 | 250 | tx.senderPublicKey | |
254 | 251 | case _ => | |
255 | 252 | throw("Match error") | |
256 | 253 | } | |
257 | 254 | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
258 | 255 | } | |
259 | 256 |
github/deemru/w8io/026f985 95.88 ms ◑