Skip to content

Commit fd37bcc

Browse files
bayulaksana479andrewklau
authored andcommitted
feat(frontent): ft & nft list, token transfers in txn details
1 parent 4595eab commit fd37bcc

File tree

114 files changed

+2633
-751
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+2633
-751
lines changed

apps/api/src/routes/v3/txns.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,26 @@ const routes = (app: Router) => {
192192
* description: Success response
193193
*/
194194
route.get('/:hash/nfts', validate(request.nfts), service.nfts);
195+
196+
/**
197+
* @openapi
198+
* /v3/txns/{hash}/mts:
199+
* get:
200+
* summary: Get txn mt events
201+
* tags:
202+
* - V3 / Txns
203+
* parameters:
204+
* - in: path
205+
* name: hash
206+
* required: true
207+
* description: Txn hash or RLP hash to retrieve mt events for
208+
* schema:
209+
* type: string
210+
* responses:
211+
* 200:
212+
* description: Success response
213+
*/
214+
route.get('/:hash/mts', validate(request.mts), service.mts);
195215
};
196216

197217
export default routes;

apps/api/src/services/v3/fts/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const list = responseHandler(
4949
sort: cursor?.sort,
5050
},
5151
direction,
52+
has_cursor: !!cursor,
5253
// Fetch one extra to check if there is a next page
5354
limit: limit + 1,
5455
order,
@@ -63,7 +64,7 @@ const list = responseHandler(
6364
direction,
6465
(token) => ({
6566
contract: token.contract,
66-
sort,
67+
sort: token[sort as keyof FTList],
6768
}),
6869
!!cursor,
6970
);

apps/api/src/services/v3/nfts/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const list = responseHandler(
4848
contract: cursor?.contract,
4949
sort: cursor?.sort,
5050
},
51+
has_cursor: !!cursor,
5152
// Fetch one extra to check if there is a next page
5253
limit: limit + 1,
5354
order,
@@ -62,7 +63,7 @@ const list = responseHandler(
6263
direction,
6364
(token) => ({
6465
contract: token.contract,
65-
sort,
66+
sort: token[sort as keyof NFTList],
6667
}),
6768
!!cursor,
6869
);

apps/api/src/services/v3/txns/index.ts

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type {
44
TxnCountReq,
55
TxnFT,
66
TxnFTsReq,
7+
TxnMT,
8+
TxnMTsReq,
79
TxnNFT,
810
TxnNFTsReq,
911
TxnReceipt,
@@ -340,4 +342,67 @@ const nfts = responseHandler(
340342
},
341343
);
342344

343-
export default { count, fts, latest, nfts, receipts, txn, txns };
345+
const mts = responseHandler(
346+
response.mts,
347+
async (req: RequestValidator<TxnMTsReq>) => {
348+
const hash = req.validator.hash;
349+
350+
if (hash.startsWith('0x')) {
351+
const receipts = await rollingWindow<
352+
Pick<TxnMT, 'block_timestamp' | 'receipt_id'>[]
353+
>(
354+
async (start, end) => {
355+
const receipts = await dbBase.any<TxnMT>(sql.eventsRlp, {
356+
end,
357+
hash,
358+
start,
359+
});
360+
361+
return receipts.length ? receipts : null;
362+
},
363+
{ start: config.baseStart },
364+
);
365+
366+
if (!receipts || !receipts.length) {
367+
return { data: [] };
368+
}
369+
370+
const queries = receipts.map((receipt) => {
371+
return pgp.as.format(sql.mt, receipt);
372+
});
373+
const unionQuery = queries.join('\nUNION ALL\n');
374+
const mts = await dbEvents.manyOrNone<TxnMT>(unionQuery);
375+
376+
return { data: mts };
377+
}
378+
379+
const receipts = await rollingWindow<
380+
Pick<TxnMT, 'block_timestamp' | 'receipt_id'>[]
381+
>(
382+
async (start, end) => {
383+
const receipts = await dbBase.any<TxnMT>(sql.events, {
384+
end,
385+
hash,
386+
start,
387+
});
388+
389+
return receipts.length ? receipts : null;
390+
},
391+
{ start: config.baseStart },
392+
);
393+
394+
if (!receipts || !receipts.length) {
395+
return { data: [] };
396+
}
397+
398+
const queries = receipts.map((receipt) => {
399+
return pgp.as.format(sql.mt, receipt);
400+
});
401+
const unionQuery = queries.join('\nUNION ALL\n');
402+
const mts = await dbEvents.manyOrNone<TxnMT>(unionQuery);
403+
404+
return { data: mts };
405+
},
406+
);
407+
408+
export default { count, fts, latest, mts, nfts, receipts, txn, txns };

