@stellar-expert/tx-meta-effects-parser 8.0.0 → 8.2.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 +13 -29
- package/src/index.js +3 -0
- package/src/parser/tx-xdr-parser-utils.js +41 -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,12 @@ 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
|
+
xdrParseSacBalanceChange
|
|
10
|
+
} = require('./parser/tx-xdr-parser-utils')
|
|
6
11
|
const {contractIdFromPreimage} = require('./parser/contract-preimage-encoder')
|
|
7
12
|
const {generateContractCodeEntryHash} = require('./parser/ledger-key')
|
|
8
13
|
const {analyzeSignerChanges} = require('./aggregation/signer-changes-analyzer')
|
|
@@ -803,33 +808,6 @@ class EffectsAnalyzer {
|
|
|
803
808
|
this.addEffect(effect)
|
|
804
809
|
}
|
|
805
810
|
|
|
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
811
|
processContractChanges({action, before, after}) {
|
|
834
812
|
const {kind, owner: contract, keyHash} = after
|
|
835
813
|
let effect = {
|
|
@@ -906,7 +884,13 @@ class EffectsAnalyzer {
|
|
|
906
884
|
break
|
|
907
885
|
}
|
|
908
886
|
this.addEffect(effect)
|
|
909
|
-
|
|
887
|
+
const tokenBalance = xdrParseSacBalanceChange(effect.type, key, after?.value, before?.value)
|
|
888
|
+
if (tokenBalance) {
|
|
889
|
+
const balanceEffects = this.effects.filter(e => e.source === tokenBalance.address &&
|
|
890
|
+
(e.type === effectTypes.accountCredited || e.type === effectTypes.accountDebited) &&
|
|
891
|
+
(e.asset === effect.owner || e.asset === this.sacMap?.get(effect.owner)))
|
|
892
|
+
balanceEffects[balanceEffects.length - 1].balance = tokenBalance.balance //set latest transfer effect balance
|
|
893
|
+
}
|
|
910
894
|
}
|
|
911
895
|
|
|
912
896
|
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,36 @@ function xdrParseScVal(value, treatBytesAsContractId = false) {
|
|
|
285
293
|
}
|
|
286
294
|
}
|
|
287
295
|
|
|
296
|
+
function xdrParseSacBalanceChange(changeEventType, 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
|
+
const res = {
|
|
306
|
+
address: xdrParseScVal(keyParts[1]),
|
|
307
|
+
balance: changeEventType===effectTypes.contractDataRemoved?
|
|
308
|
+
'0':
|
|
309
|
+
retrieveBalanceFromStateData(value)
|
|
310
|
+
}
|
|
311
|
+
if (res.balance === undefined)
|
|
312
|
+
return null
|
|
313
|
+
return res
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function retrieveBalanceFromStateData(value) {
|
|
317
|
+
const xdrVal = xdr.ScVal.fromXDR(value, 'base64')
|
|
318
|
+
if (xdrVal._arm !== 'map')
|
|
319
|
+
return undefined
|
|
320
|
+
const parsedValue = xdrParseScVal(xdrVal)
|
|
321
|
+
if (typeof parsedValue.amount !== 'string')
|
|
322
|
+
return undefined
|
|
323
|
+
return parsedValue.amount
|
|
324
|
+
}
|
|
325
|
+
|
|
288
326
|
module.exports = {
|
|
289
327
|
xdrParseAsset,
|
|
290
328
|
xdrParseAccountAddress,
|
|
@@ -295,5 +333,6 @@ module.exports = {
|
|
|
295
333
|
xdrParseTradeAtom,
|
|
296
334
|
xdrParseSignerKey,
|
|
297
335
|
xdrParsePrice,
|
|
298
|
-
xdrParseScVal
|
|
336
|
+
xdrParseScVal,
|
|
337
|
+
xdrParseSacBalanceChange
|
|
299
338
|
}
|