@stellar-expert/tx-meta-effects-parser 5.5.0 → 5.5.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
|
@@ -70,7 +70,8 @@ class EventsAnalyzer {
|
|
|
70
70
|
continue //throw new UnexpectedTxMetaChangeError({type: 'diagnostic_event', action: 'failed'})
|
|
71
71
|
//parse event
|
|
72
72
|
const event = evt.event()
|
|
73
|
-
const contractId = event.contractId()
|
|
73
|
+
const contractId = event.contractId() //contract id attached to the event itself
|
|
74
|
+
|| this.effectsAnalyzer.operation.func._value.contractAddress()._value //retrieve from the operation
|
|
74
75
|
this.processDiagnosticEvent(event.body().value(), event.type().value, contractId ? StrKey.encodeContract(contractId) : null)
|
|
75
76
|
}
|
|
76
77
|
}
|
|
@@ -78,10 +79,10 @@ class EventsAnalyzer {
|
|
|
78
79
|
/**
|
|
79
80
|
* @param {xdr.ContractEventV0} body
|
|
80
81
|
* @param {Number} type
|
|
81
|
-
* @param {String}
|
|
82
|
+
* @param {String} contract
|
|
82
83
|
* @private
|
|
83
84
|
*/
|
|
84
|
-
processDiagnosticEvent(body, type,
|
|
85
|
+
processDiagnosticEvent(body, type, contract) {
|
|
85
86
|
const topics = body.topics()
|
|
86
87
|
if (!topics?.length)
|
|
87
88
|
return
|
|
@@ -119,6 +120,7 @@ class EventsAnalyzer {
|
|
|
119
120
|
return // skip non-diagnostic events
|
|
120
121
|
this.effectsAnalyzer.addEffect({
|
|
121
122
|
type: effectTypes.contractError,
|
|
123
|
+
contract,
|
|
122
124
|
code: topics[1].value().value(),
|
|
123
125
|
details: processEventBodyValue(body.data())
|
|
124
126
|
})
|
|
@@ -126,7 +128,7 @@ class EventsAnalyzer {
|
|
|
126
128
|
case 'core_metrics':
|
|
127
129
|
if (type !== EVENT_TYPES.DIAGNOSTIC)
|
|
128
130
|
return // skip non-diagnostic events
|
|
129
|
-
this.effectsAnalyzer.addMetric(xdrParseScVal(topics[1]), parseInt(processEventBodyValue(body.data())))
|
|
131
|
+
this.effectsAnalyzer.addMetric(contract, xdrParseScVal(topics[1]), parseInt(processEventBodyValue(body.data())))
|
|
130
132
|
break
|
|
131
133
|
//handle standard token contract events
|
|
132
134
|
//see https://github.com/stellar/rs-soroban-sdk/blob/main/soroban-sdk/src/token.rs
|
|
@@ -146,31 +148,31 @@ class EventsAnalyzer {
|
|
|
146
148
|
let classicAsset
|
|
147
149
|
if (topics.length > 3) {
|
|
148
150
|
classicAsset = xdrParseAsset(xdrParseScVal(topics[3]))
|
|
149
|
-
if (!mapSacContract(this.effectsAnalyzer,
|
|
151
|
+
if (!mapSacContract(this.effectsAnalyzer, contract, classicAsset)) {
|
|
150
152
|
classicAsset = null //not an SAC event
|
|
151
153
|
}
|
|
152
154
|
}
|
|
153
155
|
if (classicAsset && (classicAsset.includes(from) || classicAsset.includes(to))) { //SAC transfer by asset issuer
|
|
154
156
|
if (classicAsset.includes(from)) {
|
|
155
|
-
this.effectsAnalyzer.mint(
|
|
156
|
-
this.effectsAnalyzer.credit(amount, isContractAddress(to) ?
|
|
157
|
+
this.effectsAnalyzer.mint(contract, amount)
|
|
158
|
+
this.effectsAnalyzer.credit(amount, isContractAddress(to) ? contract : classicAsset, to)
|
|
157
159
|
}
|
|
158
160
|
if (classicAsset.includes(to)) {
|
|
159
|
-
this.effectsAnalyzer.debit(amount, isContractAddress(from) ?
|
|
160
|
-
this.effectsAnalyzer.burn(
|
|
161
|
+
this.effectsAnalyzer.debit(amount, isContractAddress(from) ? contract : classicAsset, from)
|
|
162
|
+
this.effectsAnalyzer.burn(contract, amount)
|
|
161
163
|
}
|
|
162
164
|
} else { //other cases
|
|
163
165
|
if (classicAsset && !isContractAddress(from)) { //classic asset bridged to Soroban
|
|
164
166
|
this.effectsAnalyzer.burn(classicAsset, amount)
|
|
165
|
-
this.effectsAnalyzer.mint(
|
|
167
|
+
this.effectsAnalyzer.mint(contract, amount)
|
|
166
168
|
} else {
|
|
167
|
-
this.effectsAnalyzer.debit(amount,
|
|
169
|
+
this.effectsAnalyzer.debit(amount, contract, from)
|
|
168
170
|
}
|
|
169
171
|
if (classicAsset && !isContractAddress(to)) { //classic asset bridged from Soroban
|
|
170
|
-
this.effectsAnalyzer.burn(
|
|
172
|
+
this.effectsAnalyzer.burn(contract, amount)
|
|
171
173
|
this.effectsAnalyzer.mint(classicAsset, amount)
|
|
172
174
|
} else {
|
|
173
|
-
this.effectsAnalyzer.credit(amount,
|
|
175
|
+
this.effectsAnalyzer.credit(amount, contract, to)
|
|
174
176
|
}
|
|
175
177
|
}
|
|
176
178
|
|
|
@@ -185,12 +187,12 @@ class EventsAnalyzer {
|
|
|
185
187
|
return
|
|
186
188
|
this.effectsAnalyzer.addEffect({
|
|
187
189
|
type: effectTypes.assetMinted,
|
|
188
|
-
asset:
|
|
190
|
+
asset: contract,
|
|
189
191
|
amount
|
|
190
192
|
})
|
|
191
|
-
this.effectsAnalyzer.credit(amount,
|
|
193
|
+
this.effectsAnalyzer.credit(amount, contract, to)
|
|
192
194
|
if (topics.length > 3) {
|
|
193
|
-
mapSacContract(this.effectsAnalyzer,
|
|
195
|
+
mapSacContract(this.effectsAnalyzer, contract, xdrParseAsset(xdrParseScVal(topics[3])))
|
|
194
196
|
}
|
|
195
197
|
}
|
|
196
198
|
break
|
|
@@ -205,10 +207,10 @@ class EventsAnalyzer {
|
|
|
205
207
|
))
|
|
206
208
|
return
|
|
207
209
|
|
|
208
|
-
this.effectsAnalyzer.debit(amount,
|
|
209
|
-
this.effectsAnalyzer.burn(
|
|
210
|
+
this.effectsAnalyzer.debit(amount, contract, from)
|
|
211
|
+
this.effectsAnalyzer.burn(contract, amount)
|
|
210
212
|
if (topics.length > 2) {
|
|
211
|
-
mapSacContract(this.effectsAnalyzer,
|
|
213
|
+
mapSacContract(this.effectsAnalyzer, contract, xdrParseAsset(xdrParseScVal(topics[2])))
|
|
212
214
|
}
|
|
213
215
|
}
|
|
214
216
|
break
|
|
@@ -219,10 +221,10 @@ class EventsAnalyzer {
|
|
|
219
221
|
const amount = processEventBodyValue(body.data())
|
|
220
222
|
if (!this.matchInvocationEffect(e => e.function === 'clawback' && matchArrays([from, amount], e.args)))
|
|
221
223
|
return
|
|
222
|
-
this.effectsAnalyzer.debit(amount,
|
|
223
|
-
this.effectsAnalyzer.burn(
|
|
224
|
+
this.effectsAnalyzer.debit(amount, contract, from)
|
|
225
|
+
this.effectsAnalyzer.burn(contract, amount)
|
|
224
226
|
if (topics.length > 3) {
|
|
225
|
-
mapSacContract(this.effectsAnalyzer,
|
|
227
|
+
mapSacContract(this.effectsAnalyzer, contract, xdrParseAsset(xdrParseScVal(topics[3])))
|
|
226
228
|
}
|
|
227
229
|
}
|
|
228
230
|
break
|
|
@@ -233,9 +235,9 @@ class EventsAnalyzer {
|
|
|
233
235
|
const newAdmin = processEventBodyValue(body.data())
|
|
234
236
|
if (!this.matchInvocationEffect(e => e.function === 'set_admin' && matchArrays([currentAdmin, newAdmin], [this.effectsAnalyzer.source, e.args])))
|
|
235
237
|
return
|
|
236
|
-
this.effectsAnalyzer.setAdmin(
|
|
238
|
+
this.effectsAnalyzer.setAdmin(contract, newAdmin)
|
|
237
239
|
if (topics.length > 2) {
|
|
238
|
-
mapSacContract(this.effectsAnalyzer,
|
|
240
|
+
mapSacContract(this.effectsAnalyzer, contract, xdrParseAsset(xdrParseScVal(topics[2])))
|
|
239
241
|
}
|
|
240
242
|
}
|
|
241
243
|
break
|
package/src/effects-analyzer.js
CHANGED
|
@@ -173,11 +173,12 @@ class EffectsAnalyzer {
|
|
|
173
173
|
}, position)
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
addMetric(metric, value) {
|
|
176
|
+
addMetric(contract, metric, value) {
|
|
177
177
|
let {metrics} = this
|
|
178
178
|
if (!metrics) {
|
|
179
179
|
metrics = this.metrics = {
|
|
180
|
-
type: effectTypes.contractMetrics
|
|
180
|
+
type: effectTypes.contractMetrics,
|
|
181
|
+
contract
|
|
181
182
|
}
|
|
182
183
|
this.addEffect(metrics)
|
|
183
184
|
}
|