aboutsummaryrefslogtreecommitdiffstats
path: root/packages/subproviders
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2018-02-01 07:22:21 +0800
committerJacob Evans <jacob@dekz.net>2018-02-02 08:06:23 +0800
commitd635559a304f531314a89c91eb860a0d517404b3 (patch)
tree3722e22b8fb221197c9e3f8bb3448391b5ed161e /packages/subproviders
parent58dd90b7b7408a04a39e2e643c77bbf86859df1d (diff)
downloaddexon-sol-tools-d635559a304f531314a89c91eb860a0d517404b3.tar
dexon-sol-tools-d635559a304f531314a89c91eb860a0d517404b3.tar.gz
dexon-sol-tools-d635559a304f531314a89c91eb860a0d517404b3.tar.bz2
dexon-sol-tools-d635559a304f531314a89c91eb860a0d517404b3.tar.lz
dexon-sol-tools-d635559a304f531314a89c91eb860a0d517404b3.tar.xz
dexon-sol-tools-d635559a304f531314a89c91eb860a0d517404b3.tar.zst
dexon-sol-tools-d635559a304f531314a89c91eb860a0d517404b3.zip
Readability and prettier
Diffstat (limited to 'packages/subproviders')
-rw-r--r--packages/subproviders/src/globals.d.ts2
-rw-r--r--packages/subproviders/src/subproviders/nonce_tracker.ts22
2 files changed, 11 insertions, 13 deletions
diff --git a/packages/subproviders/src/globals.d.ts b/packages/subproviders/src/globals.d.ts
index 325dc27ed..6f344dcd3 100644
--- a/packages/subproviders/src/globals.d.ts
+++ b/packages/subproviders/src/globals.d.ts
@@ -101,7 +101,7 @@ declare module 'web3-provider-engine' {
}
declare module 'web3-provider-engine/util/rpc-cache-utils' {
class ProviderEngineRpcUtils {
- public static blockTagForPayload(payload: any): string|null;
+ public static blockTagForPayload(payload: any): string | null;
}
export = ProviderEngineRpcUtils;
}
diff --git a/packages/subproviders/src/subproviders/nonce_tracker.ts b/packages/subproviders/src/subproviders/nonce_tracker.ts
index 560f2dd68..a1e499629 100644
--- a/packages/subproviders/src/subproviders/nonce_tracker.ts
+++ b/packages/subproviders/src/subproviders/nonce_tracker.ts
@@ -10,12 +10,17 @@ import { Subprovider } from './subprovider';
const NONCE_TOO_LOW_ERROR_MESSAGE = 'Transaction nonce is too low';
+export type OptionalNextCallback = (callback?: (err: Error | null, result: any, cb: any) => void) => void;
+export type ErrorCallback = (err: Error | null, data?: any) => void;
+
export class NonceTrackerSubprovider extends Subprovider {
private _nonceCache: { [address: string]: string } = {};
private static _reconstructTransaction(payload: JSONRPCPayload): EthereumTx {
const raw = payload.params[0];
- const transactionData = ethUtil.stripHexPrefix(raw);
- const rawData = new Buffer(transactionData, 'hex');
+ if (_.isUndefined(raw)) {
+ throw new Error('Invalid transaction: empty parameters');
+ }
+ const rawData = ethUtil.toBuffer(raw);
return new EthereumTx(rawData);
}
private static _determineAddress(payload: JSONRPCPayload): string {
@@ -26,25 +31,18 @@ export class NonceTrackerSubprovider extends Subprovider {
const transaction = NonceTrackerSubprovider._reconstructTransaction(payload);
return `0x${transaction.getSenderAddress().toString('hex')}`.toLowerCase();
default:
- throw new Error('Invalid Method');
+ throw new Error(`Invalid Method: ${payload.method}`);
}
}
- constructor() {
- super();
- }
// tslint:disable-next-line:async-suffix
- public async handleRequest(
- payload: JSONRPCPayload,
- next: (callback?: (err: Error | null, result: any, cb: any) => void) => void,
- end: (err: Error | null, data?: any) => void,
- ): Promise<void> {
+ public async handleRequest(payload: JSONRPCPayload, next: OptionalNextCallback, end: ErrorCallback): Promise<void> {
switch (payload.method) {
case 'eth_getTransactionCount':
const blockTag = providerEngineUtils.blockTagForPayload(payload);
if (!_.isNull(blockTag) && blockTag === 'pending') {
const address = NonceTrackerSubprovider._determineAddress(payload);
const cachedResult = this._nonceCache[address];
- if (cachedResult) {
+ if (!_.isUndefined(cachedResult)) {
return end(null, cachedResult);
} else {
return next((requestError: Error | null, requestResult: any, cb: any) => {