Make handleRequest public and add comment for it

This commit is contained in:
Fabio Berger
2018-03-22 15:54:13 +00:00
parent bcb9ee4cc2
commit de8450d5c9
9 changed files with 80 additions and 26 deletions

View File

@@ -49,9 +49,16 @@ export class CoverageSubprovider extends Subprovider {
public async writeCoverageAsync(): Promise<void> {
await this._coverageManager.writeCoverageAsync();
}
// This method must conform to the web3-provider-engine interface
// tslint:disable-next-line:prefer-function-over-method underscore-private-and-protected
private handleRequest(payload: Web3.JSONRPCRequestPayload, next: NextCallback, end: ErrorCallback) {
/**
* 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
public handleRequest(payload: Web3.JSONRPCRequestPayload, next: NextCallback, end: ErrorCallback) {
switch (payload.method) {
case 'eth_sendTransaction':
const txData = payload.params[0];

View File

@@ -4,8 +4,6 @@
* Introduce `JSONRPCRequestPayloadWithMethod` type (#465)
* Export `ErrorCallback` type. (#465)
* Make `handleRequest` private in `LedgerSubprovider` since it should only be used
internally by the providerEngine. (#465)
## v0.8.0 - _March 18, 2018_

View File

@@ -9,9 +9,16 @@ import { Subprovider } from './subprovider';
* It intercepts the `eth_accounts` JSON RPC requests and never returns any addresses when queried.
*/
export class EmptyWalletSubprovider extends Subprovider {
// This method must conform to the web3-provider-engine interface
// tslint:disable-next-line:prefer-function-over-method underscore-private-and-protected
private handleRequest(payload: Web3.JSONRPCRequestPayload, next: Callback, end: ErrorCallback) {
/**
* 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
public handleRequest(payload: Web3.JSONRPCRequestPayload, next: Callback, end: ErrorCallback) {
switch (payload.method) {
case 'eth_accounts':
end(null, []);

View File

@@ -23,9 +23,16 @@ export class FakeGasEstimateSubprovider extends Subprovider {
super();
this._constantGasAmount = constantGasAmount;
}
// This method must conform to the web3-provider-engine interface
// tslint:disable-next-line:prefer-function-over-method underscore-private-and-protected
private handleRequest(payload: Web3.JSONRPCRequestPayload, next: Callback, end: ErrorCallback) {
/**
* 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
public handleRequest(payload: Web3.JSONRPCRequestPayload, next: Callback, end: ErrorCallback) {
switch (payload.method) {
case 'eth_estimateGas':
end(null, this._constantGasAmount);

View File

@@ -19,9 +19,16 @@ export class GanacheSubprovider extends Subprovider {
super();
this._ganacheProvider = Ganache.provider(opts);
}
// This method must conform to the web3-provider-engine interface
// tslint:disable-next-line:prefer-function-over-method underscore-private-and-protected
private handleRequest(payload: Web3.JSONRPCRequestPayload, next: Callback, end: ErrorCallback) {
/**
* 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
public handleRequest(payload: Web3.JSONRPCRequestPayload, next: Callback, end: ErrorCallback) {
this._ganacheProvider.sendAsync(payload, (err: Error | null, result: any) => {
end(err, result && result.result);
});

View File

@@ -21,9 +21,16 @@ export class InjectedWeb3Subprovider extends Subprovider {
super();
this._injectedWeb3 = new Web3(provider);
}
// This method must conform to the web3-provider-engine interface
// tslint:disable-next-line:prefer-function-over-method underscore-private-and-protected
private handleRequest(payload: Web3.JSONRPCRequestPayload, next: Callback, end: ErrorCallback) {
/**
* 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
public handleRequest(payload: Web3.JSONRPCRequestPayload, next: Callback, end: ErrorCallback) {
switch (payload.method) {
case 'web3_clientVersion':
this._injectedWeb3.version.getNode(end);

View File

@@ -198,9 +198,16 @@ export class LedgerSubprovider extends Subprovider {
throw err;
}
}
// Required to implement this public interface which doesn't conform to our linting rule.
// tslint:disable-next-line:async-suffix underscore-private-and-protected
private async handleRequest(
/**
* 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:async-suffix
public async handleRequest(
payload: Web3.JSONRPCRequestPayload,
next: Callback,
end: (err: Error | null, result?: any) => void,

View File

@@ -46,9 +46,16 @@ export class NonceTrackerSubprovider extends Subprovider {
throw new Error(NonceSubproviderErrors.CannotDetermineAddressFromPayload);
}
}
// This method must conform to the web3-provider-engine interface
// tslint:disable-next-line:prefer-function-over-method underscore-private-and-protected
private async handleRequest(
/**
* 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:async-suffix
public async handleRequest(
payload: Web3.JSONRPCRequestPayload,
next: NextCallback,
end: ErrorCallback,

View File

@@ -45,9 +45,16 @@ export class RedundantRPCSubprovider extends Subprovider {
});
});
}
// This method must conform to the web3-provider-engine interface
// tslint:disable-next-line:prefer-function-over-method underscore-private-and-protected
private async handleRequest(
/**
* 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:async-suffix
public async handleRequest(
payload: Web3.JSONRPCRequestPayload,
next: Callback,
end: (err: Error | null, data?: any) => void,