From 3b124219dd25ef5a0c81583fcfe67d6a3cc5a70e Mon Sep 17 00:00:00 2001 From: _ <> Date: Fri, 19 Aug 2022 19:25:46 +0200 Subject: [PATCH] fix(RpcProvider): update of RpcProvider getBlock method to work with v0.3.0 of pathfinder --- src/provider/rpc.ts | 19 +++++++++++-------- src/types/api/rpc.ts | 7 +------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts index fea185158..8b351749b 100644 --- a/src/provider/rpc.ts +++ b/src/provider/rpc.ts @@ -90,14 +90,17 @@ export class RpcProvider implements ProviderInterface { } public async getBlock(blockIdentifier: BlockIdentifier = 'pending'): Promise { - const method = - typeof blockIdentifier === 'string' && isHex(blockIdentifier) - ? 'starknet_getBlockByHash' - : 'starknet_getBlockByNumber'; - - return this.fetchEndpoint(method, [blockIdentifier]).then( - this.responseParser.parseGetBlockResponse - ); + const method = 'starknet_getBlockWithTxHashes'; + if (typeof blockIdentifier === 'string' && isHex(blockIdentifier)) { + return this.fetchEndpoint(method, [{ block_hash: blockIdentifier }]).then( + this.responseParser.parseGetBlockResponse + ); + } + else { + return this.fetchEndpoint(method, [{ block_number: blockIdentifier }]).then( + this.responseParser.parseGetBlockResponse + ); + } } public async getStorageAt( diff --git a/src/types/api/rpc.ts b/src/types/api/rpc.ts index 2264f0a24..a9706e7cd 100644 --- a/src/types/api/rpc.ts +++ b/src/types/api/rpc.ts @@ -143,12 +143,7 @@ export namespace RPC { }; export type Methods = { - starknet_getBlockByHash: { - QUERY: never; - REQUEST: any[]; - RESPONSE: GetBlockResponse; - }; - starknet_getBlockByNumber: { + starknet_getBlockWithTxHashes: { QUERY: never; REQUEST: any[]; RESPONSE: GetBlockResponse;