Skip to content

Commit c29de0f

Browse files
committed
chore: expand transaction classification to return event names instead of transaction types
1 parent 3e47069 commit c29de0f

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

packages/fasset-indexer-api/src/analytics/explorer.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,9 @@ export class ExplorerAnalytics {
6363
): Promise<ExplorerType.GenericTransactionClassification> {
6464
const em = this.orm.em.fork()
6565
if (this.isNativeTransactionHash(hash)) {
66-
const logs = await em.find(Entities.EvmLog, {
67-
transaction: { hash },
68-
name: { $in: VALID_EVENTS }
69-
})
70-
return logs.map(log => ({
71-
transactionHash: hash,
72-
eventName: ExplorerType.TransactionType[
73-
this.eventNameToTransactionType(log.name)]
74-
}))
66+
return this.nativeTransactionClassification(em, hash)
7567
} else if (this.isRippleTransactionHash(hash)) {
76-
const resp = await em.getConnection('read').execute(
77-
SQL.EVENT_FROM_UNDERLYING_HASH, [hash]
78-
) as { hash: string, name: string }[]
79-
return resp.map(({ hash, name }) => ({
80-
transactionHash: hash,
81-
eventName:ExplorerType.TransactionType[
82-
this.eventNameToTransactionType(name)]
83-
}))
68+
return this.rippleTransactionClassification(em, hash)
8469
}
8570
throw new Error(`don't recognize transaction hash ${hash} format`)
8671
}
@@ -313,6 +298,16 @@ export class ExplorerAnalytics {
313298
)
314299
}
315300

301+
protected async nativeTransactionClassification(em: EntityManager, hash: string): Promise<ExplorerType.GenericTransactionClassification> {
302+
const logs = await em.find(Entities.EvmLog, { transaction: { hash }, name: { $in: VALID_EVENTS } })
303+
return logs.map(log => ({ transactionHash: hash, eventName: log.name }))
304+
}
305+
306+
protected async rippleTransactionClassification(em: EntityManager, hash: string): Promise<ExplorerType.GenericTransactionClassification> {
307+
const resp = await em.getConnection('read').execute(SQL.EVENT_FROM_UNDERLYING_HASH, [hash]) as { hash: string, name: string }[]
308+
return resp.map(({ hash, name }) => ({ transactionHash: hash, eventName: name }))
309+
}
310+
316311
protected eventNameToTransactionType(name: string): ExplorerType.TransactionType {
317312
switch (name) {
318313
case 'CollateralReserved':

0 commit comments

Comments
 (0)