@stellar-expert/tx-meta-effects-parser 9.2.0 → 9.3.1

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": "9.2.0",
3
+ "version": "9.3.1",
4
4
  "description": "Low-level effects parser for Stellar transaction results and meta XDR",
5
5
  "main": "src/index.js",
6
6
  "author": "team@stellar.expert",
@@ -414,6 +414,30 @@ class EffectsAnalyzer {
414
414
  }
415
415
  case 'createContract':
416
416
  case 'createContractV2': //handled in entry changes
417
+ const executable = value.executable()
418
+ const executableType = executable.switch().name
419
+ if (executableType !== 'contractExecutableWasm') {
420
+ const preimage = value.contractIdPreimage()
421
+ const preimageParams = preimage.value()
422
+ const effect = {
423
+ type: effectTypes.contractCreated,
424
+ contract: contractIdFromPreimage(preimage, this.network)
425
+ }
426
+ switch (preimage.switch().name) {
427
+ case 'contractIdPreimageFromAddress':
428
+ effect.kind = 'fromAddress'
429
+ effect.issuer = xdrParseAccountAddress(preimageParams.address().value())
430
+ effect.salt = preimageParams.salt().toString('base64')
431
+ break
432
+ case 'contractIdPreimageFromAsset':
433
+ effect.kind = 'fromAsset'
434
+ effect.asset = xdrParseAsset(preimageParams)
435
+ break
436
+ default:
437
+ throw new TxMetaEffectParserError('Unknown preimage type: ' + preimage.switch().name)
438
+ }
439
+ this.addEffect(effect)
440
+ }
417
441
  break
418
442
  default:
419
443
  throw new TxMetaEffectParserError('Unknown host function call type: ' + func.arm())
@@ -788,6 +812,8 @@ class EffectsAnalyzer {
788
812
  case 'wasm':
789
813
  effect.wasmHash = after.wasmHash
790
814
  break
815
+ case 'fromAddress':
816
+ break
791
817
  default:
792
818
  throw new TxMetaEffectParserError('Unexpected contract type: ' + kind)
793
819
  }
@@ -808,7 +834,17 @@ class EffectsAnalyzer {
808
834
  throw new UnexpectedTxMetaChangeError({type: 'contract', action})
809
835
  }
810
836
  if (effect) {
811
- this.addEffect(effect, effect.type === effectTypes.contractCreated ? this.effects.findIndex(e => e.contract === effect.contract || e.owner === effect.contract) : undefined)
837
+ if (effect.type === effectTypes.contractCreated) {
838
+ const existing = this.effects.find(e => e.type === effectTypes.contractCreated && e.contract === effect.contract)
839
+ if (!existing) { //the effect might be already emitted from the op call
840
+ this.addEffect(effect, this.effects.findIndex(e => e.contract === effect.contract || e.owner === effect.contract))
841
+ } else {
842
+ existing.keyHash = effect.keyHash //assign keyHash, can't be calculated directly
843
+ }
844
+ } else {
845
+
846
+ this.addEffect(effect)
847
+ }
812
848
  }
813
849
  if (before?.storage?.length || after?.storage?.length) {
814
850
  this.processInstanceDataChanges(before, after, action === 'restored')
@@ -278,12 +278,14 @@ function parseContractData(value) {
278
278
  const type = instance.executable._switch.name
279
279
  switch (type) {
280
280
  case 'contractExecutableStellarAsset':
281
- entry.kind = 'fromAsset'
282
281
  if (instance.storage?.length) { //if not -- the asset has been created "fromAddress" - no metadata in this case
282
+ entry.kind = 'fromAsset'
283
283
  const metaArgs = instance.storage[0]._attributes
284
284
  if (metaArgs.key._value.toString() !== 'METADATA')
285
285
  throw new TxMetaEffectParserError('Unexpected asset initialization metadata')
286
286
  entry.asset = xdrParseAsset(metaArgs.val._value[1]._attributes.val._value.toString())
287
+ } else {
288
+ entry.kind = 'fromAddress'
287
289
  }
288
290
  break
289
291
  case 'contractExecutableWasm':