@stellar-expert/tx-meta-effects-parser 5.6.0 → 5.6.2

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": "5.6.0",
3
+ "version": "5.6.2",
4
4
  "description": "Low-level effects parser for Stellar transaction results and meta XDR",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -9,7 +9,7 @@
9
9
  "author": "team@stellar.expert",
10
10
  "license": "MIT",
11
11
  "peerDependencies": {
12
- "@stellar/stellar-base": "^12.0.1"
12
+ "@stellar/stellar-base": "^12.1.0"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@babel/core": "^7.22.9",
@@ -50,9 +50,9 @@ class AssetSupplyAnalyzer {
50
50
  this.supplyChanges |= 1
51
51
  }
52
52
  }
53
- if ((this.supplyChanges & 3) === 3) { //analyze possible collapsible mints only if both mint and burn effects recorded
53
+ /*if ((this.supplyChanges & 3) === 3) { //analyze possible collapsible mints only if both mint and burn effects recorded
54
54
  new CollapsibleMintsAnalyzer(this.effectsAnalyzer).removeCollapsingMints()
55
- }
55
+ }*/
56
56
  }
57
57
 
58
58
  /**
@@ -181,7 +181,7 @@ class CollapsibleMintsAnalyzer {
181
181
  if (sum > 0n) { //asset minted
182
182
  this.effectsAnalyzer.mint(asset, sum.toString(), true) //insert mint effect
183
183
  } else if (sum < 0n) { //asset burned
184
- this.effectsAnalyzer.burn(asset, sum.toString(), position) //insert burn effect at the position of the last removed effect
184
+ this.effectsAnalyzer.burn(asset, (-sum).toString(), position) //insert burn effect at the position of the last removed effect
185
185
  }
186
186
  //if sum=0 then both effects were annihilated and removed
187
187
  }
@@ -158,13 +158,6 @@ class EventsAnalyzer {
158
158
  if (classicAsset) {
159
159
  if (classicAsset.includes(from)) { //SAC transfer by asset issuer
160
160
  this.effectsAnalyzer.mint(classicAsset, amount)
161
- this.effectsAnalyzer.credit(amount, classicAsset, to)
162
- return
163
- }
164
- if (classicAsset.includes(to)) { //SAC transfer by asset issuer
165
- this.effectsAnalyzer.debit(amount, classicAsset, from)
166
- this.effectsAnalyzer.burn(classicAsset, amount)
167
- return
168
161
  }
169
162
  if (isContractAddress(from)) {
170
163
  this.effectsAnalyzer.debit(amount, classicAsset, from)
@@ -172,6 +165,9 @@ class EventsAnalyzer {
172
165
  if (isContractAddress(to)) {
173
166
  this.effectsAnalyzer.credit(amount, classicAsset, to)
174
167
  }
168
+ if (classicAsset.includes(to)) { //SAC transfer by asset issuer
169
+ this.effectsAnalyzer.burn(classicAsset, amount)
170
+ }
175
171
  } else { //other cases
176
172
  this.effectsAnalyzer.debit(amount, this.effectsAnalyzer.resolveAsset(contract), from)
177
173
  this.effectsAnalyzer.credit(amount, this.effectsAnalyzer.resolveAsset(contract), to)
@@ -190,7 +186,7 @@ class EventsAnalyzer {
190
186
  }
191
187
  const asset = this.effectsAnalyzer.resolveAsset(contract)
192
188
  this.effectsAnalyzer.mint(asset, amount)
193
- if (isContractAddress(asset)) {
189
+ if (isContractAddress(asset) || isContractAddress(to)) {
194
190
  this.effectsAnalyzer.credit(amount, asset, to)
195
191
  }
196
192
  }
@@ -209,7 +205,7 @@ class EventsAnalyzer {
209
205
  mapSacContract(this.effectsAnalyzer, contract, xdrParseAsset(xdrParseScVal(topics[2])))
210
206
  }
211
207
  const asset = this.effectsAnalyzer.resolveAsset(contract)
212
- if (isContractAddress(asset)) {
208
+ if (isContractAddress(asset) || isContractAddress(from)) {
213
209
  this.effectsAnalyzer.debit(amount, asset, from)
214
210
  }
215
211
  this.effectsAnalyzer.burn(asset, amount)
@@ -132,7 +132,7 @@ class EffectsAnalyzer {
132
132
  type: effectTypes.accountDebited,
133
133
  source,
134
134
  asset,
135
- amount
135
+ amount: validateAmount(amount)
136
136
  }
137
137
  if (balance !== undefined) {
138
138
  effect.balance = balance
@@ -147,7 +147,7 @@ class EffectsAnalyzer {
147
147
  type: effectTypes.accountCredited,
148
148
  source,
149
149
  asset,
150
- amount
150
+ amount: validateAmount(amount)
151
151
  }
152
152
  if (balance !== undefined) {
153
153
  effect.balance = balance
@@ -162,7 +162,7 @@ class EffectsAnalyzer {
162
162
  this.addEffect({
163
163
  type: effectTypes.assetMinted,
164
164
  asset,
165
- amount
165
+ amount: validateAmount(amount)
166
166
  }, position)
167
167
  }
168
168
 
@@ -170,7 +170,7 @@ class EffectsAnalyzer {
170
170
  this.addEffect({
171
171
  type: effectTypes.assetBurned,
172
172
  asset,
173
- amount
173
+ amount: validateAmount(amount)
174
174
  }, position)
175
175
  }
176
176
 
@@ -998,6 +998,12 @@ function encodeSponsorshipEffectName(action, type) {
998
998
  return effectTypes[`${type}Sponsorship${actionKey}`]
999
999
  }
1000
1000
 
1001
+ function validateAmount(amount) {
1002
+ if (amount < 0)
1003
+ throw new TxMetaEffectParserError('Negative balance change amount: ' + amount.toString())
1004
+ return amount
1005
+ }
1006
+
1001
1007
  function parseLargeInt(largeInt) {
1002
1008
  return largeInt._value.toString()
1003
1009
  }