Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

fix: eth get block transaction count by hash to work with forks #3739

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/chains/ethereum/ethereum/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1274,14 +1274,12 @@ export default class EthereumApi implements Api {
@assertArgLength(1)
async eth_getBlockTransactionCountByHash(hash: DATA) {
const { blocks } = this.#blockchain;
const blockNum = await blocks.getNumberFromHash(hash);
if (!blockNum) return null;

const rawBlock = await blocks.getRawByBlockNumber(Quantity.from(blockNum));
if (!rawBlock) return null;

const [, rawTransactions] = decode<GanacheRawBlock>(rawBlock);
return Quantity.from(rawTransactions.length);
const block = await blocks
davidmurdoch marked this conversation as resolved.
Show resolved Hide resolved
.getByHash(hash)
.catch<Block>(_ => null);
if (!block) return null;
const transactions = block.getTransactions();
return Quantity.from(transactions.length);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/chains/ethereum/ethereum/tests/forking/block.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,12 @@ describe("forking", function () {
const block = await provider.send("eth_getBlockByNumber", ["0x0", true]);
assert.deepStrictEqual(block, block0);
});

it("should get transaction count by hash from the original chain", async () => {
const block = await provider.send("eth_getBlockByNumber", ["0xB443", true]);
const blockTransactionCountByHash = await provider.send("eth_getBlockTransactionCountByHash", [block.hash]);
assert.deepStrictEqual(block.transactions.length, parseInt(blockTransactionCountByHash));
});

});
});