Skip to content

Commit 1efaf07

Browse files
committed
feat: add filter by status to explorer transactions endpoint
1 parent 545b37b commit 1efaf07

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,14 @@ export class ExplorerAnalytics extends SharedAnalytics {
4848
user?: string, agent?: string,
4949
start?: number, end?: number,
5050
asc: boolean = false,
51+
status?: number,
5152
types: ExplorerType.TransactionType[] = ALL_TRANSACTION_TYPES
5253
): Promise<ExplorerType.TransactionsInfo> {
5354
const em = this.orm.em.fork()
54-
const isuser = user != null
55-
const isagent = agent != null
5655
;[start, end] = this.standardizeInterval(start, end)
57-
const window = start != null || end != null
5856
const transactions = await em.getConnection('read').execute(
59-
SQL.EXPLORER_TRANSACTIONS(isuser, isagent, asc, window, types),
60-
(isuser || isagent)
61-
? (window ? [user ?? agent, start, end, limit, offset] : [user ?? agent, limit, offset])
62-
: (window ? [start, end, limit, offset] : [limit, offset])
57+
SQL.EXPLORER_TRANSACTIONS(user != null, agent != null, asc, start != null || end != null, status != null, types),
58+
[user ?? agent, start, end, status, limit, offset].filter(x => x != null)
6359
) as SQL.ExplorerTransactionsOrmResult[]
6460
const info: ExplorerType.TransactionInfo[] = []
6561
for (const { name, timestamp, source, hash, agent_vault, agent_name, value_uba, user, resolution, underlying_payment } of transactions) {

packages/fasset-indexer-api/src/analytics/utils/raw-sql.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,17 @@ const explorerQueryTransactions = new Map([
137137
])
138138

139139
// psql specific query
140-
export const EXPLORER_TRANSACTIONS = (user: boolean, agent: boolean, asc: boolean, window: boolean, methods: TransactionType[]) => `
140+
export const EXPLORER_TRANSACTIONS = (
141+
user: boolean, agent: boolean,
142+
asc: boolean, window: boolean,
143+
status: boolean,
144+
methods: TransactionType[]
145+
) => `
141146
SELECT
142147
et.hash, el.name, eb.timestamp, eaa.hex as agent_vault,
143148
am.name as agent_name, eau.hex as user, eao.hex as source,
144149
t.value_uba, t.resolution, ur.id as underlying_payment, COUNT(*) OVER() as count
145-
FROM (${Array.from(explorerQueryTransactions.entries()).filter(([k, _]) => methods.includes(k)).map(([_,v]) => v).join(' UNION ALL ')}) t
150+
FROM (${Array.from(explorerQueryTransactions.entries()).filter(([k, _]) => methods.includes(k)).map(([_, v]) => v).join(' UNION ALL ')}) t
146151
FULL JOIN evm_address eau ON eau.id = t.user_id
147152
FULL JOIN underlying_reference ur ON ur.reference = t.payment_reference
148153
JOIN evm_log el ON el.id = t.evm_log_id
@@ -153,9 +158,11 @@ JOIN evm_address eao ON eao.id = et.source_id
153158
JOIN agent_vault av ON av.address_id = t.agent_vault_address_id
154159
JOIN agent_owner ao ON av.vaults = ao.id
155160
JOIN agent_manager am ON am.address_id = ao.agents
156-
${user ? 'WHERE eau.hex = ?' : ''}
157-
${agent ? 'WHERE eaa.hex = ?' : ''}
158-
${window ? ((agent || user ? 'AND' : 'WHERE') + ' eb.timestamp BETWEEN ? AND ?') : ''}
161+
WHERE 1=1
162+
${user ? 'AND eau.hex = ?' : ''}
163+
${agent ? 'AND eaa.hex = ?' : ''}
164+
${window ? 'AND eb.timestamp BETWEEN ? AND ?' : ''}
165+
${status ? 'AND t.resolution = ?' : ''}
159166
ORDER BY el.block_index ${asc ? 'ASC' : 'DESC'}
160167
LIMIT ? OFFSET ?
161168
`

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class ExplorerController {
3737
@ApiQuery({ name: 'start', type: Number, required: false })
3838
@ApiQuery({ name: 'end', type: Number, required: false })
3939
@ApiQuery({ name: 'asc', type: Boolean, required: false })
40+
@ApiQuery({ name: 'status', type: Number, required: false })
4041
@ApiQuery({ name: 'types', type: String, isArray: true, required: false })
4142
getTransactions(
4243
@Query('limit', ParseIntPipe) limit: number,
@@ -46,11 +47,12 @@ export class ExplorerController {
4647
@Query('asc', new ParseBoolPipe({ optional: true })) asc?: boolean,
4748
@Query('start', new ParseIntPipe({ optional: true })) start?: number,
4849
@Query('end', new ParseIntPipe({ optional: true })) end?: number,
50+
@Query('status', new ParseIntPipe({ optional: true })) status?: number,
4951
@Query('types') types?: string | string[]
5052
): Promise<ApiResponse<Types.TransactionsInfo>> {
5153
if (types != null && typeof types == 'string') types = [types]
5254
const transactionTypes = types != null ? this.parseTransactionTypes(types as string[]) : undefined
53-
return apiResponse(this.service.transactions(limit, offset, user, agent, start, end, asc, transactionTypes), 200)
55+
return apiResponse(this.service.transactions(limit, offset, user, agent, start, end, asc, status, transactionTypes), 200)
5456
}
5557

5658
@Get('transaction-classification')

0 commit comments

Comments
 (0)