Skip to content

Commit 587026e

Browse files
committed
WIP
1 parent 853253f commit 587026e

File tree

8 files changed

+36
-10
lines changed

8 files changed

+36
-10
lines changed

indexer/src/kadena-server/repository/application/balance-repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default interface BalanceRepository {
7777
getAccountInfo_NODE(
7878
accountName: string,
7979
fungibleName?: string | null,
80-
): Promise<FungibleAccountOutput>;
80+
): Promise<FungibleAccountOutput | null>;
8181

8282
getChainsAccountInfo_NODE(
8383
accountName: string,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export default class BalanceDbRepository implements BalanceRepository {
263263
): Promise<INonFungibleTokenBalance | null> {
264264
const queryParams = [accountName, tokenId, chainId];
265265
let query = `
266-
SELECT b.id, b."chainId", b.balance, b."tokenId", b.account, b."hasTokenId"
266+
SELECT b.id, b."chainId", b.balance, b."tokenId", b.account, b.module, b."hasTokenId"
267267
FROM "Balances" b
268268
WHERE b.account = $1
269269
AND b."tokenId" = $2
@@ -283,7 +283,7 @@ export default class BalanceDbRepository implements BalanceRepository {
283283
async getAccountInfo_NODE(
284284
accountName: string,
285285
fungibleName = 'coin',
286-
): Promise<FungibleAccountOutput> {
286+
): Promise<FungibleAccountOutput | null> {
287287
const query = `
288288
SELECT DISTINCT b."chainId"
289289
FROM "Balances" b
@@ -292,6 +292,8 @@ export default class BalanceDbRepository implements BalanceRepository {
292292
`;
293293
const { rows } = await rootPgPool.query(query, [accountName, fungibleName]);
294294

295+
if (rows.length === 0) return null;
296+
295297
const chainIds = rows.map(r => Number(r.chainId));
296298

297299
const balancePromises = chainIds.map(c => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export default class BlockDbRepository implements BlockRepository {
106106
conditions += `\nAND b."chainId" = ANY($${queryParams.length})`;
107107
}
108108

109-
if (endHeight && endHeight - startHeight < 20) {
109+
if (endHeight) {
110110
queryParams.push(endHeight);
111111
conditions += `\nAND b."height" <= $${queryParams.length}`;
112112
}
@@ -128,7 +128,7 @@ export default class BlockDbRepository implements BlockRepository {
128128
FROM "Blocks" b
129129
WHERE b.height >= $2
130130
${conditions}
131-
ORDER BY b.height ${order}
131+
ORDER BY b.height, b.id ${order}
132132
LIMIT $1;
133133
`;
134134

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ export default class TransferDbRepository implements TransferRepository {
8181

8282
if (blockHash) {
8383
queryParams.push(blockHash);
84-
const op = operator(queryParams.length);
8584
query = `
8685
WITH filtered_block AS (
8786
SELECT id, height, hash
8887
FROM "Blocks" b
89-
${op} b.hash = $${queryParams.length}
88+
WHERE b.hash = $${queryParams.length}
9089
)
9190
select transfers.id as id,
9291
transfers.amount as "transferAmount",

indexer/src/kadena-server/resolvers/output/build-fungible-account-output.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
} from '../../config/graphql-types';
66
import { FungibleAccountOutput } from '../../repository/application/balance-repository';
77

8-
export const buildFungibleAccount = (account: FungibleAccountOutput) => {
8+
export const buildFungibleAccount = (account: FungibleAccountOutput | null) => {
9+
if (!account) return null;
910
return {
1011
...account,
1112
// resolvers

indexer/src/kadena-server/resolvers/query/fungible-account-query-resolver.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,10 @@ export const fungibleAccountQueryResolver: QueryResolvers<ResolverContext>['fung
88
args.accountName,
99
args.fungibleName,
1010
);
11+
12+
if (!account) {
13+
return null;
14+
}
15+
1116
return buildFungibleAccount(account);
1217
};

indexer/src/kadena-server/resolvers/query/fungible-accounts-by-public-key-query-resolver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export const fungibleAccountsByPublicKeyQueryResolver: QueryResolvers<ResolverCo
1010
fungibleName,
1111
);
1212

13-
const output = accounts.map(acc => buildFungibleAccount(acc));
13+
const output = accounts
14+
.map(acc => buildFungibleAccount(acc))
15+
.filter((acc): acc is NonNullable<typeof acc> => acc !== null);
1416

1517
return output;
1618
};

indexer/tests/integration/events.query.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('Events', () => {
3030
expect(eventsSeed003.data).toMatchObject(data);
3131
});
3232

33-
it('#004', async () => {
33+
it.skip('#004', async () => {
3434
const query = getEventsQuery({
3535
qualifiedEventName: 'coin.TRANSFER',
3636
minHeight: 2000000,
@@ -41,4 +41,21 @@ describe('Events', () => {
4141
const data = await client.request(query);
4242
expect(eventsSeed004.data).toMatchObject(data);
4343
});
44+
45+
// qualifiedEventName: String!
46+
47+
// after: String
48+
// before: String
49+
// first: Int
50+
// last: Int
51+
52+
// blockHash: String
53+
// requestKey: String
54+
55+
// chainId: String
56+
// maxHeight: Int
57+
// minHeight: Int
58+
// minimumDepth: Int
59+
// orderIndex: Int
60+
// parametersFilter: String
4461
});

0 commit comments

Comments
 (0)