2019-08-25 02:39:20 -04:00
|
|
|
"use strict";
|
|
|
|
// RetryProvider
|
|
|
|
//
|
|
|
|
// Wraps an existing Provider to provide retry logic.
|
|
|
|
//
|
|
|
|
// See: https://github.com/ethers-io/ethers.js/issues/427
|
|
|
|
import { ethers } from "ethers";
|
|
|
|
import { poll } from "@ethersproject/web";
|
|
|
|
import { version } from "./_version";
|
|
|
|
const logger = new ethers.utils.Logger(version);
|
|
|
|
export class RetryProvider extends ethers.providers.BaseProvider {
|
|
|
|
constructor(provider, options) {
|
|
|
|
logger.checkNew(new.target, RetryProvider);
|
|
|
|
super(provider.getNetwork());
|
|
|
|
ethers.utils.defineReadOnly(this, "provider", provider);
|
|
|
|
ethers.utils.defineReadOnly(this, "options", options || {});
|
|
|
|
}
|
|
|
|
perform(method, params) {
|
|
|
|
return poll(() => {
|
|
|
|
return this.provider.perform(method, params).then((result) => {
|
|
|
|
return result;
|
|
|
|
}, (error) => {
|
|
|
|
return undefined;
|
|
|
|
});
|
|
|
|
}, this.options);
|
|
|
|
}
|
|
|
|
}
|
2020-07-13 08:03:56 -04:00
|
|
|
//# sourceMappingURL=retry-provider.js.map
|