From 28beff76107f762478e70974389eb75202a65d42 Mon Sep 17 00:00:00 2001 From: Antun Badurina Date: Thu, 21 Jul 2022 11:46:53 +0200 Subject: [PATCH] fix: revert default block to pending --- __tests__/defaultProvider.test.ts | 4 ++-- src/provider/default.ts | 10 +++++----- src/provider/rpc.ts | 12 ++++++------ src/provider/sequencer.ts | 12 ++++++------ src/utils/responseParser/rpc.ts | 16 +++------------- 5 files changed, 22 insertions(+), 32 deletions(-) diff --git a/__tests__/defaultProvider.test.ts b/__tests__/defaultProvider.test.ts index 3cbd84e2a..1779f7b48 100644 --- a/__tests__/defaultProvider.test.ts +++ b/__tests__/defaultProvider.test.ts @@ -33,7 +33,7 @@ describe('defaultProvider', () => { exampleTransactionHash = transaction_hash; exampleContractAddress = contract_address; - exampleBlock = await testProvider.getBlock(); + exampleBlock = await testProvider.getBlock('latest'); exampleBlockHash = exampleBlock.block_hash; exampleBlockNumber = exampleBlock.block_number; }); @@ -47,7 +47,7 @@ describe('defaultProvider', () => { return expect(testProvider.getBlock(exampleBlockHash)).resolves.not.toThrow(); }); - test('getBlock(blockHash=undefined, blockNumber=null)', async () => { + test('getBlock(blockIdentifier=latest)', async () => { expect(exampleBlock).not.toBeNull(); const { block_number, accepted_time } = exampleBlock; diff --git a/src/provider/default.ts b/src/provider/default.ts index 746504792..54a3b0979 100644 --- a/src/provider/default.ts +++ b/src/provider/default.ts @@ -45,20 +45,20 @@ export class Provider implements ProviderInterface { return this.provider.chainId; } - public async getBlock(blockIdentifier: BlockIdentifier = 'latest'): Promise { + public async getBlock(blockIdentifier: BlockIdentifier = 'pending'): Promise { return this.provider.getBlock(blockIdentifier); } public async getClassAt( contractAddress: string, - blockIdentifier: BlockIdentifier = 'latest' + blockIdentifier: BlockIdentifier = 'pending' ): Promise { return this.provider.getClassAt(contractAddress, blockIdentifier); } public async getEstimateFee( invocation: Invocation, - blockIdentifier: BlockIdentifier = 'latest', // 'pending' is not working on the RPC node + blockIdentifier: BlockIdentifier = 'pending', // 'pending' is not working on the RPC node invocationDetails: InvocationsDetails = {} ): Promise { return this.provider.getEstimateFee(invocation, blockIdentifier, invocationDetails); @@ -67,7 +67,7 @@ export class Provider implements ProviderInterface { public async getStorageAt( contractAddress: string, key: BigNumberish, - blockTagOrHash: BlockTag | BigNumberish = 'latest' + blockTagOrHash: BlockTag | BigNumberish = 'pending' ): Promise { return this.provider.getStorageAt(contractAddress, key, blockTagOrHash); } @@ -82,7 +82,7 @@ export class Provider implements ProviderInterface { public async callContract( request: Call, - blockIdentifier: BlockIdentifier = 'latest' + blockIdentifier: BlockIdentifier = 'pending' ): Promise { return this.provider.callContract(request, blockIdentifier); } diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts index a6404d7b8..871421257 100644 --- a/src/provider/rpc.ts +++ b/src/provider/rpc.ts @@ -90,7 +90,7 @@ export class RpcProvider implements ProviderInterface { return this.fetchEndpoint('starknet_chainId'); } - public async getBlock(blockIdentifier: BlockIdentifier = 'latest'): Promise { + public async getBlock(blockIdentifier: BlockIdentifier = 'pending'): Promise { const method = typeof blockIdentifier === 'string' && isHex(blockIdentifier) ? 'starknet_getBlockByHash' @@ -104,7 +104,7 @@ export class RpcProvider implements ProviderInterface { public async getStorageAt( contractAddress: string, key: BigNumberish, - blockHashOrTag: BlockTag | BigNumberish = 'latest' + blockHashOrTag: BlockTag | BigNumberish = 'pending' ): Promise { const parsedKey = toHex(toBN(key)); return this.fetchEndpoint('starknet_getStorageAt', [ @@ -128,14 +128,14 @@ export class RpcProvider implements ProviderInterface { public async getClassAt( contractAddress: string, - _blockIdentifier: BlockIdentifier = 'latest' + _blockIdentifier: BlockIdentifier = 'pending' ): Promise { return this.fetchEndpoint('starknet_getClassAt', [contractAddress]); } public async getEstimateFee( invocation: Invocation, - blockIdentifier: BlockIdentifier = 'latest', + blockIdentifier: BlockIdentifier = 'pending', invocationDetails: InvocationsDetails = {} ): Promise { return this.fetchEndpoint('starknet_estimateFee', [ @@ -200,7 +200,7 @@ export class RpcProvider implements ProviderInterface { public async callContract( call: Call, - blockIdentifier: BlockIdentifier = 'latest' + blockIdentifier: BlockIdentifier = 'pending' ): Promise { const result = await this.fetchEndpoint('starknet_call', [ { @@ -219,7 +219,7 @@ export class RpcProvider implements ProviderInterface { let retries = 100; while (!onchain) { - const successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2']; + const successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING']; const errorStates = ['REJECTED', 'NOT_RECEIVED']; // eslint-disable-next-line no-await-in-loop diff --git a/src/provider/sequencer.ts b/src/provider/sequencer.ts index e0c645dfc..1a12f68a1 100644 --- a/src/provider/sequencer.ts +++ b/src/provider/sequencer.ts @@ -204,7 +204,7 @@ export class SequencerProvider implements ProviderInterface { public async callContract( { contractAddress, entrypoint: entryPointSelector, calldata = [] }: Call, - blockIdentifier: BlockIdentifier = 'latest' + blockIdentifier: BlockIdentifier = 'pending' ): Promise { return this.fetchEndpoint( 'call_contract', @@ -218,7 +218,7 @@ export class SequencerProvider implements ProviderInterface { ).then(this.responseParser.parseCallContractResponse); } - public async getBlock(blockIdentifier: BlockIdentifier = 'latest'): Promise { + public async getBlock(blockIdentifier: BlockIdentifier = 'pending'): Promise { return this.fetchEndpoint('get_block', { blockIdentifier }).then( this.responseParser.parseGetBlockResponse ); @@ -227,7 +227,7 @@ export class SequencerProvider implements ProviderInterface { public async getStorageAt( contractAddress: string, key: BigNumberish, - blockHashOrTag: BlockTag | BigNumberish = 'latest' + blockHashOrTag: BlockTag | BigNumberish = 'pending' ): Promise { const parsedKey = toBN(key).toString(10); return this.fetchEndpoint('get_storage_at', { @@ -253,7 +253,7 @@ export class SequencerProvider implements ProviderInterface { public async getClassAt( contractAddress: string, - blockIdentifier: BlockIdentifier = 'latest' + blockIdentifier: BlockIdentifier = 'pending' ): Promise { return this.fetchEndpoint('get_full_contract', { blockIdentifier, contractAddress }).then( parseContract @@ -306,7 +306,7 @@ export class SequencerProvider implements ProviderInterface { public async getEstimateFee( invocation: Invocation, - blockIdentifier: BlockIdentifier = 'latest', + blockIdentifier: BlockIdentifier = 'pending', invocationDetails: InvocationsDetails = {} ): Promise { return this.fetchEndpoint( @@ -331,7 +331,7 @@ export class SequencerProvider implements ProviderInterface { // eslint-disable-next-line no-await-in-loop const res = await this.getTransactionStatus(txHash); - const successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2']; + const successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING']; const errorStates = ['REJECTED', 'NOT_RECEIVED']; if (successStates.includes(res.tx_status)) { diff --git a/src/utils/responseParser/rpc.ts b/src/utils/responseParser/rpc.ts index 987cd638f..9654f4815 100644 --- a/src/utils/responseParser/rpc.ts +++ b/src/utils/responseParser/rpc.ts @@ -51,19 +51,9 @@ export class RPCResponseParser extends ResponseParser { actual_fee: res.actual_fee, status: res.status, status_data: res.status_data, - messages_sent: res.messages_sent?.map(({ to_address, payload }) => ({ - to_address, - payload, - })), - l1_origin_message: res.l1_origin_message && { - from_address: res.l1_origin_message.from_address, - payload: res.l1_origin_message.payload, - }, - events: res.events.map(({ from_address, keys, data }) => ({ - from_address, - keys, - data, - })), + messages_sent: res.messages_sent, + l1_origin_message: res.l1_origin_message, + events: res.events, }; }