Skip to content

Commit 2f9e2d2

Browse files
committed
fix: prioritize fetching successful underlying transactions at fasset-explorer transaction details api
1 parent 33271ef commit 2f9e2d2

File tree

8 files changed

+20
-5
lines changed

8 files changed

+20
-5
lines changed

packages/fasset-indexer-api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@nestjs/swagger": "^7.3.1",
2121
"cache-manager": "^5.1.0",
2222
"fasset-indexer-core": "workspace:*",
23+
"fasset-indexer-xrp": "workspace:*",
2324
"helmet": "^7.1.0",
2425
"reflect-metadata": "^0.2.0",
2526
"rxjs": "^7.8.1"

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as ExplorerType from "./types"
44
import * as SQL from "./utils/raw-sql"
55
import { PaymentReference } from "fasset-indexer-core/utils"
66
import { EVENTS } from "fasset-indexer-core/config"
7+
import { XRP_TRANSACTION_SUCCESS_CODE } from 'fasset-indexer-xrp/constants'
78
import { unixnow } from "../shared/utils"
89
import type { EntityManager, ORM } from "fasset-indexer-core/orm"
910
import type { FilterQuery } from "@mikro-orm/core"
@@ -409,10 +410,14 @@ export class ExplorerAnalytics {
409410
reference: string,
410411
filters: FilterQuery<Entities.UnderlyingVoutReference> = {}
411412
): Promise<Entities.UnderlyingVoutReference | null> {
412-
return em.findOne(Entities.UnderlyingVoutReference,
413+
const transactions = await em.find(Entities.UnderlyingVoutReference,
413414
{ fasset, reference, ...filters as object },
414415
{ populate: [ 'transaction.block', 'transaction.source', 'transaction.target' ] }
415416
)
417+
if (transactions.length == 0) return null
418+
const successful = transactions.filter(x => x.transaction.result == XRP_TRANSACTION_SUCCESS_CODE)
419+
if (successful.length > 0) return successful[0]
420+
return transactions[0]
416421
}
417422

418423
protected eventNameToTransactionType(name: string): ExplorerType.TransactionType {

packages/fasset-indexer-api/src/controllers/explorer.controller.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ export class ExplorerController {
4242
@Query('types') types?: string | string[]
4343
): Promise<ApiResponse<TransactionsInfo>> {
4444
if (types != null && typeof types == 'string') types = [types]
45-
console.log(types)
4645
const transactionTypes = types != null ? this.parseTransactionTypes(types as string[]) : undefined
47-
console.log(transactionTypes)
4846
return apiResponse(this.service.transactions(limit, offset, user, agent, start, end, asc, transactionTypes), 200)
4947
}
5048

packages/fasset-indexer-api/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"references": [
1717
{
1818
"path": "../fasset-indexer-core"
19+
},
20+
{
21+
"path": "../fasset-indexer-xrp"
1922
}
2023
]
2124
}

packages/fasset-indexer-xrp/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
".": {
99
"types": "./dist/src/index.d.ts",
1010
"default": "./dist/src/index.js"
11+
},
12+
"./constants": {
13+
"types": "./dist/src/config/index.d.ts",
14+
"default": "./dist/src/config/index.js"
1115
}
1216
},
1317
"scripts": {

packages/fasset-indexer-xrp/src/config/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ export const FIRST_UNHANDLED_XRP_BLOCK_DB_KEY = 'firstUnhandledXrpBlock'
22
export const MIN_XRP_BLOCK_NUMBER_DB_KEY = 'minXrpBlockNumber'
33

44
export const XRP_BLOCK_HEIGHT_OFFSET = 15
5-
export const XRP_TIMESTAMP_UNIX_OFFSET = 946684800
5+
export const XRP_TIMESTAMP_UNIX_OFFSET = 946684800
6+
7+
export const XRP_TRANSACTION_SUCCESS_CODE = 'tesSUCCESS'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { XRP_TRANSACTION_SUCCESS_CODE } from './constants'

yarn.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3618,6 +3618,7 @@ __metadata:
36183618
"@types/supertest": ^6.0.0
36193619
cache-manager: ^5.1.0
36203620
fasset-indexer-core: "workspace:*"
3621+
fasset-indexer-xrp: "workspace:*"
36213622
helmet: ^7.1.0
36223623
reflect-metadata: ^0.2.0
36233624
rxjs: ^7.8.1
@@ -3674,7 +3675,7 @@ __metadata:
36743675
languageName: unknown
36753676
linkType: soft
36763677

3677-
"fasset-indexer-xrp@workspace:packages/fasset-indexer-xrp":
3678+
"fasset-indexer-xrp@workspace:*, fasset-indexer-xrp@workspace:packages/fasset-indexer-xrp":
36783679
version: 0.0.0-use.local
36793680
resolution: "fasset-indexer-xrp@workspace:packages/fasset-indexer-xrp"
36803681
dependencies:

0 commit comments

Comments
 (0)