diff options
author | Fabio Berger <me@fabioberger.com> | 2018-04-12 07:56:13 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-04-12 07:56:13 +0800 |
commit | faedd2fa0b2582ea24ca4624e13ea7466de18408 (patch) | |
tree | b5e02ec65e8ae5298761f07eae18df145024bb16 /packages/subproviders/src | |
parent | 41bd0e30d6d0a18530e31133efe57d35e3360ebd (diff) | |
parent | c47fb8f9a83d409c092dd7449054fa16cf0fa1c9 (diff) | |
download | dexon-sol-tools-faedd2fa0b2582ea24ca4624e13ea7466de18408.tar dexon-sol-tools-faedd2fa0b2582ea24ca4624e13ea7466de18408.tar.gz dexon-sol-tools-faedd2fa0b2582ea24ca4624e13ea7466de18408.tar.bz2 dexon-sol-tools-faedd2fa0b2582ea24ca4624e13ea7466de18408.tar.lz dexon-sol-tools-faedd2fa0b2582ea24ca4624e13ea7466de18408.tar.xz dexon-sol-tools-faedd2fa0b2582ea24ca4624e13ea7466de18408.tar.zst dexon-sol-tools-faedd2fa0b2582ea24ca4624e13ea7466de18408.zip |
Merge branch 'development' into fix/docImprovements
* development: (31 commits)
Prettier ignore Metacoin artifacts
Publish
Updated CHANGELOGS
Improve deployer error message
Fix 0x.js tests
Fix lint issue
Simply export
Move NULL_BYTES to @0xproject/utils
Simplify the tests
Fix lint error
Add step to publishing that upload staging doc jsons, deploys staging website, opens every docs page and asks the dev to confirm that each one renders properly before publishing
Fix web3Wrapper build command
Add top-level `yarn lerna:stage_docs` to upload docJsons to the staging S3 bucket for all packages with a docs page
Refactor publish script to have it's main execution body be lean and discrete steps
Removed unused command
Remove 0x.js test artifacts
Fix tslint
Move migrations into separate monorepo subpackage and hook it up to 0x.js and contracts
Remove unused var
Refactor RedundantRpcSubprovider into RedundantSubprovider
...
# Conflicts:
# packages/react-docs/CHANGELOG.json
Diffstat (limited to 'packages/subproviders/src')
-rw-r--r-- | packages/subproviders/src/index.ts | 2 | ||||
-rw-r--r-- | packages/subproviders/src/subproviders/empty_wallet_subprovider.ts | 4 | ||||
-rw-r--r-- | packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts | 4 | ||||
-rw-r--r-- | packages/subproviders/src/subproviders/ganache.ts | 4 | ||||
-rw-r--r-- | packages/subproviders/src/subproviders/injected_web3.ts | 4 | ||||
-rw-r--r-- | packages/subproviders/src/subproviders/redundant_subprovider.ts (renamed from packages/subproviders/src/subproviders/redundant_rpc.ts) | 25 | ||||
-rw-r--r-- | packages/subproviders/src/subproviders/subprovider.ts | 18 |
7 files changed, 32 insertions, 29 deletions
diff --git a/packages/subproviders/src/index.ts b/packages/subproviders/src/index.ts index dd553fde4..b84473e45 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/empty_wallet_subprovider.ts b/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts index 595ec654d..8f152dc0a 100644 --- a/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts +++ b/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts @@ -17,8 +17,8 @@ export class EmptyWalletSubprovider extends Subprovider { * @param next Callback to call if this subprovider decides not to handle the request * @param end Callback to call if subprovider handled the request and wants to pass back the request. */ - // tslint:disable-next-line:prefer-function-over-method - public handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { + // tslint:disable-next-line:prefer-function-over-method async-suffix + public async handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { switch (payload.method) { case 'eth_accounts': end(null, []); diff --git a/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts b/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts index 966c37d8a..54fd7bcb9 100644 --- a/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts +++ b/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts @@ -31,8 +31,8 @@ export class FakeGasEstimateSubprovider extends Subprovider { * @param next Callback to call if this subprovider decides not to handle the request * @param end Callback to call if subprovider handled the request and wants to pass back the request. */ - // tslint:disable-next-line:prefer-function-over-method - public handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { + // tslint:disable-next-line:prefer-function-over-method async-suffix + public async handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { switch (payload.method) { case 'eth_estimateGas': end(null, this._constantGasAmount); diff --git a/packages/subproviders/src/subproviders/ganache.ts b/packages/subproviders/src/subproviders/ganache.ts index 8008d1b4b..debd7ecf0 100644 --- a/packages/subproviders/src/subproviders/ganache.ts +++ b/packages/subproviders/src/subproviders/ganache.ts @@ -27,8 +27,8 @@ export class GanacheSubprovider extends Subprovider { * @param next Callback to call if this subprovider decides not to handle the request * @param end Callback to call if subprovider handled the request and wants to pass back the request. */ - // tslint:disable-next-line:prefer-function-over-method - public handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { + // tslint:disable-next-line:prefer-function-over-method async-suffix + public async handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { this._ganacheProvider.sendAsync(payload, (err: Error | null, result: any) => { end(err, result && result.result); }); diff --git a/packages/subproviders/src/subproviders/injected_web3.ts b/packages/subproviders/src/subproviders/injected_web3.ts index 1d7b2ddfe..3ca0c4bd0 100644 --- a/packages/subproviders/src/subproviders/injected_web3.ts +++ b/packages/subproviders/src/subproviders/injected_web3.ts @@ -30,8 +30,8 @@ export class InjectedWeb3Subprovider extends Subprovider { * @param next Callback to call if this subprovider decides not to handle the request * @param end Callback to call if subprovider handled the request and wants to pass back the request. */ - // tslint:disable-next-line:prefer-function-over-method - public handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { + // tslint:disable-next-line:prefer-function-over-method async-suffix + public async handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { switch (payload.method) { case 'web3_clientVersion': this._injectedWeb3.version.getNode(end); 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); diff --git a/packages/subproviders/src/subproviders/subprovider.ts b/packages/subproviders/src/subproviders/subprovider.ts index c51462f07..2118f52c8 100644 --- a/packages/subproviders/src/subproviders/subprovider.ts +++ b/packages/subproviders/src/subproviders/subprovider.ts @@ -2,13 +2,14 @@ import { JSONRPCRequestPayload, JSONRPCResponsePayload } from '@0xproject/types' import { promisify } from '@0xproject/utils'; import * as Web3 from 'web3'; -import { JSONRPCRequestPayloadWithMethod } from '../types'; +import { Callback, ErrorCallback, JSONRPCRequestPayloadWithMethod } from '../types'; /** * A altered version of the base class Subprovider found in [web3-provider-engine](https://github.com/MetaMask/provider-engine). * This one has an async/await `emitPayloadAsync` and also defined types. */ -export class Subprovider { - private _engine: any; +export abstract class Subprovider { + // tslint:disable-next-line:underscore-private-and-protected + private engine: any; // Ported from: https://github.com/MetaMask/provider-engine/blob/master/util/random-id.js private static _getRandomId() { const extraDigits = 3; @@ -31,6 +32,13 @@ export class Subprovider { }; return finalPayload; } + // tslint:disable-next-line:async-suffix + public abstract async handleRequest( + payload: JSONRPCRequestPayload, + next: Callback, + end: ErrorCallback, + ): Promise<void>; + /** * Emits a JSON RPC payload that will then be handled by the ProviderEngine instance * this subprovider is a part of. The payload will cascade down the subprovider middleware @@ -40,7 +48,7 @@ export class Subprovider { */ public async emitPayloadAsync(payload: Partial<JSONRPCRequestPayloadWithMethod>): Promise<JSONRPCResponsePayload> { const finalPayload = Subprovider._createFinalPayload(payload); - const response = await promisify<JSONRPCResponsePayload>(this._engine.sendAsync, this._engine)(finalPayload); + const response = await promisify<JSONRPCResponsePayload>(this.engine.sendAsync, this.engine)(finalPayload); return response; } /** @@ -49,6 +57,6 @@ export class Subprovider { * directly. */ public setEngine(engine: any): void { - this._engine = engine; + this.engine = engine; } } |