@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stellar-expert/tx-meta-effects-parser",
3
- "version": "6.0.1",
3
+ "version": "6.0.3",
4
4
  "description": "Low-level effects parser for Stellar transaction results and meta XDR",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -200,7 +200,10 @@ class EffectsAnalyzer {
200
200
 
201
201
  setOptions() {
202
202
  const sourceAccount = normalizeAddress(this.source)
203
- const {before, after} = this.changes.find(ch => ch.type === 'account' && ch.before.address === sourceAccount)
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 trustlineChange = this.changes.find(ch => ch.type === 'trustline' && ch.before.asset === trustAsset)
240
- if (trustlineChange) {
241
- if (trustlineChange.action !== 'updated')
242
- throw new UnexpectedTxMetaChangeError(trustlineChange)
243
- const {before, after} = trustlineChange
244
- if (before.flags !== after.flags) {
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.trustlineAuthorizationUpdated,
247
- trustor: this.operation.trustor,
248
- asset: after.asset,
249
- flags: after.flags,
250
- prevFlags: before.flags
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 {before, after} = this.changes.find(ch => ch.type === 'account')
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 poolUpdatedChanges = this.changes.find(ch => ch.type === 'liquidityPool' && ch.action === 'updated' && ch.after.pool === liquidityPoolId)
316
- if (!poolUpdatedChanges) //tx failed
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} = poolUpdatedChanges
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 {before, after} = this.changes.find(ch => ch.type === 'liquidityPool' && ch.action === 'updated' && ch.before.pool === pool)
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
@@ -1,8 +0,0 @@
1
- module.exports = {
2
- //utilize this ESLint config
3
- extends: ['@stellar-expert/eslint-config-js'],
4
- //provide paths to ignore
5
- ignorePatterns: ['distr/', 'node_modules/'],
6
- //define project-specific globals if any
7
- globals: {}
8
- }
package/.npmignore DELETED
@@ -1,6 +0,0 @@
1
- node_modules/
2
- .npm
3
- .idea
4
- test/
5
- pnpm-lock.yaml
6
- !.npmignore
package/babel.config.js DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- presets: [['@babel/preset-env', {targets: {node: 'current'}}]]
3
- }
package/jest.config.js DELETED
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- clearMocks: true,
3
- transformIgnorePatterns: [],
4
- maxWorkers: 1
5
- //runner: "jest-runner",
6
- }