Skip to content

Commit 6b3ef1b

Browse files
committed
WIP
1 parent 519ca35 commit 6b3ef1b

File tree

58 files changed

+13207
-19
lines changed

Some content is hidden

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

58 files changed

+13207
-19
lines changed

.github/workflows/indexer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
uses: actions/setup-node@v2
2020
with:
2121
node-version: '18'
22-
cache: 'yarn'
22+
cache: 'none'
2323

2424
- name: Install dependencies
2525
run: yarn install

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/application/transaction-repository.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export interface GetTransactionsByPublicKeyParams extends PaginationsParams {
88
publicKey: string;
99
}
1010

11+
export interface GetSignersParams {
12+
transactionId?: string;
13+
requestKey?: string;
14+
orderIndex?: string;
15+
}
16+
1117
export interface GetTransactionsCountParams {
1218
blockHash?: string | null;
1319
accountName?: string | null;
@@ -48,5 +54,5 @@ export default interface TransactionRepository {
4854
}>;
4955
getTransactionsByPublicKeyCount(publicKey: string): Promise<number>;
5056
getTransactionsByEventIds(eventIds: string[]): Promise<TransactionOutput[]>;
51-
getSigners(transactionId: string, orderIndex?: number): Promise<SignerOutput[]>;
57+
getSigners(params: GetSignersParams): Promise<SignerOutput[]>;
5258
}

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/transaction-db-repository.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { rootPgPool } from '../../../../config/database';
22
import TransactionRepository, {
3+
GetSignersParams,
34
GetTransactionsByPublicKeyParams,
45
GetTransactionsByRequestKey,
56
GetTransactionsCountParams,
@@ -626,8 +627,9 @@ export default class TransactionDbRepository implements TransactionRepository {
626627
return eventIds.map(eventId => transactionMap[eventId]) as TransactionOutput[];
627628
}
628629

629-
async getSigners(transactionId: string, orderIndex?: number) {
630-
const queryParams: Array<string | number> = [transactionId];
630+
async getSigners(params: GetSignersParams) {
631+
const { transactionId, requestKey, orderIndex } = params;
632+
const queryParams: Array<string | number> = [];
631633
let query = `
632634
SELECT s.pubkey as "publicKey",
633635
s.address as "address",
@@ -636,14 +638,24 @@ export default class TransactionDbRepository implements TransactionRepository {
636638
t.requestkey as "requestKey"
637639
FROM "Signers" s
638640
JOIN "Transactions" t on s."transactionId" = t.id
639-
WHERE t.id = $1
640641
`;
641642

643+
if (transactionId) {
644+
queryParams.push(transactionId);
645+
query += `\nWHERE t.id = $1`;
646+
}
647+
648+
if (requestKey) {
649+
queryParams.push(requestKey);
650+
query += `\nWHERE t.requestkey = $1`;
651+
}
652+
642653
if (orderIndex) {
643-
query += `\nAND s."orderIndex" = $2`;
644654
queryParams.push(orderIndex);
655+
query += `\nAND s."orderIndex" = $2`;
645656
}
646657

658+
console.log(query, queryParams);
647659
const { rows } = await rootPgPool.query(query, queryParams);
648660

649661
const output = rows.map(row => signerMetaValidator.validate(row));

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

Lines changed: 2 additions & 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",
@@ -199,6 +198,7 @@ export default class TransferDbRepository implements TransferRepository {
199198
`;
200199
}
201200

201+
console.log(query, queryParams);
202202
const { rows } = await rootPgPool.query(query, queryParams);
203203

204204
const edges = rows.map(row => ({

indexer/src/kadena-server/resolvers/fields/transaction-command/signers-transaction-command-resolver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export const signersTransactionCommandResolver: TransactionCommandResolvers<Reso
88
async (parent, _args, context) => {
99
const parentArgs = schema.parse(parent);
1010

11-
const output = await context.transactionRepository.getSigners(parentArgs.databaseTransactionId);
11+
const output = await context.transactionRepository.getSigners({
12+
transactionId: parentArgs.databaseTransactionId,
13+
});
1214
return output;
1315
};

indexer/src/kadena-server/resolvers/node-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const getNode = async (context: ResolverContext, id: string) => {
7676

7777
if (type === 'Signer') {
7878
const [requestKey, orderIndex] = JSON.parse(params);
79-
const [output] = await context.transactionRepository.getSigners(requestKey, orderIndex);
79+
const [output] = await context.transactionRepository.getSigners({ requestKey, orderIndex });
8080
return output;
8181
}
8282

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

0 commit comments

Comments
 (0)