@stellar-expert/tx-meta-effects-parser 6.0.1 → 6.0.3
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/package.json +1 -1
- package/src/effects-analyzer.js +41 -32
- package/.eslintrc.js +0 -8
- package/.npmignore +0 -6
- package/babel.config.js +0 -3
- package/jest.config.js +0 -6
package/package.json
CHANGED
package/src/effects-analyzer.js
CHANGED
|
@@ -200,7 +200,10 @@ class EffectsAnalyzer {
|
|
|
200
200
|
|
|
201
201
|
setOptions() {
|
|
202
202
|
const sourceAccount = normalizeAddress(this.source)
|
|
203
|
-
const
|
|
203
|
+
const change = this.changes.find(ch => ch.type === 'account' && ch.before.address === sourceAccount)
|
|
204
|
+
if (!change)
|
|
205
|
+
return // failed tx or no changes
|
|
206
|
+
const {before, after} = change
|
|
204
207
|
if (before.homeDomain !== after.homeDomain) {
|
|
205
208
|
this.addEffect({
|
|
206
209
|
type: effectTypes.accountHomeDomainUpdated,
|
|
@@ -236,34 +239,34 @@ class EffectsAnalyzer {
|
|
|
236
239
|
if (!this.changes.length)
|
|
237
240
|
return
|
|
238
241
|
const trustAsset = xdrParseAsset(this.operation.asset || {code: this.operation.assetCode, issuer: normalizeAddress(this.source)})
|
|
239
|
-
const
|
|
240
|
-
if (
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
242
|
+
const change = this.changes.find(ch => ch.type === 'trustline' && ch.before.asset === trustAsset)
|
|
243
|
+
if (!change)
|
|
244
|
+
return
|
|
245
|
+
if (change.action !== 'updated')
|
|
246
|
+
throw new UnexpectedTxMetaChangeError(change)
|
|
247
|
+
const {before, after} = change
|
|
248
|
+
if (before.flags !== after.flags) {
|
|
249
|
+
this.addEffect({
|
|
250
|
+
type: effectTypes.trustlineAuthorizationUpdated,
|
|
251
|
+
trustor: this.operation.trustor,
|
|
252
|
+
asset: after.asset,
|
|
253
|
+
flags: after.flags,
|
|
254
|
+
prevFlags: before.flags
|
|
255
|
+
})
|
|
256
|
+
for (const change of this.changes) {
|
|
257
|
+
if (change.type !== 'liquidityPool')
|
|
258
|
+
continue
|
|
259
|
+
const {before, after} = change
|
|
245
260
|
this.addEffect({
|
|
246
|
-
type: effectTypes.
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
261
|
+
type: effectTypes.liquidityPoolWithdrew,
|
|
262
|
+
source: this.operation.trustor,
|
|
263
|
+
pool: before.pool,
|
|
264
|
+
assets: before.asset.map((asset, i) => ({
|
|
265
|
+
asset,
|
|
266
|
+
amount: (BigInt(before.amount[i]) - (after ? BigInt(after.amount[i]) : 0n)).toString()
|
|
267
|
+
})),
|
|
268
|
+
shares: (BigInt(before.shares) - (after ? BigInt(after.shares) : 0n)).toString()
|
|
251
269
|
})
|
|
252
|
-
for (const change of this.changes) {
|
|
253
|
-
if (change.type !== 'liquidityPool')
|
|
254
|
-
continue
|
|
255
|
-
const {before, after} = change
|
|
256
|
-
this.addEffect({
|
|
257
|
-
type: effectTypes.liquidityPoolWithdrew,
|
|
258
|
-
source: this.operation.trustor,
|
|
259
|
-
pool: before.pool,
|
|
260
|
-
assets: before.asset.map((asset, i) => ({
|
|
261
|
-
asset,
|
|
262
|
-
amount: (BigInt(before.amount[i]) - (after ? BigInt(after.amount[i]) : 0n)).toString()
|
|
263
|
-
})),
|
|
264
|
-
shares: (BigInt(before.shares) - (after ? BigInt(after.shares) : 0n)).toString()
|
|
265
|
-
})
|
|
266
|
-
}
|
|
267
270
|
}
|
|
268
271
|
}
|
|
269
272
|
}
|
|
@@ -281,7 +284,10 @@ class EffectsAnalyzer {
|
|
|
281
284
|
bumpSequence() {
|
|
282
285
|
if (!this.changes.length)
|
|
283
286
|
return
|
|
284
|
-
const
|
|
287
|
+
const change = this.changes.find(ch => ch.type === 'account')
|
|
288
|
+
if (!change)
|
|
289
|
+
return //failed tx or no changes
|
|
290
|
+
const {before, after} = change
|
|
285
291
|
if (before.sequence !== after.sequence) {
|
|
286
292
|
this.addEffect({
|
|
287
293
|
type: effectTypes.sequenceBumped,
|
|
@@ -312,10 +318,10 @@ class EffectsAnalyzer {
|
|
|
312
318
|
|
|
313
319
|
liquidityPoolDeposit() {
|
|
314
320
|
const {liquidityPoolId} = this.operation
|
|
315
|
-
const
|
|
316
|
-
if (!
|
|
321
|
+
const change = this.changes.find(ch => ch.type === 'liquidityPool' && ch.action === 'updated' && ch.after.pool === liquidityPoolId)
|
|
322
|
+
if (!change) //tx failed
|
|
317
323
|
return
|
|
318
|
-
const {before, after} =
|
|
324
|
+
const {before, after} = change
|
|
319
325
|
this.addEffect({
|
|
320
326
|
type: effectTypes.liquidityPoolDeposited,
|
|
321
327
|
pool: this.operation.liquidityPoolId,
|
|
@@ -329,7 +335,10 @@ class EffectsAnalyzer {
|
|
|
329
335
|
|
|
330
336
|
liquidityPoolWithdraw() {
|
|
331
337
|
const pool = this.operation.liquidityPoolId
|
|
332
|
-
const
|
|
338
|
+
const change = this.changes.find(ch => ch.type === 'liquidityPool' && ch.action === 'updated' && ch.before.pool === pool)
|
|
339
|
+
if (!change) //tx failed
|
|
340
|
+
return
|
|
341
|
+
const {before, after} = change
|
|
333
342
|
this.addEffect({
|
|
334
343
|
type: effectTypes.liquidityPoolWithdrew,
|
|
335
344
|
pool,
|
package/.eslintrc.js
DELETED
package/.npmignore
DELETED
package/babel.config.js
DELETED