Skip to content

Commit d5aed23

Browse files
authored
Merge pull request #447 from hack-a-chain-software/nft-transfers-new-field
refactor: added token id field in the transfers query for the case where isNft = true
2 parents 30b7c12 + 4176ab5 commit d5aed23

File tree

8 files changed

+1132
-26
lines changed

8 files changed

+1132
-26
lines changed

indexer/src/kadena-server/config/graphql-types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,8 @@ export type Transfer = Node & {
14341434
receiverAccount: Scalars['String']['output'];
14351435
requestKey: Scalars['String']['output'];
14361436
senderAccount: Scalars['String']['output'];
1437+
/** The token id if this is a poly-fungible transfer. */
1438+
tokenId?: Maybe<Scalars['String']['output']>;
14371439
/** The transaction that initiated this transfer. */
14381440
transaction?: Maybe<Transaction>;
14391441
};
@@ -3701,6 +3703,7 @@ export type TransferResolvers<
37013703
receiverAccount?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
37023704
requestKey?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
37033705
senderAccount?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
3706+
tokenId?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
37043707
transaction?: Resolver<Maybe<ResolversTypes['Transaction']>, ParentType, ContextType>;
37053708
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
37063709
};

indexer/src/kadena-server/config/schema.graphql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,11 @@ type Transfer implements Node {
10561056
receiverAccount: String!
10571057
requestKey: String!
10581058
senderAccount: String!
1059+
1060+
"""
1061+
The token id if this is a poly-fungible transfer.
1062+
"""
1063+
tokenId: String
10591064
"""
10601065
The transaction that initiated this transfer.
10611066
"""

indexer/src/kadena-server/repository/infra/repository/transfer-db-repository.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ export default class TransferDbRepository implements TransferRepository {
8585

8686
if (hasTokenId) {
8787
queryParams.push('marmalade-v2.ledger');
88-
queryParams.push('marmalade.ledger');
8988
const op = operator(queryParams.length);
89+
queryParams.push('marmalade.ledger');
9090
conditions += `\n${op} transfers.modulename IN ($${queryParams.length - 1}, $${queryParams.length})`;
9191
}
9292

@@ -157,7 +157,8 @@ export default class TransferDbRepository implements TransferRepository {
157157
transfers.modulehash as "moduleHash",
158158
transfers.requestkey as "requestKey",
159159
transfers."orderIndex" as "orderIndex",
160-
td.pactid as "pactId"
160+
td.pactid as "pactId",
161+
transfers."tokenId" as "tokenId"
161162
from filtered_block b
162163
join "Transactions" t on b.id = t."blockId"
163164
join "Transfers" transfers on transfers."transactionId" = t.id
@@ -192,7 +193,8 @@ export default class TransferDbRepository implements TransferRepository {
192193
transfers.modulehash as "moduleHash",
193194
transfers.requestkey as "requestKey",
194195
transfers."orderIndex" as "orderIndex",
195-
td.pactid as "pactId"
196+
td.pactid as "pactId",
197+
transfers."tokenId" as "tokenId"
196198
from filtered_transaction t
197199
join "Blocks" b on b.id = t."blockId"
198200
join "Transfers" transfers on transfers."transactionId" = t.id
@@ -216,7 +218,8 @@ export default class TransferDbRepository implements TransferRepository {
216218
transfers.modulehash as "moduleHash",
217219
transfers.requestkey as "requestKey",
218220
transfers."orderIndex" as "orderIndex",
219-
td.pactid as "pactId"
221+
td.pactid as "pactId",
222+
transfers."tokenId" as "tokenId"
220223
from "Transfers" transfers
221224
join "Transactions" t on t.id = transfers."transactionId"
222225
join "Blocks" b on b."id" = t."blockId"
@@ -430,7 +433,8 @@ export default class TransferDbRepository implements TransferRepository {
430433
transfers.modulehash as "moduleHash",
431434
transfers.requestkey as "requestKey",
432435
transfers."orderIndex" as "orderIndex",
433-
td.pactid as "pactId"
436+
td.pactid as "pactId",
437+
transfers."tokenId" as "tokenId"
434438
from "Blocks" b
435439
join "Transactions" transactions on b.id = transactions."blockId"
436440
join "Transfers" transfers on transfers."transactionId" = transactions.id

indexer/src/kadena-server/repository/infra/schema-validator/transfer-schema-validator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const schema = zod.object({
3636
senderAccount: zod.string(),
3737
requestKey: zod.string(),
3838
pactId: zod.string().nullable(),
39+
tokenId: zod.string().nullable().optional(),
3940
});
4041

4142
/**
@@ -94,6 +95,7 @@ function validate(row: any): TransferOutput {
9495
senderAccount: res.senderAccount,
9596
transferId: res.id.toString(),
9697
pactId: res.pactId,
98+
tokenId: res.tokenId,
9799
};
98100
}
99101

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { gql } from 'graphql-request';
2+
3+
export const getNftTransfersQuery = (params: any): string => {
4+
if (Object.keys(params).length === 0) {
5+
throw new Error('No parameters provided to getNftTransfersQuery.');
6+
}
7+
8+
const query = Object.entries(params)
9+
.map(([key, value]) => `${key}: ${typeof value === 'string' ? `"${value}"` : value}`)
10+
.join(', ');
11+
12+
const queryGql = gql`
13+
query {
14+
transfers(${query}) {
15+
pageInfo {
16+
endCursor
17+
hasNextPage
18+
hasPreviousPage
19+
startCursor
20+
}
21+
edges {
22+
cursor
23+
node {
24+
amount
25+
block {
26+
chainId
27+
}
28+
creationTime
29+
crossChainTransfer {
30+
id
31+
}
32+
id
33+
tokenId
34+
moduleHash
35+
moduleName
36+
orderIndex
37+
receiverAccount
38+
requestKey
39+
senderAccount
40+
transaction {
41+
id
42+
}
43+
}
44+
}
45+
}
46+
}
47+
`;
48+
49+
return queryGql;
50+
};

0 commit comments

Comments
 (0)