Skip to content

Commit

Permalink
fix: revert default block to pending
Browse files Browse the repository at this point in the history
  • Loading branch information
badurinantun committed Jul 21, 2022
1 parent 9e708ba commit 28beff7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 32 deletions.
4 changes: 2 additions & 2 deletions __tests__/defaultProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/provider/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ export class Provider implements ProviderInterface {
return this.provider.chainId;
}

public async getBlock(blockIdentifier: BlockIdentifier = 'latest'): Promise<GetBlockResponse> {
public async getBlock(blockIdentifier: BlockIdentifier = 'pending'): Promise<GetBlockResponse> {
return this.provider.getBlock(blockIdentifier);
}

public async getClassAt(
contractAddress: string,
blockIdentifier: BlockIdentifier = 'latest'
blockIdentifier: BlockIdentifier = 'pending'
): Promise<any> {
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<EstimateFeeResponse> {
return this.provider.getEstimateFee(invocation, blockIdentifier, invocationDetails);
Expand All @@ -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<BigNumberish> {
return this.provider.getStorageAt(contractAddress, key, blockTagOrHash);
}
Expand All @@ -82,7 +82,7 @@ export class Provider implements ProviderInterface {

public async callContract(
request: Call,
blockIdentifier: BlockIdentifier = 'latest'
blockIdentifier: BlockIdentifier = 'pending'
): Promise<CallContractResponse> {
return this.provider.callContract(request, blockIdentifier);
}
Expand Down
12 changes: 6 additions & 6 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class RpcProvider implements ProviderInterface {
return this.fetchEndpoint('starknet_chainId');
}

public async getBlock(blockIdentifier: BlockIdentifier = 'latest'): Promise<GetBlockResponse> {
public async getBlock(blockIdentifier: BlockIdentifier = 'pending'): Promise<GetBlockResponse> {
const method =
typeof blockIdentifier === 'string' && isHex(blockIdentifier)
? 'starknet_getBlockByHash'
Expand All @@ -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<BigNumberish> {
const parsedKey = toHex(toBN(key));
return this.fetchEndpoint('starknet_getStorageAt', [
Expand All @@ -128,14 +128,14 @@ export class RpcProvider implements ProviderInterface {

public async getClassAt(
contractAddress: string,
_blockIdentifier: BlockIdentifier = 'latest'
_blockIdentifier: BlockIdentifier = 'pending'
): Promise<any> {
return this.fetchEndpoint('starknet_getClassAt', [contractAddress]);
}

public async getEstimateFee(
invocation: Invocation,
blockIdentifier: BlockIdentifier = 'latest',
blockIdentifier: BlockIdentifier = 'pending',
invocationDetails: InvocationsDetails = {}
): Promise<EstimateFeeResponse> {
return this.fetchEndpoint('starknet_estimateFee', [
Expand Down Expand Up @@ -200,7 +200,7 @@ export class RpcProvider implements ProviderInterface {

public async callContract(
call: Call,
blockIdentifier: BlockIdentifier = 'latest'
blockIdentifier: BlockIdentifier = 'pending'
): Promise<CallContractResponse> {
const result = await this.fetchEndpoint('starknet_call', [
{
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/provider/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class SequencerProvider implements ProviderInterface {

public async callContract(
{ contractAddress, entrypoint: entryPointSelector, calldata = [] }: Call,
blockIdentifier: BlockIdentifier = 'latest'
blockIdentifier: BlockIdentifier = 'pending'
): Promise<CallContractResponse> {
return this.fetchEndpoint(
'call_contract',
Expand All @@ -218,7 +218,7 @@ export class SequencerProvider implements ProviderInterface {
).then(this.responseParser.parseCallContractResponse);
}

public async getBlock(blockIdentifier: BlockIdentifier = 'latest'): Promise<GetBlockResponse> {
public async getBlock(blockIdentifier: BlockIdentifier = 'pending'): Promise<GetBlockResponse> {
return this.fetchEndpoint('get_block', { blockIdentifier }).then(
this.responseParser.parseGetBlockResponse
);
Expand All @@ -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<BigNumberish> {
const parsedKey = toBN(key).toString(10);
return this.fetchEndpoint('get_storage_at', {
Expand All @@ -253,7 +253,7 @@ export class SequencerProvider implements ProviderInterface {

public async getClassAt(
contractAddress: string,
blockIdentifier: BlockIdentifier = 'latest'
blockIdentifier: BlockIdentifier = 'pending'
): Promise<ContractClass> {
return this.fetchEndpoint('get_full_contract', { blockIdentifier, contractAddress }).then(
parseContract
Expand Down Expand Up @@ -306,7 +306,7 @@ export class SequencerProvider implements ProviderInterface {

public async getEstimateFee(
invocation: Invocation,
blockIdentifier: BlockIdentifier = 'latest',
blockIdentifier: BlockIdentifier = 'pending',
invocationDetails: InvocationsDetails = {}
): Promise<EstimateFeeResponse> {
return this.fetchEndpoint(
Expand All @@ -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)) {
Expand Down
16 changes: 3 additions & 13 deletions src/utils/responseParser/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down

0 comments on commit 28beff7

Please sign in to comment.