diff options
Diffstat (limited to 'packages/subproviders')
-rw-r--r-- | packages/subproviders/CHANGELOG.md | 4 | ||||
-rw-r--r-- | packages/subproviders/package.json | 12 | ||||
-rw-r--r-- | packages/subproviders/src/index.ts | 2 | ||||
-rw-r--r-- | packages/subproviders/src/subproviders/empty_wallet_subprovider.ts | 27 | ||||
-rw-r--r-- | packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts | 34 |
5 files changed, 73 insertions, 6 deletions
diff --git a/packages/subproviders/CHANGELOG.md b/packages/subproviders/CHANGELOG.md index f2c028aea..c2d590a35 100644 --- a/packages/subproviders/CHANGELOG.md +++ b/packages/subproviders/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## v0.5.0 - _February 16, 2018_ + + * Add EmptyWalletSubprovider and FakeGasEstimateSubprovider (#392) + ## v0.4.1 - _February 9, 2018_ * Fix publishing issue where .npmignore was not properly excluding undesired content (#389) diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json index 1a372ac6d..0c791b80f 100644 --- a/packages/subproviders/package.json +++ b/packages/subproviders/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/subproviders", - "version": "0.4.2", + "version": "0.5.0", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", "license": "Apache-2.0", @@ -18,8 +18,8 @@ "test:integration": "run-s clean build run_mocha_integration" }, "dependencies": { - "@0xproject/assert": "^0.0.19", - "@0xproject/utils": "^0.3.3", + "@0xproject/assert": "^0.0.20", + "@0xproject/utils": "^0.3.4", "bn.js": "^4.11.8", "es6-promisify": "^5.0.0", "ethereumjs-tx": "^1.3.3", @@ -33,8 +33,8 @@ }, "devDependencies": { "@0xproject/tslint-config": "^0.4.9", - "@0xproject/types": "^0.2.2", - "@0xproject/utils": "^0.3.3", + "@0xproject/types": "^0.2.3", + "@0xproject/utils": "^0.3.4", "@types/lodash": "^4.14.86", "@types/mocha": "^2.2.42", "@types/node": "^8.0.53", @@ -51,7 +51,7 @@ "types-bn": "^0.0.1", "types-ethereumjs-util": "0xProject/types-ethereumjs-util", "typescript": "2.7.1", - "web3-typescript-typings": "^0.9.10", + "web3-typescript-typings": "^0.9.11", "webpack": "^3.1.0" } } diff --git a/packages/subproviders/src/index.ts b/packages/subproviders/src/index.ts index 67d52ee25..4da405ec0 100644 --- a/packages/subproviders/src/index.ts +++ b/packages/subproviders/src/index.ts @@ -6,6 +6,8 @@ import { 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 { LedgerSubprovider } from './subproviders/ledger'; diff --git a/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts b/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts new file mode 100644 index 000000000..8c1fdfdb2 --- /dev/null +++ b/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts @@ -0,0 +1,27 @@ +import { JSONRPCPayload } from '@0xproject/types'; + +/* + * This class implements the web3-provider-engine subprovider interface and returns + * that the provider has no addresses when queried. + * Source: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js + */ +export class EmptyWalletSubprovider { + // This method needs to be here to satisfy the interface but linter wants it to be static. + // tslint:disable-next-line:prefer-function-over-method + public handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error | null, result: any) => void) { + switch (payload.method) { + case 'eth_accounts': + end(null, []); + return; + + default: + next(); + return; + } + } + // Required to implement this method despite not needing it for this subprovider + // tslint:disable-next-line:prefer-function-over-method + public setEngine(engine: any) { + // noop + } +} diff --git a/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts b/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts new file mode 100644 index 000000000..b455a0ed7 --- /dev/null +++ b/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts @@ -0,0 +1,34 @@ +import { JSONRPCPayload } from '@0xproject/types'; + +/* + * This class implements the web3-provider-engine subprovider interface and returns + * the constant gas estimate when queried. + * HACK: We need this so that our tests don't use testrpc gas estimation which sometimes kills the node. + * Source: https://github.com/trufflesuite/ganache-cli/issues/417 + * Source: https://github.com/trufflesuite/ganache-cli/issues/437 + * Source: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js + */ +export class FakeGasEstimateSubprovider { + private _constantGasAmount: number; + constructor(constantGasAmount: number) { + this._constantGasAmount = constantGasAmount; + } + // This method needs to be here to satisfy the interface but linter wants it to be static. + // tslint:disable-next-line:prefer-function-over-method + public handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error | null, result: any) => void) { + switch (payload.method) { + case 'eth_estimateGas': + end(null, this._constantGasAmount); + return; + + default: + next(); + return; + } + } + // Required to implement this method despite not needing it for this subprovider + // tslint:disable-next-line:prefer-function-over-method + public setEngine(engine: any) { + // noop + } +} |