@stellar-expert/tx-meta-effects-parser 5.5.2 → 5.5.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,7 @@
|
|
|
1
1
|
const {StrKey} = require('@stellar/stellar-base')
|
|
2
2
|
const effectTypes = require('../effect-types')
|
|
3
3
|
const {xdrParseScVal, xdrParseAsset, isContractAddress} = require('../parser/tx-xdr-parser-utils')
|
|
4
|
+
const {contractIdFromPreimage} = require('../parser/contract-preimage-encoder')
|
|
4
5
|
const {mapSacContract} = require('./sac-contract-mapper')
|
|
5
6
|
|
|
6
7
|
const EVENT_TYPES = {
|
|
@@ -64,15 +65,18 @@ class EventsAnalyzer {
|
|
|
64
65
|
const {diagnosticEvents, processSystemEvents} = this.effectsAnalyzer
|
|
65
66
|
if (!diagnosticEvents)
|
|
66
67
|
return
|
|
68
|
+
const opContractId = retrieveOpContractId(this.effectsAnalyzer.operation, this.effectsAnalyzer.network)
|
|
67
69
|
//diagnostic events
|
|
68
70
|
for (const evt of diagnosticEvents) {
|
|
69
71
|
if (!processSystemEvents && !evt.inSuccessfulContractCall())
|
|
70
72
|
continue //throw new UnexpectedTxMetaChangeError({type: 'diagnostic_event', action: 'failed'})
|
|
71
73
|
//parse event
|
|
72
74
|
const event = evt.event()
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
let contractId = event.contractId() || opContractId //contract id may be attached to the event itself, otherwise use contract from operation
|
|
76
|
+
if (contractId && typeof contractId !== 'string') {
|
|
77
|
+
contractId = StrKey.encodeContract(contractId)
|
|
78
|
+
}
|
|
79
|
+
this.processDiagnosticEvent(event.body().value(), event.type().value, contractId)
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
|
|
@@ -301,4 +305,18 @@ function processEventBodyValue(value) {
|
|
|
301
305
|
return xdrParseScVal(value) //other scValue
|
|
302
306
|
}
|
|
303
307
|
|
|
308
|
+
function retrieveOpContractId(operation, network) {
|
|
309
|
+
const funcValue = operation.func._value._attributes
|
|
310
|
+
if (!funcValue)
|
|
311
|
+
return null //WASM upload
|
|
312
|
+
let address = funcValue.contractAddress?._value
|
|
313
|
+
if (!address) {
|
|
314
|
+
const preimage = funcValue.contractIdPreimage
|
|
315
|
+
if (preimage) {
|
|
316
|
+
address = contractIdFromPreimage(preimage, network)
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return address
|
|
320
|
+
}
|
|
321
|
+
|
|
304
322
|
module.exports = EventsAnalyzer
|