apps/api/src/sql/queries/accounts/fts/txns.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ FROM
4141
ft_meta fm
4242
WHERE
4343
fm.contract = ft.contract_account_id
44+
AND fm.modified_at IS NOT NULL
4445
) m ON TRUE
4546
WHERE
4647
affected_account_id = ${account}

apps/api/src/sql/queries/accounts/mts/txns.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ FROM
5555
WHERE
5656
mbm.contract = mt.contract_account_id
5757
AND mbm.token = mt.token_id
58+
AND mbm.modified_at IS NOT NULL
5859
) bm ON TRUE
5960
JOIN LATERAL (
6061
SELECT
@@ -75,6 +76,7 @@ FROM
7576
WHERE
7677
mtm.contract = mt.contract_account_id
7778
AND mtm.token = mt.token_id
79+
AND mtm.modified_at IS NOT NULL
7880
) tm ON TRUE
7981
WHERE
8082
affected_account_id = ${account}

apps/api/src/sql/queries/accounts/nfts/txns.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ FROM
3838
reference
3939
) AS meta
4040
FROM
41-
nft_meta nfm
41+
nft_meta nm
4242
WHERE
43-
nfm.contract = nft.contract_account_id
43+
nm.contract = nft.contract_account_id
44+
AND nm.modified_at IS NOT NULL
4445
) m ON TRUE
4546
JOIN LATERAL (
4647
SELECT
@@ -61,6 +62,7 @@ FROM
6162
WHERE
6263
ntm.contract = nft.contract_account_id
6364
AND ntm.token = nft.token_id
65+
AND ntm.modified_at IS NOT NULL
6466
) tm ON TRUE
6567
WHERE
6668
affected_account_id = ${account}

apps/api/src/sql/queries/fts/contract.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ FROM
2727
ft_meta
2828
WHERE
2929
contract = ${contract}
30+
AND modified_at IS NOT NULL

apps/api/src/sql/queries/fts/contractTxns.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ FROM
4141
ft_meta fm
4242
WHERE
4343
fm.contract = ft.contract_account_id
44+
AND fm.modified_at IS NOT NULL
4445
) m ON TRUE
4546
WHERE
4647
ft.contract_account_id = ${contract}

apps/api/src/sql/queries/fts/list.sql

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,50 @@ WHERE
2222
OR name ILIKE ${search}
2323
)
2424
AND (
25-
${cursor.sort} IS NULL
25+
NOT ${has_cursor}
2626
OR (
2727
${order} = 'desc'
2828
AND (
29-
(${sort:name} < ${cursor.sort})
29+
(
30+
${cursor.sort} IS NOT NULL
31+
AND (
32+
(${sort:name} < ${cursor.sort})
33+
OR (
34+
${sort:name} = ${cursor.sort}
35+
AND contract > ${cursor.contract}
36+
)
37+
OR (${sort:name} IS NULL)
38+
)
39+
)
3040
OR (
31-
${sort:name} = ${cursor.sort}
41+
${cursor.sort} IS NULL
42+
AND ${sort:name} IS NULL
3243
AND contract > ${cursor.contract}
3344
)
3445
)
3546
)
3647
OR (
3748
${order} = 'asc'
3849
AND (
39-
(${sort:name} > ${cursor.sort})
50+
(
51+
${cursor.sort} IS NOT NULL
52+
AND (
53+
(${sort:name} > ${cursor.sort})
54+
OR (
55+
${sort:name} = ${cursor.sort}
56+
AND contract > ${cursor.contract}
57+
)
58+
)
59+
)
4060
OR (
41-
${sort:name} = ${cursor.sort}
42-
AND contract > ${cursor.contract}
61+
${cursor.sort} IS NULL
62+
AND (
63+
(
64+
${sort:name} IS NULL
65+
AND contract > ${cursor.contract}
66+
)
67+
OR (${sort:name} IS NOT NULL)
68+
)
4369
)
4470
)
4571
)

0 commit comments

Comments
 (0)