Skip to content

Commit 40ce2d7

Browse files
authored
Merge pull request #430 from hack-a-chain-software/total-gas-used-graphql
feat: added total gas used in block type of graphql
2 parents 16c3b8c + 9116662 commit 40ce2d7

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export type Block = Node & {
5252
/** The proof of work hash. */
5353
powHash: Scalars['String']['output'];
5454
target: Scalars['String']['output'];
55+
totalGasUsed: Scalars['Decimal']['output'];
5556
/** Default page size is 20. */
5657
transactions: BlockTransactionsConnection;
5758
weight: Scalars['String']['output'];
@@ -2104,6 +2105,7 @@ export type BlockResolvers<
21042105
payloadHash?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
21052106
powHash?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
21062107
target?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
2108+
totalGasUsed?: Resolver<ResolversTypes['Decimal'], ParentType, ContextType>;
21072109
transactions?: Resolver<
21082110
ResolversTypes['BlockTransactionsConnection'],
21092111
ParentType,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ type Block implements Node {
627627
canonical: Boolean!
628628

629629
parent: Block @complexity(value: 1)
630+
totalGasUsed: Decimal!
630631
"""
631632
Default page size is 20.
632633
"""

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ export default class BlockDbRepository implements BlockRepository {
285285
b.adjacents as "adjacents",
286286
b.parent as "parent",
287287
b.canonical as "canonical",
288-
b."transactionsCount" as "transactionsCount"
288+
b."transactionsCount" as "transactionsCount",
289+
b."totalGasUsed" as "totalGasUsed"
289290
FROM "Blocks" b
290291
WHERE b.height ${before ? '<=' : '>='} $2
291292
${conditions}
@@ -574,7 +575,8 @@ export default class BlockDbRepository implements BlockRepository {
574575
b.parent as "parent",
575576
b.canonical as "canonical",
576577
t.id as "transactionId",
577-
b."transactionsCount" as "transactionsCount"
578+
b."transactionsCount" as "transactionsCount",
579+
b."totalGasUsed" as "totalGasUsed"
578580
FROM "Blocks" b
579581
JOIN "Transactions" t ON b.id = t."blockId"
580582
WHERE t.id = ANY($1::int[])`,
@@ -623,7 +625,8 @@ export default class BlockDbRepository implements BlockRepository {
623625
b.adjacents as "adjacents",
624626
b.parent as "parent",
625627
b.canonical as "canonical",
626-
b."transactionsCount" as "transactionsCount"
628+
b."transactionsCount" as "transactionsCount",
629+
b."totalGasUsed" as "totalGasUsed"
627630
FROM "Blocks" b
628631
WHERE b.hash = ANY($1::text[])`,
629632
[hashes],

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const schema = zod.object({
4343
coinbase: zod.any(),
4444
canonical: zod.boolean().nullable(),
4545
transactionsCount: zod.number(),
46+
totalGasUsed: zod.string().nullable(),
4647
});
4748

4849
/**
@@ -100,6 +101,7 @@ const validate = (row: any): BlockOutput => {
100101
})),
101102
numTransactions: res.transactionsCount,
102103
blockId: res.id,
104+
totalGasUsed: res.totalGasUsed ?? '0',
103105
};
104106
};
105107

@@ -137,6 +139,7 @@ const mapFromSequelize = (blockModel: BlockAttributes): BlockOutput => {
137139
})),
138140
numTransactions: blockModel.transactionsCount,
139141
blockId: blockModel.id,
142+
totalGasUsed: blockModel.totalGasUsed ?? '0',
140143
};
141144
};
142145

0 commit comments

Comments
 (0)