@stellar-expert/tx-meta-effects-parser 8.0.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +10 -8
- package/package.json +1 -1
- package/src/effects-analyzer.js +16 -29
- package/src/index.js +3 -0
- package/src/parser/tx-xdr-parser-utils.js +36 -2
package/README.MD
CHANGED
|
@@ -108,7 +108,8 @@ parseTxOperationsMeta({
|
|
|
108
108
|
source: 'GBKP…YDLI',
|
|
109
109
|
asset: 'XLM',
|
|
110
110
|
bid: '10000',
|
|
111
|
-
charged: '100'
|
|
111
|
+
charged: '100',
|
|
112
|
+
balance: '99999999900'
|
|
112
113
|
}
|
|
113
114
|
```
|
|
114
115
|
</td>
|
|
@@ -152,7 +153,7 @@ parseTxOperationsMeta({
|
|
|
152
153
|
<sub><code>accountDebited</code></sub>
|
|
153
154
|
</td>
|
|
154
155
|
<td><sub>CreateAccountOp, AccountMergeOp, PaymentOp, PathPaymentStrictReceiveOp,
|
|
155
|
-
PathPaymentStrictSendOp, CreateClaimableBalanceOp, ClawbackOp</sub></td>
|
|
156
|
+
PathPaymentStrictSendOp, CreateClaimableBalanceOp, ClawbackOp, InvokeHostFunctionOp</sub></td>
|
|
156
157
|
<td>
|
|
157
158
|
|
|
158
159
|
```js
|
|
@@ -160,7 +161,8 @@ PathPaymentStrictSendOp, CreateClaimableBalanceOp, ClawbackOp</sub></td>
|
|
|
160
161
|
type: 'accountDebited',
|
|
161
162
|
source: 'GBKP…YDLI',
|
|
162
163
|
asset: 'XLM',
|
|
163
|
-
amount: '1000000000'
|
|
164
|
+
amount: '1000000000',
|
|
165
|
+
balance: '199999999900'
|
|
164
166
|
}
|
|
165
167
|
```
|
|
166
168
|
</td>
|
|
@@ -172,7 +174,7 @@ PathPaymentStrictSendOp, CreateClaimableBalanceOp, ClawbackOp</sub></td>
|
|
|
172
174
|
</td>
|
|
173
175
|
<td><sub>CreateAccountOp, AccountMergeOp, PaymentOp, PathPaymentStrictReceiveOp,
|
|
174
176
|
PathPaymentStrictSendOp, ClaimClaimableBalanceOp, ClawbackOp,
|
|
175
|
-
ClawbackClaimableBalance, InflationOp</sub></td>
|
|
177
|
+
ClawbackClaimableBalance, InflationOp, InvokeHostFunctionOp</sub></td>
|
|
176
178
|
<td>
|
|
177
179
|
|
|
178
180
|
```js
|
|
@@ -180,7 +182,8 @@ ClawbackClaimableBalance, InflationOp</sub></td>
|
|
|
180
182
|
type: 'accountCredited',
|
|
181
183
|
source: 'GBWC…DXHN',
|
|
182
184
|
asset: 'XLM',
|
|
183
|
-
amount: '1000000000'
|
|
185
|
+
amount: '1000000000',
|
|
186
|
+
balance: '299999999900'
|
|
184
187
|
}
|
|
185
188
|
```
|
|
186
189
|
</td>
|
|
@@ -412,7 +415,7 @@ ClawbackClaimableBalance, InflationOp</sub></td>
|
|
|
412
415
|
<sub><code>assetMinted</code></sub>
|
|
413
416
|
</td>
|
|
414
417
|
<td><sub>PaymentOp, PathPaymentStrictReceiveOp, PathPaymentStrictSendOp, CreateClaimableBalanceOp,
|
|
415
|
-
ManageBuyOfferOp, ManageSellOfferOp, CreatePassiveOfferOp, DepositLiquidityOp</sub></td>
|
|
418
|
+
ManageBuyOfferOp, ManageSellOfferOp, CreatePassiveOfferOp, DepositLiquidityOp, InvokeHostFunctionOp</sub></td>
|
|
416
419
|
<td>
|
|
417
420
|
|
|
418
421
|
```js
|
|
@@ -432,8 +435,7 @@ ManageBuyOfferOp, ManageSellOfferOp, CreatePassiveOfferOp, DepositLiquidityOp</s
|
|
|
432
435
|
<sub><code>assetBurned</code></sub>
|
|
433
436
|
</td>
|
|
434
437
|
<td><sub>PaymentOp, PathPaymentStrictReceiveOp, PathPaymentStrictSendOp, CreateClaimableBalanceOp, ManageBuyOfferOp, ManageSellOfferOp,
|
|
435
|
-
CreatePassiveOfferOp, WithdrawLiquidityOp, ClawbackOp,
|
|
436
|
-
ClaimClaimableBalanceOp</sub></td>
|
|
438
|
+
CreatePassiveOfferOp, WithdrawLiquidityOp, ClawbackOp, ClaimClaimableBalanceOp, InvokeHostFunctionOp</sub></td>
|
|
437
439
|
<td>
|
|
438
440
|
|
|
439
441
|
```js
|
package/package.json
CHANGED
package/src/effects-analyzer.js
CHANGED
|
@@ -2,7 +2,13 @@ const {StrKey, hash, xdr, nativeToScVal} = require('@stellar/stellar-base')
|
|
|
2
2
|
const effectTypes = require('./effect-types')
|
|
3
3
|
const {validateAmount, normalizeAddress, parseLargeInt} = require('./parser/normalization')
|
|
4
4
|
const {parseLedgerEntryChanges} = require('./parser/ledger-entry-changes-parser')
|
|
5
|
-
const {
|
|
5
|
+
const {
|
|
6
|
+
xdrParseAsset,
|
|
7
|
+
xdrParseAccountAddress,
|
|
8
|
+
xdrParseScVal,
|
|
9
|
+
xdrParseSacBalance,
|
|
10
|
+
xdrParseTokenBalance
|
|
11
|
+
} = require('./parser/tx-xdr-parser-utils')
|
|
6
12
|
const {contractIdFromPreimage} = require('./parser/contract-preimage-encoder')
|
|
7
13
|
const {generateContractCodeEntryHash} = require('./parser/ledger-key')
|
|
8
14
|
const {analyzeSignerChanges} = require('./aggregation/signer-changes-analyzer')
|
|
@@ -803,33 +809,6 @@ class EffectsAnalyzer {
|
|
|
803
809
|
this.addEffect(effect)
|
|
804
810
|
}
|
|
805
811
|
|
|
806
|
-
processContractBalance(effect) {
|
|
807
|
-
const parsedKey = xdr.ScVal.fromXDR(effect.key, 'base64')
|
|
808
|
-
if (parsedKey._arm !== 'vec')
|
|
809
|
-
return
|
|
810
|
-
const keyParts = parsedKey._value
|
|
811
|
-
if (!(keyParts instanceof Array) || keyParts.length !== 2)
|
|
812
|
-
return
|
|
813
|
-
if (keyParts[0]._arm !== 'sym' || keyParts[1]._arm !== 'address' || keyParts[0]._value.toString() !== 'Balance')
|
|
814
|
-
return
|
|
815
|
-
const account = xdrParseScVal(keyParts[1])
|
|
816
|
-
const balanceEffects = this.effects.filter(e => (e.type === effectTypes.accountCredited || e.type === effectTypes.accountDebited) && e.source === account && e.asset === effect.owner)
|
|
817
|
-
if (balanceEffects.length !== 1) //we can set balance only when we found 1-1 mapping, if there are several balance changes, we can't establish balance relation
|
|
818
|
-
return
|
|
819
|
-
if (effect.type === effectTypes.contractDataRemoved) { //balance completely removed - this may be a reversible operation if the balance simply expired
|
|
820
|
-
balanceEffects[0].balance = '0'
|
|
821
|
-
return
|
|
822
|
-
}
|
|
823
|
-
const value = xdr.ScVal.fromXDR(effect.value, 'base64')
|
|
824
|
-
if (value._arm !== 'map')
|
|
825
|
-
return
|
|
826
|
-
const parsedValue = xdrParseScVal(value)
|
|
827
|
-
if (typeof parsedValue.clawback !== 'boolean' || typeof parsedValue.authorized !== 'boolean' || typeof parsedValue.amount !== 'string')
|
|
828
|
-
return
|
|
829
|
-
//set transfer effect balance
|
|
830
|
-
balanceEffects[0].balance = parsedValue.amount
|
|
831
|
-
}
|
|
832
|
-
|
|
833
812
|
processContractChanges({action, before, after}) {
|
|
834
813
|
const {kind, owner: contract, keyHash} = after
|
|
835
814
|
let effect = {
|
|
@@ -906,7 +885,15 @@ class EffectsAnalyzer {
|
|
|
906
885
|
break
|
|
907
886
|
}
|
|
908
887
|
this.addEffect(effect)
|
|
909
|
-
|
|
888
|
+
const tokenBalance = xdrParseTokenBalance(effect)
|
|
889
|
+
if (tokenBalance) {
|
|
890
|
+
const balanceEffects = this.effects.filter(e => e.source === tokenBalance.address &&
|
|
891
|
+
(e.type === effectTypes.accountCredited || e.type === effectTypes.accountDebited) &&
|
|
892
|
+
(e.asset === effect.owner || e.asset === this.sacMap?.get(effect.owner)))
|
|
893
|
+
if (balanceEffects.length !== 1)
|
|
894
|
+
return //we can set balance only when we found 1-1 mapping, if there are several balance changes, we can't establish balance relation
|
|
895
|
+
balanceEffects[0].balance = tokenBalance.balance //set transfer effect balance
|
|
896
|
+
}
|
|
910
897
|
}
|
|
911
898
|
|
|
912
899
|
processContractCodeChanges({type, action, before, after}) {
|
package/src/index.js
CHANGED
|
@@ -129,6 +129,9 @@ function parseTxOperationsMeta({
|
|
|
129
129
|
effect.source = (before || after).address
|
|
130
130
|
res.effects.push(effect)
|
|
131
131
|
}
|
|
132
|
+
if (feeEffect.source === after.address) {
|
|
133
|
+
feeEffect.balance = after.balance
|
|
134
|
+
}
|
|
132
135
|
if (isFeeBump && protocol === 20 && before.balance !== after.balance) { //bump fee calculation bug in protocol v20
|
|
133
136
|
const currentFee = BigInt(feeEffect.charged)
|
|
134
137
|
const diff = BigInt(after.balance) - BigInt(before.balance)
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {
|
|
2
|
+
xdr,
|
|
3
|
+
StrKey,
|
|
4
|
+
LiquidityPoolId,
|
|
5
|
+
scValToBigInt,
|
|
6
|
+
encodeMuxedAccount,
|
|
7
|
+
encodeMuxedAccountToAddress
|
|
8
|
+
} = require('@stellar/stellar-base')
|
|
2
9
|
const {TxMetaEffectParserError} = require('../errors')
|
|
10
|
+
const effectTypes = require('../effect-types')
|
|
3
11
|
|
|
4
12
|
/**
|
|
5
13
|
* Parse account address from XDR representation
|
|
@@ -285,6 +293,31 @@ function xdrParseScVal(value, treatBytesAsContractId = false) {
|
|
|
285
293
|
}
|
|
286
294
|
}
|
|
287
295
|
|
|
296
|
+
function xdrParseTokenBalance({type, key, value}) {
|
|
297
|
+
const parsedKey = xdr.ScVal.fromXDR(key, 'base64')
|
|
298
|
+
if (parsedKey._arm !== 'vec')
|
|
299
|
+
return null
|
|
300
|
+
const keyParts = parsedKey._value
|
|
301
|
+
if (!(keyParts instanceof Array) || keyParts.length !== 2)
|
|
302
|
+
return null
|
|
303
|
+
if (keyParts[0]._arm !== 'sym' || keyParts[1]._arm !== 'address' || keyParts[0]._value.toString() !== 'Balance')
|
|
304
|
+
return null
|
|
305
|
+
let balance = '0'
|
|
306
|
+
if (type !== effectTypes.contractDataRemoved) { //TODO: handle evicted entries separately
|
|
307
|
+
const xdrVal = xdr.ScVal.fromXDR(value, 'base64')
|
|
308
|
+
if (xdrVal._arm !== 'map')
|
|
309
|
+
return null
|
|
310
|
+
const parsedValue = xdrParseScVal(xdrVal)
|
|
311
|
+
if (typeof parsedValue.amount !== 'string')
|
|
312
|
+
return null
|
|
313
|
+
balance = parsedValue.amount
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
address: xdrParseScVal(keyParts[1]),
|
|
317
|
+
balance
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
288
321
|
module.exports = {
|
|
289
322
|
xdrParseAsset,
|
|
290
323
|
xdrParseAccountAddress,
|
|
@@ -295,5 +328,6 @@ module.exports = {
|
|
|
295
328
|
xdrParseTradeAtom,
|
|
296
329
|
xdrParseSignerKey,
|
|
297
330
|
xdrParsePrice,
|
|
298
|
-
xdrParseScVal
|
|
331
|
+
xdrParseScVal,
|
|
332
|
+
xdrParseTokenBalance
|
|
299
333
|
}
|