Skip to content

Commit

Permalink
Merge pull request #1 from Instadapp/batch-retry-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
KABBOUCHI authored Aug 31, 2023
2 parents f4059c2 + 9b1a808 commit 51c5017
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/providers/retry-provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JsonRpcProvider, StaticJsonRpcProvider } from '@ethersproject/providers'
import { JsonRpcProvider, StaticJsonRpcProvider, JsonRpcBatchProvider } from '@ethersproject/providers'
import { retry } from '../promises'

export class JsonRpcRetryProvider extends JsonRpcProvider {
Expand Down Expand Up @@ -26,6 +26,31 @@ export class JsonRpcRetryProvider extends JsonRpcProvider {
}
}

export class JsonRpcRetryBatchProvider extends JsonRpcBatchProvider {
timeouts: number[] = [5_000, 10_000, 15_000]
delay: number = 300

constructor (url: string, options?: { timeouts?: number[], delay?: number }) {
super(url)

if (options && options.timeouts) {
this.timeouts = options.timeouts
}

if (options && options.delay) {
this.delay = options.delay
}

Object.setPrototypeOf(this, JsonRpcRetryProvider.prototype)
}

public perform (method: string, params: any): Promise<any> {
const operation = () => super.perform(method, params)

return retry(operation, { timeouts: this.timeouts, delay: this.delay })
}
}

export class StaticJsonRpcRetryProvider extends StaticJsonRpcProvider {
timeouts: number[] = [5_000, 10_000, 15_000]
delay: number = 300
Expand Down

0 comments on commit 51c5017

Please sign in to comment.