@stellar-expert/tx-meta-effects-parser 5.6.5 → 5.7.0
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
|
@@ -67,7 +67,7 @@ class EventsAnalyzer {
|
|
|
67
67
|
const opContractId = this.effectsAnalyzer.retrieveOpContractId()
|
|
68
68
|
//diagnostic events
|
|
69
69
|
for (const evt of diagnosticEvents) {
|
|
70
|
-
if (!processSystemEvents && !evt.inSuccessfulContractCall())
|
|
70
|
+
if (!processSystemEvents && !(evt.inSuccessfulContractCall() || this.effectsAnalyzer.processFailedOpEffects))
|
|
71
71
|
continue //throw new UnexpectedTxMetaChangeError({type: 'diagnostic_event', action: 'failed'})
|
|
72
72
|
//parse event
|
|
73
73
|
const event = evt.event()
|
package/src/effects-analyzer.js
CHANGED
|
@@ -6,11 +6,11 @@ const {analyzeSignerChanges} = require('./aggregation/signer-changes-analyzer')
|
|
|
6
6
|
const {contractIdFromPreimage} = require('./parser/contract-preimage-encoder')
|
|
7
7
|
const EventsAnalyzer = require('./aggregation/events-analyzer')
|
|
8
8
|
const AssetSupplyAnalyzer = require('./aggregation/asset-supply-analyzer')
|
|
9
|
-
const {UnexpectedTxMetaChangeError, TxMetaEffectParserError} = require('./errors')
|
|
10
9
|
const {mapSacContract} = require('./aggregation/sac-contract-mapper')
|
|
10
|
+
const {UnexpectedTxMetaChangeError, TxMetaEffectParserError} = require('./errors')
|
|
11
11
|
|
|
12
12
|
class EffectsAnalyzer {
|
|
13
|
-
constructor({operation, meta, result, network, events, diagnosticEvents, mapSac, processSystemEvents}) {
|
|
13
|
+
constructor({operation, meta, result, network, events, diagnosticEvents, mapSac, processSystemEvents, processFailedOpEffects}) {
|
|
14
14
|
//set execution context
|
|
15
15
|
if (!operation.source)
|
|
16
16
|
throw new TxMetaEffectParserError('Operation source is not explicitly defined')
|
|
@@ -20,6 +20,7 @@ class EffectsAnalyzer {
|
|
|
20
20
|
this.changes = parseLedgerEntryChanges(meta)
|
|
21
21
|
this.source = this.operation.source
|
|
22
22
|
this.events = events
|
|
23
|
+
this.processFailedOpEffects = processFailedOpEffects
|
|
23
24
|
if (diagnosticEvents?.length) {
|
|
24
25
|
this.diagnosticEvents = diagnosticEvents
|
|
25
26
|
if (processSystemEvents) {
|
|
@@ -103,10 +104,7 @@ class EffectsAnalyzer {
|
|
|
103
104
|
//calculate minted/burned assets
|
|
104
105
|
new AssetSupplyAnalyzer(this).analyze()
|
|
105
106
|
//process state data changes in the end
|
|
106
|
-
|
|
107
|
-
if (change.type === 'contractData') {
|
|
108
|
-
this.processContractDataChanges(change)
|
|
109
|
-
}
|
|
107
|
+
this.processStateChanges()
|
|
110
108
|
return this.effects
|
|
111
109
|
}
|
|
112
110
|
|
|
@@ -813,7 +811,7 @@ class EffectsAnalyzer {
|
|
|
813
811
|
this.addEffect(effect)
|
|
814
812
|
}
|
|
815
813
|
|
|
816
|
-
|
|
814
|
+
processContractStateEntryChanges({action, before, after}) {
|
|
817
815
|
const {owner, key, durability} = after || before
|
|
818
816
|
const effect = {
|
|
819
817
|
type: '',
|
|
@@ -924,6 +922,13 @@ class EffectsAnalyzer {
|
|
|
924
922
|
}
|
|
925
923
|
}
|
|
926
924
|
|
|
925
|
+
processStateChanges() {
|
|
926
|
+
for (const change of this.changes)
|
|
927
|
+
if (change.type === 'contractData') {
|
|
928
|
+
this.processContractStateEntryChanges(change)
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
|
|
927
932
|
retrieveOpContractId() {
|
|
928
933
|
const funcValue = this.operation.func._value._attributes
|
|
929
934
|
if (funcValue) {
|
package/src/index.js
CHANGED
|
@@ -18,10 +18,11 @@ const effectTypes = require('./effect-types')
|
|
|
18
18
|
* @param {String|Buffer|xdr.TransactionMeta} [meta] - Base64-encoded tx envelope meta
|
|
19
19
|
* @param {Boolean} [mapSac] - Whether to create a map SAC->Asset
|
|
20
20
|
* @param {Boolean} [processSystemEvents] - Emit effects for contract errors and resource stats
|
|
21
|
+
* @param {Boolean} [processFailedOpEffects] - Whether to generate operation effects for failed/rejected transactions
|
|
21
22
|
* @param {Number} [protocol] - Specific Stellar protocol version for the executed transaction
|
|
22
23
|
* @return {ParsedTxOperationsMetadata}
|
|
23
24
|
*/
|
|
24
|
-
function parseTxOperationsMeta({network, tx, result, meta, mapSac = false, processSystemEvents = false, protocol}) {
|
|
25
|
+
function parseTxOperationsMeta({network, tx, result, meta, mapSac = false, processSystemEvents = false, processFailedOpEffects = false, protocol}) {
|
|
25
26
|
if (!network)
|
|
26
27
|
throw new TypeError(`Network passphrase argument is required.`)
|
|
27
28
|
if (typeof network !== 'string')
|
|
@@ -96,7 +97,8 @@ function parseTxOperationsMeta({network, tx, result, meta, mapSac = false, proce
|
|
|
96
97
|
const {success, opResults} = parseTxResult(parsedResult)
|
|
97
98
|
if (!success || isFeeBump && !feeBumpSuccess) {
|
|
98
99
|
res.failed = true
|
|
99
|
-
|
|
100
|
+
if (!processFailedOpEffects)
|
|
101
|
+
return res
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
//retrieve operations result metadata
|
|
@@ -128,11 +130,12 @@ function parseTxOperationsMeta({network, tx, result, meta, mapSac = false, proce
|
|
|
128
130
|
//analyze operation effects for each operation
|
|
129
131
|
for (let i = 0; i < parsedTx.operations.length; i++) {
|
|
130
132
|
const operation = parsedTx.operations[i]
|
|
131
|
-
if (success) {
|
|
133
|
+
if (success || processFailedOpEffects) {
|
|
132
134
|
const params = {
|
|
133
135
|
operation,
|
|
134
|
-
meta: opMeta[i]?.changes(),
|
|
135
|
-
result: opResults[i], network
|
|
136
|
+
meta: opMeta[i]?.changes() || [],
|
|
137
|
+
result: opResults[i], network,
|
|
138
|
+
processFailedOpEffects
|
|
136
139
|
}
|
|
137
140
|
const isSorobanInvocation = operation.type === 'invokeHostFunction'
|
|
138
141
|
//only for Soroban contract invocation
|
|
@@ -142,8 +145,6 @@ function parseTxOperationsMeta({network, tx, result, meta, mapSac = false, proce
|
|
|
142
145
|
params.diagnosticEvents = sorobanMeta.diagnosticEvents()
|
|
143
146
|
params.mapSac = mapSac
|
|
144
147
|
params.processSystemEvents = processSystemEvents
|
|
145
|
-
//process fee stats
|
|
146
|
-
|
|
147
148
|
}
|
|
148
149
|
const analyzer = new EffectsAnalyzer(params)
|
|
149
150
|
operation.effects = analyzer.analyze()
|