From 49f1a6933cc22d1e703d631d5b861b8601ca2231 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 12 Jul 2018 23:13:47 +0200 Subject: Add fetchAsync util and RPCSubprovider --- packages/subproviders/package.json | 1 + packages/subproviders/src/globals.d.ts | 2 + packages/subproviders/src/index.ts | 1 + .../src/subproviders/rpc_subprovider.ts | 88 ++++++++++++++++++++++ .../subproviders/src/subproviders/subprovider.ts | 26 +++---- 5 files changed, 105 insertions(+), 13 deletions(-) create mode 100644 packages/subproviders/src/subproviders/rpc_subprovider.ts (limited to 'packages/subproviders') diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json index bdc846e6b..796d87cf4 100644 --- a/packages/subproviders/package.json +++ b/packages/subproviders/package.json @@ -55,6 +55,7 @@ "ethereumjs-util": "^5.1.1", "ganache-core": "0xProject/ganache-core", "hdkey": "^0.7.1", + "json-rpc-error": "2.0.0", "lodash": "^4.17.4", "semaphore-async-await": "^1.5.1", "web3-provider-engine": "14.0.6" diff --git a/packages/subproviders/src/globals.d.ts b/packages/subproviders/src/globals.d.ts index 94e63a32d..6af4c7980 100644 --- a/packages/subproviders/src/globals.d.ts +++ b/packages/subproviders/src/globals.d.ts @@ -4,3 +4,5 @@ declare module '*.json' { export default json; /* tslint:enable */ } + +declare module 'json-rpc-error'; diff --git a/packages/subproviders/src/index.ts b/packages/subproviders/src/index.ts index 71d643f14..9a5597a06 100644 --- a/packages/subproviders/src/index.ts +++ b/packages/subproviders/src/index.ts @@ -10,6 +10,7 @@ export { FakeGasEstimateSubprovider } from './subproviders/fake_gas_estimate_sub export { SignerSubprovider } from './subproviders/signer'; export { RedundantSubprovider } from './subproviders/redundant_subprovider'; export { LedgerSubprovider } from './subproviders/ledger'; +export { RPCSubprovider } from './subproviders/rpc_subprovider'; export { GanacheSubprovider } from './subproviders/ganache'; export { Subprovider } from './subproviders/subprovider'; export { NonceTrackerSubprovider } from './subproviders/nonce_tracker'; diff --git a/packages/subproviders/src/subproviders/rpc_subprovider.ts b/packages/subproviders/src/subproviders/rpc_subprovider.ts new file mode 100644 index 000000000..87c522271 --- /dev/null +++ b/packages/subproviders/src/subproviders/rpc_subprovider.ts @@ -0,0 +1,88 @@ +import { assert } from '@0xproject/assert'; +import { StatusCodes } from '@0xproject/types'; +import { fetchAsync } from '@0xproject/utils'; +import { JSONRPCRequestPayload } from 'ethereum-types'; +import JsonRpcError = require('json-rpc-error'); + +import { Callback, ErrorCallback } from '../types'; + +import { Subprovider } from './subprovider'; + +/** + * This class implements the [web3-provider-engine](https://github.com/MetaMask/provider-engine) subprovider interface. + * It forwards on JSON RPC requests to the supplied `rpcUrl` endpoint + */ +export class RPCSubprovider extends Subprovider { + private _rpcUrl: string; + constructor(rpcUrl: string) { + super(); + assert.isString('rpcUrl', rpcUrl); + this._rpcUrl = rpcUrl; + } + /** + * This method conforms to the web3-provider-engine interface. + * It is called internally by the ProviderEngine when it is this subproviders + * turn to handle a JSON RPC request. + * @param payload JSON RPC payload + * @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 async-suffix + public async handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback): Promise { + const finalPayload = Subprovider.createFinalPayload(payload); + const headers = new Headers({ + Accept: 'application/json', + 'Content-Type': 'application/json', + }); + const timeoutMs = 1000; + + let response; + try { + response = await fetchAsync( + this._rpcUrl, + { + method: 'POST', + headers, + body: JSON.stringify(finalPayload), + }, + timeoutMs, + ); + } catch (err) { + end(new JsonRpcError.InternalError(err)); + return; + } + + const text = await response.text(); + if (!response.ok) { + const statusCode = response.status; + switch (statusCode) { + case StatusCodes.MethodNotAllowed: + end(new JsonRpcError.MethodNotFound()); + return; + case StatusCodes.GatewayTimeout: + const errMsg = + 'Gateway timeout. The request took too long to process. This can happen when querying logs over too wide a block range.'; + const err = new Error(errMsg); + end(new JsonRpcError.InternalError(err)); + return; + default: + end(new JsonRpcError.InternalError(text)); + return; + } + } + + let data; + try { + data = JSON.parse(text); + } catch (err) { + end(new JsonRpcError.InternalError(err)); + return; + } + + if (data.error) { + end(data.error); + return; + } + end(null, data.result); + } +} diff --git a/packages/subproviders/src/subproviders/subprovider.ts b/packages/subproviders/src/subproviders/subprovider.ts index ff8378c4e..6f4a8f99e 100644 --- a/packages/subproviders/src/subproviders/subprovider.ts +++ b/packages/subproviders/src/subproviders/subprovider.ts @@ -9,18 +9,7 @@ import { Callback, ErrorCallback, JSONRPCRequestPayloadWithMethod } from '../typ export abstract class Subprovider { // tslint:disable-next-line:underscore-private-and-protected private engine!: Provider; - // Ported from: https://github.com/MetaMask/provider-engine/blob/master/util/random-id.js - private static _getRandomId(): number { - const extraDigits = 3; - const baseTen = 10; - // 13 time digits - const datePart = new Date().getTime() * Math.pow(baseTen, extraDigits); - // 3 random digits - const extraPart = Math.floor(Math.random() * Math.pow(baseTen, extraDigits)); - // 16 digits - return datePart + extraPart; - } - private static _createFinalPayload( + public static createFinalPayload( payload: Partial, ): Partial { const finalPayload = { @@ -32,6 +21,17 @@ export abstract class Subprovider { }; return finalPayload; } + // Ported from: https://github.com/MetaMask/provider-engine/blob/master/util/random-id.js + private static _getRandomId(): number { + const extraDigits = 3; + const baseTen = 10; + // 13 time digits + const datePart = new Date().getTime() * Math.pow(baseTen, extraDigits); + // 3 random digits + const extraPart = Math.floor(Math.random() * Math.pow(baseTen, extraDigits)); + // 16 digits + return datePart + extraPart; + } // tslint:disable-next-line:async-suffix public abstract async handleRequest( payload: JSONRPCRequestPayload, @@ -47,7 +47,7 @@ export abstract class Subprovider { * @returns JSON RPC response payload */ public async emitPayloadAsync(payload: Partial): Promise { - const finalPayload = Subprovider._createFinalPayload(payload); + const finalPayload = Subprovider.createFinalPayload(payload); const response = await promisify(this.engine.sendAsync, this.engine)(finalPayload); return response; } -- cgit v1.2.3 From c2a1317c3813b13353eb84e4255284fe99ff8e6c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 12 Jul 2018 23:17:35 +0200 Subject: Adjust timeout --- packages/subproviders/src/subproviders/rpc_subprovider.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'packages/subproviders') diff --git a/packages/subproviders/src/subproviders/rpc_subprovider.ts b/packages/subproviders/src/subproviders/rpc_subprovider.ts index 87c522271..0fb99f87a 100644 --- a/packages/subproviders/src/subproviders/rpc_subprovider.ts +++ b/packages/subproviders/src/subproviders/rpc_subprovider.ts @@ -34,8 +34,10 @@ export class RPCSubprovider extends Subprovider { Accept: 'application/json', 'Content-Type': 'application/json', }); - const timeoutMs = 1000; + // Since Ethereum nodes have a proclivity for accepting requests and never + // returning a response, we set this quite low (10 seconds). + const timeoutMs = 10000; let response; try { response = await fetchAsync( -- cgit v1.2.3 From 1229c61ba420b280708b39c04cc21f31e43ed3cf Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 12:05:02 +0200 Subject: Make timeout configurable on RPCSubprovider --- packages/subproviders/src/subproviders/rpc_subprovider.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'packages/subproviders') diff --git a/packages/subproviders/src/subproviders/rpc_subprovider.ts b/packages/subproviders/src/subproviders/rpc_subprovider.ts index 0fb99f87a..5c1c3272c 100644 --- a/packages/subproviders/src/subproviders/rpc_subprovider.ts +++ b/packages/subproviders/src/subproviders/rpc_subprovider.ts @@ -14,10 +14,12 @@ import { Subprovider } from './subprovider'; */ export class RPCSubprovider extends Subprovider { private _rpcUrl: string; - constructor(rpcUrl: string) { + private _requestTimeoutMs: number; + constructor(rpcUrl: string, requestTimeoutMs: number = 20000) { super(); assert.isString('rpcUrl', rpcUrl); this._rpcUrl = rpcUrl; + this._requestTimeoutMs = requestTimeoutMs; } /** * This method conforms to the web3-provider-engine interface. @@ -35,9 +37,6 @@ export class RPCSubprovider extends Subprovider { 'Content-Type': 'application/json', }); - // Since Ethereum nodes have a proclivity for accepting requests and never - // returning a response, we set this quite low (10 seconds). - const timeoutMs = 10000; let response; try { response = await fetchAsync( @@ -47,7 +46,7 @@ export class RPCSubprovider extends Subprovider { headers, body: JSON.stringify(finalPayload), }, - timeoutMs, + this._requestTimeoutMs, ); } catch (err) { end(new JsonRpcError.InternalError(err)); -- cgit v1.2.3 From 2e5ff53d7271509accc226e83d76d1785350b1d2 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 12:42:01 +0200 Subject: -fetch'; --- packages/subproviders/test/integration/ledger_subprovider_test.ts | 7 ++----- packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) (limited to 'packages/subproviders') diff --git a/packages/subproviders/test/integration/ledger_subprovider_test.ts b/packages/subproviders/test/integration/ledger_subprovider_test.ts index 196cecf32..e5233fdbc 100644 --- a/packages/subproviders/test/integration/ledger_subprovider_test.ts +++ b/packages/subproviders/test/integration/ledger_subprovider_test.ts @@ -8,9 +8,8 @@ import * as chai from 'chai'; import { JSONRPCResponsePayload } from 'ethereum-types'; import * as ethUtils from 'ethereumjs-util'; import Web3ProviderEngine = require('web3-provider-engine'); -import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); -import { LedgerSubprovider } from '../../src'; +import { LedgerSubprovider, RPCSubprovider } from '../../src'; import { LedgerEthereumClient } from '../../src/types'; import { chaiSetup } from '../chai_setup'; import { fixtureData } from '../utils/fixture_data'; @@ -86,9 +85,7 @@ describe('LedgerSubprovider', () => { before(() => { ledgerProvider = new Web3ProviderEngine(); ledgerProvider.addProvider(ledgerSubprovider); - const httpProvider = new RpcSubprovider({ - rpcUrl: 'http://localhost:8545', - }); + const httpProvider = new RPCSubprovider('http://localhost:8545'); ledgerProvider.addProvider(httpProvider); ledgerProvider.start(); diff --git a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts index 810fb8f45..e3f204b15 100644 --- a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts +++ b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts @@ -3,9 +3,8 @@ import * as chai from 'chai'; import { JSONRPCResponsePayload } from 'ethereum-types'; import * as Sinon from 'sinon'; import Web3ProviderEngine = require('web3-provider-engine'); -import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); -import { RedundantSubprovider } from '../../src'; +import { RedundantSubprovider, RPCSubprovider } from '../../src'; import { Subprovider } from '../../src/subproviders/subprovider'; import { chaiSetup } from '../chai_setup'; import { ganacheSubprovider } from '../utils/ganache_subprovider'; @@ -39,9 +38,7 @@ describe('RedundantSubprovider', () => { }); it('succeeds when supplied at least one healthy endpoint', (done: DoneCallback) => { provider = new Web3ProviderEngine(); - const nonExistentSubprovider = new RpcSubprovider({ - rpcUrl: 'http://does-not-exist:3000', - }); + const nonExistentSubprovider = new RPCSubprovider('http://does-not-exist:3000'); const handleRequestStub = Sinon.stub(nonExistentSubprovider, 'handleRequest').throws( new Error('REQUEST_FAILED'), ); -- cgit v1.2.3 From 701ea5c46bb1d25ffc2e6962042ba3e0c0277454 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 13:05:21 +0200 Subject: Add typedoc for json-rpc-error package --- packages/subproviders/src/globals.d.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'packages/subproviders') diff --git a/packages/subproviders/src/globals.d.ts b/packages/subproviders/src/globals.d.ts index 6af4c7980..837ed287d 100644 --- a/packages/subproviders/src/globals.d.ts +++ b/packages/subproviders/src/globals.d.ts @@ -5,4 +5,12 @@ declare module '*.json' { /* tslint:enable */ } -declare module 'json-rpc-error'; +// TODO: Move this to `typescript-typings` once it is more fleshed out +declare module 'json-rpc-error' { + export class InternalError extends Error { + constructor(err: Error | string); + } + export class MethodNotFound extends Error { + constructor(); + } +} -- cgit v1.2.3 From 512502ca0873a290accb53777ca9d93f8d28e84b Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 14:26:02 +0200 Subject: Export Web3ProviderEngine from subproviders package --- packages/subproviders/src/index.ts | 1 + packages/subproviders/src/utils/subprovider_utils.ts | 4 ++-- packages/subproviders/test/integration/ledger_subprovider_test.ts | 3 +-- packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts | 3 +-- packages/subproviders/test/unit/ledger_subprovider_test.ts | 3 +-- packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts | 3 +-- packages/subproviders/test/unit/nonce_tracker_subprovider_test.ts | 3 +-- .../subproviders/test/unit/private_key_wallet_subprovider_test.ts | 3 +-- packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts | 3 +-- 9 files changed, 10 insertions(+), 16 deletions(-) (limited to 'packages/subproviders') diff --git a/packages/subproviders/src/index.ts b/packages/subproviders/src/index.ts index 9a5597a06..9d4480e59 100644 --- a/packages/subproviders/src/index.ts +++ b/packages/subproviders/src/index.ts @@ -1,5 +1,6 @@ import Eth from '@ledgerhq/hw-app-eth'; import TransportU2F from '@ledgerhq/hw-transport-u2f'; +export import Web3ProviderEngine = require('web3-provider-engine'); export { ECSignature } from '@0xproject/types'; import { LedgerEthereumClient } from './types'; diff --git a/packages/subproviders/src/utils/subprovider_utils.ts b/packages/subproviders/src/utils/subprovider_utils.ts index 24ebedd06..beda408ab 100644 --- a/packages/subproviders/src/utils/subprovider_utils.ts +++ b/packages/subproviders/src/utils/subprovider_utils.ts @@ -1,4 +1,4 @@ -import ProviderEngine = require('web3-provider-engine'); +import Web3ProviderEngine = require('web3-provider-engine'); import { Subprovider } from '../subproviders/subprovider'; @@ -7,7 +7,7 @@ import { Subprovider } from '../subproviders/subprovider'; * @param provider Given provider * @param subprovider Subprovider to prepend */ -export function prependSubprovider(provider: ProviderEngine, subprovider: Subprovider): void { +export function prependSubprovider(provider: Web3ProviderEngine, subprovider: Subprovider): void { subprovider.setEngine(provider); // HACK: We use implementation details of provider engine here // https://github.com/MetaMask/provider-engine/blob/master/index.js#L68 diff --git a/packages/subproviders/test/integration/ledger_subprovider_test.ts b/packages/subproviders/test/integration/ledger_subprovider_test.ts index e5233fdbc..103e8f952 100644 --- a/packages/subproviders/test/integration/ledger_subprovider_test.ts +++ b/packages/subproviders/test/integration/ledger_subprovider_test.ts @@ -7,9 +7,8 @@ import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'; import * as chai from 'chai'; import { JSONRPCResponsePayload } from 'ethereum-types'; import * as ethUtils from 'ethereumjs-util'; -import Web3ProviderEngine = require('web3-provider-engine'); -import { LedgerSubprovider, RPCSubprovider } from '../../src'; +import { LedgerSubprovider, RPCSubprovider, Web3ProviderEngine } from '../../src'; import { LedgerEthereumClient } from '../../src/types'; import { chaiSetup } from '../chai_setup'; import { fixtureData } from '../utils/fixture_data'; diff --git a/packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts b/packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts index f17c21f02..063817a95 100644 --- a/packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts +++ b/packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts @@ -2,9 +2,8 @@ import * as chai from 'chai'; import * as lightwallet from 'eth-lightwallet'; import { JSONRPCResponsePayload } from 'ethereum-types'; import * as ethUtils from 'ethereumjs-util'; -import Web3ProviderEngine = require('web3-provider-engine'); -import { EthLightwalletSubprovider } from '../../src'; +import { EthLightwalletSubprovider, Web3ProviderEngine } from '../../src'; import { DoneCallback } from '../../src/types'; import { chaiSetup } from '../chai_setup'; import { fixtureData } from '../utils/fixture_data'; diff --git a/packages/subproviders/test/unit/ledger_subprovider_test.ts b/packages/subproviders/test/unit/ledger_subprovider_test.ts index 3b57e125b..edff5144e 100644 --- a/packages/subproviders/test/unit/ledger_subprovider_test.ts +++ b/packages/subproviders/test/unit/ledger_subprovider_test.ts @@ -2,9 +2,8 @@ import * as chai from 'chai'; import { JSONRPCResponsePayload } from 'ethereum-types'; import * as ethUtils from 'ethereumjs-util'; import * as _ from 'lodash'; -import Web3ProviderEngine = require('web3-provider-engine'); -import { LedgerSubprovider } from '../../src'; +import { LedgerSubprovider, Web3ProviderEngine } from '../../src'; import { DoneCallback, LedgerCommunicationClient, diff --git a/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts b/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts index 51ba7094c..f2bdda3cd 100644 --- a/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts +++ b/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts @@ -1,9 +1,8 @@ import * as chai from 'chai'; import { JSONRPCResponsePayload } from 'ethereum-types'; import * as ethUtils from 'ethereumjs-util'; -import Web3ProviderEngine = require('web3-provider-engine'); -import { GanacheSubprovider, MnemonicWalletSubprovider } from '../../src/'; +import { GanacheSubprovider, MnemonicWalletSubprovider, Web3ProviderEngine } from '../../src/'; import { DoneCallback, WalletSubproviderErrors } from '../../src/types'; import { chaiSetup } from '../chai_setup'; import { fixtureData } from '../utils/fixture_data'; diff --git a/packages/subproviders/test/unit/nonce_tracker_subprovider_test.ts b/packages/subproviders/test/unit/nonce_tracker_subprovider_test.ts index fa33cd50a..c437d0815 100644 --- a/packages/subproviders/test/unit/nonce_tracker_subprovider_test.ts +++ b/packages/subproviders/test/unit/nonce_tracker_subprovider_test.ts @@ -1,11 +1,10 @@ import * as chai from 'chai'; -import Web3ProviderEngine = require('web3-provider-engine'); import FixtureSubprovider = require('web3-provider-engine/subproviders/fixture'); import { promisify } from '@0xproject/utils'; import EthereumTx = require('ethereumjs-tx'); -import { NonceTrackerSubprovider } from '../../src'; +import { NonceTrackerSubprovider, Web3ProviderEngine } from '../../src'; import { chaiSetup } from '../chai_setup'; const expect = chai.expect; diff --git a/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts b/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts index ab321bcff..95773145f 100644 --- a/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts +++ b/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts @@ -1,9 +1,8 @@ import * as chai from 'chai'; import { JSONRPCResponsePayload } from 'ethereum-types'; import * as ethUtils from 'ethereumjs-util'; -import Web3ProviderEngine = require('web3-provider-engine'); -import { GanacheSubprovider, PrivateKeyWalletSubprovider } from '../../src/'; +import { GanacheSubprovider, PrivateKeyWalletSubprovider, Web3ProviderEngine } from '../../src/'; import { DoneCallback, WalletSubproviderErrors } from '../../src/types'; import { chaiSetup } from '../chai_setup'; import { fixtureData } from '../utils/fixture_data'; diff --git a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts index e3f204b15..e30d2f74e 100644 --- a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts +++ b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts @@ -2,9 +2,8 @@ import { DoneCallback } from '@0xproject/types'; import * as chai from 'chai'; import { JSONRPCResponsePayload } from 'ethereum-types'; import * as Sinon from 'sinon'; -import Web3ProviderEngine = require('web3-provider-engine'); -import { RedundantSubprovider, RPCSubprovider } from '../../src'; +import { RedundantSubprovider, RPCSubprovider, Web3ProviderEngine } from '../../src'; import { Subprovider } from '../../src/subproviders/subprovider'; import { chaiSetup } from '../chai_setup'; import { ganacheSubprovider } from '../utils/ganache_subprovider'; -- cgit v1.2.3 From 70c3515c94e731f060aa8c532eb52d845f07b20f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 15:04:17 +0200 Subject: Make createFinalPayload protected --- packages/subproviders/src/subproviders/rpc_subprovider.ts | 2 +- packages/subproviders/src/subproviders/subprovider.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/subproviders') diff --git a/packages/subproviders/src/subproviders/rpc_subprovider.ts b/packages/subproviders/src/subproviders/rpc_subprovider.ts index 5c1c3272c..cb08e729e 100644 --- a/packages/subproviders/src/subproviders/rpc_subprovider.ts +++ b/packages/subproviders/src/subproviders/rpc_subprovider.ts @@ -31,7 +31,7 @@ export class RPCSubprovider extends Subprovider { */ // tslint:disable-next-line:prefer-function-over-method async-suffix public async handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback): Promise { - const finalPayload = Subprovider.createFinalPayload(payload); + const finalPayload = Subprovider._createFinalPayload(payload); const headers = new Headers({ Accept: 'application/json', 'Content-Type': 'application/json', diff --git a/packages/subproviders/src/subproviders/subprovider.ts b/packages/subproviders/src/subproviders/subprovider.ts index 6f4a8f99e..5dc273569 100644 --- a/packages/subproviders/src/subproviders/subprovider.ts +++ b/packages/subproviders/src/subproviders/subprovider.ts @@ -9,7 +9,7 @@ import { Callback, ErrorCallback, JSONRPCRequestPayloadWithMethod } from '../typ export abstract class Subprovider { // tslint:disable-next-line:underscore-private-and-protected private engine!: Provider; - public static createFinalPayload( + protected static _createFinalPayload( payload: Partial, ): Partial { const finalPayload = { @@ -47,7 +47,7 @@ export abstract class Subprovider { * @returns JSON RPC response payload */ public async emitPayloadAsync(payload: Partial): Promise { - const finalPayload = Subprovider.createFinalPayload(payload); + const finalPayload = Subprovider._createFinalPayload(payload); const response = await promisify(this.engine.sendAsync, this.engine)(finalPayload); return response; } -- cgit v1.2.3 From f5293e6c38b7e4e5352379e2fbd4d03c02b455b2 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 15:09:51 +0200 Subject: Fix linter --- packages/subproviders/src/subproviders/rpc_subprovider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/subproviders') diff --git a/packages/subproviders/src/subproviders/rpc_subprovider.ts b/packages/subproviders/src/subproviders/rpc_subprovider.ts index cb08e729e..dac821d01 100644 --- a/packages/subproviders/src/subproviders/rpc_subprovider.ts +++ b/packages/subproviders/src/subproviders/rpc_subprovider.ts @@ -30,7 +30,7 @@ export class RPCSubprovider extends Subprovider { * @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 async-suffix - public async handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback): Promise { + public async handleRequest(payload: JSONRPCRequestPayload, _next: Callback, end: ErrorCallback): Promise { const finalPayload = Subprovider._createFinalPayload(payload); const headers = new Headers({ Accept: 'application/json', -- cgit v1.2.3 From 350989bbec59b731a11c69237bec8625f2331ce2 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 15:25:37 +0200 Subject: Move type defs to typescript-typingsd --- packages/subproviders/src/globals.d.ts | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'packages/subproviders') diff --git a/packages/subproviders/src/globals.d.ts b/packages/subproviders/src/globals.d.ts index 837ed287d..94e63a32d 100644 --- a/packages/subproviders/src/globals.d.ts +++ b/packages/subproviders/src/globals.d.ts @@ -4,13 +4,3 @@ declare module '*.json' { export default json; /* tslint:enable */ } - -// TODO: Move this to `typescript-typings` once it is more fleshed out -declare module 'json-rpc-error' { - export class InternalError extends Error { - constructor(err: Error | string); - } - export class MethodNotFound extends Error { - constructor(); - } -} -- cgit v1.2.3 From 179c487da958dedda0f1a8cd93a2ce67f169e53c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 15:25:48 +0200 Subject: Add missing assertion --- packages/subproviders/src/subproviders/rpc_subprovider.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/subproviders') diff --git a/packages/subproviders/src/subproviders/rpc_subprovider.ts b/packages/subproviders/src/subproviders/rpc_subprovider.ts index dac821d01..3ad0e5325 100644 --- a/packages/subproviders/src/subproviders/rpc_subprovider.ts +++ b/packages/subproviders/src/subproviders/rpc_subprovider.ts @@ -18,6 +18,7 @@ export class RPCSubprovider extends Subprovider { constructor(rpcUrl: string, requestTimeoutMs: number = 20000) { super(); assert.isString('rpcUrl', rpcUrl); + assert.isNumber('requestTimeoutMs', requestTimeoutMs); this._rpcUrl = rpcUrl; this._requestTimeoutMs = requestTimeoutMs; } -- cgit v1.2.3