Skip to content

Commit

Permalink
fix(RpcProvider): update of RpcProvider getBlock method to work with …
Browse files Browse the repository at this point in the history
…v0.3.0 of pathfinder
  • Loading branch information
_ committed Aug 19, 2022
1 parent a67af4a commit 3b12421
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
19 changes: 11 additions & 8 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,17 @@ export class RpcProvider implements ProviderInterface {
}

public async getBlock(blockIdentifier: BlockIdentifier = 'pending'): Promise<GetBlockResponse> {
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(
Expand Down
7 changes: 1 addition & 6 deletions src/types/api/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3b12421

Please sign in to comment.