aboutsummaryrefslogtreecommitdiffstats
path: root/packages/subproviders/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-04-06 14:46:27 +0800
committerFabio Berger <me@fabioberger.com>2018-04-06 14:46:27 +0800
commit22fa5a57a588c3c5c2a72ec5ef539797c2847688 (patch)
tree4ecfb7ff51b4f41213c571c13dcb55b650671b0f /packages/subproviders/src
parente30c76b7430d8518319eb7d90c7d70ef7c7f6c8d (diff)
downloaddexon-sol-tools-22fa5a57a588c3c5c2a72ec5ef539797c2847688.tar
dexon-sol-tools-22fa5a57a588c3c5c2a72ec5ef539797c2847688.tar.gz
dexon-sol-tools-22fa5a57a588c3c5c2a72ec5ef539797c2847688.tar.bz2
dexon-sol-tools-22fa5a57a588c3c5c2a72ec5ef539797c2847688.tar.lz
dexon-sol-tools-22fa5a57a588c3c5c2a72ec5ef539797c2847688.tar.xz
dexon-sol-tools-22fa5a57a588c3c5c2a72ec5ef539797c2847688.tar.zst
dexon-sol-tools-22fa5a57a588c3c5c2a72ec5ef539797c2847688.zip
Refactor RedundantRpcSubprovider into RedundantSubprovider
Diffstat (limited to 'packages/subproviders/src')
-rw-r--r--packages/subproviders/src/index.ts2
-rw-r--r--packages/subproviders/src/subproviders/redundant_subprovider.ts (renamed from packages/subproviders/src/subproviders/redundant_rpc.ts)25
2 files changed, 11 insertions, 16 deletions
diff --git a/packages/subproviders/src/index.ts b/packages/subproviders/src/index.ts
index 9786347e6..1711387f1 100644
--- a/packages/subproviders/src/index.ts
+++ b/packages/subproviders/src/index.ts
@@ -7,7 +7,7 @@ import { LedgerEthereumClient } from './types';
export { EmptyWalletSubprovider } from './subproviders/empty_wallet_subprovider';
export { FakeGasEstimateSubprovider } from './subproviders/fake_gas_estimate_subprovider';
export { InjectedWeb3Subprovider } from './subproviders/injected_web3';
-export { RedundantRPCSubprovider } from './subproviders/redundant_rpc';
+export { RedundantSubprovider } from './subproviders/redundant_subprovider';
export { LedgerSubprovider } from './subproviders/ledger';
export { GanacheSubprovider } from './subproviders/ganache';
export { Subprovider } from './subproviders/subprovider';
diff --git a/packages/subproviders/src/subproviders/redundant_rpc.ts b/packages/subproviders/src/subproviders/redundant_subprovider.ts
index f8ff0915d..37c8bba5a 100644
--- a/packages/subproviders/src/subproviders/redundant_rpc.ts
+++ b/packages/subproviders/src/subproviders/redundant_subprovider.ts
@@ -1,7 +1,6 @@
import { JSONRPCRequestPayload } from '@0xproject/types';
import { promisify } from '@0xproject/utils';
import * as _ from 'lodash';
-import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
import { Callback } from '../types';
@@ -12,17 +11,17 @@ import { Subprovider } from './subprovider';
* It attempts to handle each JSON RPC request by sequentially attempting to receive a valid response from one of a
* set of JSON RPC endpoints.
*/
-export class RedundantRPCSubprovider extends Subprovider {
- private _rpcs: RpcSubprovider[];
+export class RedundantSubprovider extends Subprovider {
+ private _subproviders: Subprovider[];
private static async _firstSuccessAsync(
- rpcs: RpcSubprovider[],
+ subproviders: Subprovider[],
payload: JSONRPCRequestPayload,
next: Callback,
): Promise<any> {
let lastErr: Error | undefined;
- for (const rpc of rpcs) {
+ for (const subprovider of subproviders) {
try {
- const data = await promisify(rpc.handleRequest.bind(rpc))(payload, next);
+ const data = await promisify(subprovider.handleRequest.bind(subprovider))(payload, next);
return data;
} catch (err) {
lastErr = err;
@@ -34,16 +33,12 @@ export class RedundantRPCSubprovider extends Subprovider {
}
}
/**
- * Instantiates a new RedundantRPCSubprovider
+ * Instantiates a new RedundantSubprovider
* @param endpoints JSON RPC endpoints to attempt. Attempts are made in the order of the endpoints.
*/
- constructor(endpoints: string[]) {
+ constructor(subproviders: Subprovider[]) {
super();
- this._rpcs = _.map(endpoints, endpoint => {
- return new RpcSubprovider({
- rpcUrl: endpoint,
- });
- });
+ this._subproviders = subproviders;
}
/**
* This method conforms to the web3-provider-engine interface.
@@ -59,9 +54,9 @@ export class RedundantRPCSubprovider extends Subprovider {
next: Callback,
end: (err: Error | null, data?: any) => void,
): Promise<void> {
- const rpcsCopy = this._rpcs.slice();
+ const subprovidersCopy = this._subproviders.slice();
try {
- const data = await RedundantRPCSubprovider._firstSuccessAsync(rpcsCopy, payload, next);
+ const data = await RedundantSubprovider._firstSuccessAsync(subprovidersCopy, payload, next);
end(null, data);
} catch (err) {
end(err);