This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +13
-8
lines changed
src/chains/ethereum/ethereum Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -1274,14 +1274,12 @@ export default class EthereumApi implements Api {
12741274 @assertArgLength ( 1 )
12751275 async eth_getBlockTransactionCountByHash ( hash : DATA ) {
12761276 const { blocks } = this . #blockchain;
1277- const blockNum = await blocks . getNumberFromHash ( hash ) ;
1278- if ( ! blockNum ) return null ;
1279-
1280- const rawBlock = await blocks . getRawByBlockNumber ( Quantity . from ( blockNum ) ) ;
1281- if ( ! rawBlock ) return null ;
1282-
1283- const [ , rawTransactions ] = decode < GanacheRawBlock > ( rawBlock ) ;
1284- return Quantity . from ( rawTransactions . length ) ;
1277+ const block = await blocks
1278+ . getByHash ( hash )
1279+ . catch < Block > ( _ => null ) ;
1280+ if ( ! block ) return null ;
1281+ const transactions = block . getTransactions ( ) ;
1282+ return Quantity . from ( transactions . length ) ;
12851283 }
12861284
12871285 /**
Original file line number Diff line number Diff line change @@ -84,5 +84,12 @@ describe("forking", function () {
8484 const block = await provider . send ( "eth_getBlockByNumber" , [ "0x0" , true ] ) ;
8585 assert . deepStrictEqual ( block , block0 ) ;
8686 } ) ;
87+
88+ it ( "should get transaction count by hash from the original chain" , async ( ) => {
89+ const block = await provider . send ( "eth_getBlockByNumber" , [ "0xB443" , true ] ) ;
90+ const blockTransactionCountByHash = await provider . send ( "eth_getBlockTransactionCountByHash" , [ block . hash ] ) ;
91+ assert . deepStrictEqual ( block . transactions . length , parseInt ( blockTransactionCountByHash ) ) ;
92+ } ) ;
93+
8794 } ) ;
8895} ) ;
You can’t perform that action at this time.
0 commit comments