Skip to content

Commit

Permalink
fix: add compute units to jsonrpc parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Sep 1, 2022
1 parent 31087b8 commit cb57f8f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions web3.js/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,8 @@ export type ParsedTransactionMeta = {
err: TransactionError | null;
/** The collection of addresses loaded using address lookup tables */
loadedAddresses?: LoadedAddresses;
/** The compute units consumed after processing the transaction */
computeUnitsConsumed?: number;
};

export type CompiledInnerInstruction = {
Expand Down Expand Up @@ -917,6 +919,8 @@ export type ConfirmedTransactionMeta = {
err: TransactionError | null;
/** The collection of addresses loaded using address lookup tables */
loadedAddresses?: LoadedAddresses;
/** The compute units consumed after processing the transaction */
computeUnitsConsumed?: number;
};

/**
Expand Down Expand Up @@ -1993,6 +1997,7 @@ const ConfirmedTransactionMetaResult = pick({
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
postTokenBalances: optional(nullable(array(TokenBalanceResult))),
loadedAddresses: optional(LoadedAddressesResult),
computeUnitsConsumed: optional(number()),
});

/**
Expand All @@ -2017,6 +2022,7 @@ const ParsedConfirmedTransactionMetaResult = pick({
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
postTokenBalances: optional(nullable(array(TokenBalanceResult))),
loadedAddresses: optional(LoadedAddressesResult),
computeUnitsConsumed: optional(number()),
});

const TransactionVersionStruct = union([literal(0), literal('legacy')]);
Expand Down
4 changes: 4 additions & 0 deletions web3.js/test/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4460,6 +4460,8 @@ describe('Connection', function () {
readonly: [],
writable: [lookupTableAddresses[0]],
});
expect(fetchedTransaction.meta?.computeUnitsConsumed).to.not.be
.undefined;
expect(
fetchedTransaction.transaction.message.addressTableLookups,
).to.eql(addressTableLookups);
Expand Down Expand Up @@ -4489,6 +4491,8 @@ describe('Connection', function () {
readonly: [],
writable: [lookupTableAddresses[0]],
});
expect(parsedTransaction?.meta?.computeUnitsConsumed).to.not.be
.undefined;
expect(
parsedTransaction?.transaction.message.addressTableLookups,
).to.eql(addressTableLookups);
Expand Down

0 comments on commit cb57f8f

Please sign in to comment.