Skip to content

Commit

Permalink
feat: rpc optionsOrProvider extend with retries
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Sep 16, 2022
1 parent 0ab5769 commit 46f9634
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import { randomAddress } from '../utils/stark';
import { ProviderInterface } from './interface';
import { Block, BlockIdentifier } from './utils';

export type RpcProviderOptions = { nodeUrl: string };
type Options = { retries: number };
export type RpcProviderOptions = {
nodeUrl: string;
retries?: number;
};

export class RpcProvider implements ProviderInterface {
public nodeUrl: string;
Expand All @@ -42,12 +44,12 @@ export class RpcProvider implements ProviderInterface {

private responseParser = new RPCResponseParser();

private options: Options;
private retries: number;

constructor(optionsOrProvider: RpcProviderOptions, options: Options) {
const { nodeUrl } = optionsOrProvider;
constructor(optionsOrProvider: RpcProviderOptions) {
const { nodeUrl, retries } = optionsOrProvider;
this.nodeUrl = nodeUrl;
this.options = options;
this.retries = retries || 200;

this.getChainId().then((chainId) => {
this.chainId = chainId;
Expand Down Expand Up @@ -298,7 +300,7 @@ export class RpcProvider implements ProviderInterface {
}

public async waitForTransaction(txHash: string, retryInterval: number = 8000) {
let retries = this.options?.retries || 200;
let { retries } = this;
let onchain = false;

while (!onchain) {
Expand Down

0 comments on commit 46f9634

Please sign in to comment.