aboutsummaryrefslogtreecommitdiffstats
path: root/packages/subproviders
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-04-06 14:41:42 +0800
committerFabio Berger <me@fabioberger.com>2018-04-06 14:41:42 +0800
commite30c76b7430d8518319eb7d90c7d70ef7c7f6c8d (patch)
treedcb28d9372c515aa0f9d825f876d495e2b2a3459 /packages/subproviders
parent75a51af00603236e0b80fe04336494944a32739c (diff)
downloaddexon-sol-tools-e30c76b7430d8518319eb7d90c7d70ef7c7f6c8d.tar
dexon-sol-tools-e30c76b7430d8518319eb7d90c7d70ef7c7f6c8d.tar.gz
dexon-sol-tools-e30c76b7430d8518319eb7d90c7d70ef7c7f6c8d.tar.bz2
dexon-sol-tools-e30c76b7430d8518319eb7d90c7d70ef7c7f6c8d.tar.lz
dexon-sol-tools-e30c76b7430d8518319eb7d90c7d70ef7c7f6c8d.tar.xz
dexon-sol-tools-e30c76b7430d8518319eb7d90c7d70ef7c7f6c8d.tar.zst
dexon-sol-tools-e30c76b7430d8518319eb7d90c7d70ef7c7f6c8d.zip
Make all `handleRequest` methods async, rename _engine to engine to remain compliant with web3-provider-engine
Diffstat (limited to 'packages/subproviders')
-rw-r--r--packages/subproviders/src/subproviders/empty_wallet_subprovider.ts4
-rw-r--r--packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts4
-rw-r--r--packages/subproviders/src/subproviders/ganache.ts4
-rw-r--r--packages/subproviders/src/subproviders/injected_web3.ts4
-rw-r--r--packages/subproviders/src/subproviders/subprovider.ts18
5 files changed, 21 insertions, 13 deletions
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/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;
}
}