diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-03-28 22:26:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-28 22:26:05 +0800 |
commit | 8926dac78c3ac8d75ad5ffd5b4febe36def4e53c (patch) | |
tree | 01c1b3f8dba486beb4e83e67ad0bc35c3da6a14e /packages/subproviders | |
parent | 18cac3f0927a0424e3618fd56dba73fc9dfc0288 (diff) | |
parent | 01e27426d643b525661e044dbb8c8f27734329e7 (diff) | |
download | dexon-sol-tools-8926dac78c3ac8d75ad5ffd5b4febe36def4e53c.tar dexon-sol-tools-8926dac78c3ac8d75ad5ffd5b4febe36def4e53c.tar.gz dexon-sol-tools-8926dac78c3ac8d75ad5ffd5b4febe36def4e53c.tar.bz2 dexon-sol-tools-8926dac78c3ac8d75ad5ffd5b4febe36def4e53c.tar.lz dexon-sol-tools-8926dac78c3ac8d75ad5ffd5b4febe36def4e53c.tar.xz dexon-sol-tools-8926dac78c3ac8d75ad5ffd5b4febe36def4e53c.tar.zst dexon-sol-tools-8926dac78c3ac8d75ad5ffd5b4febe36def4e53c.zip |
Merge pull request #482 from 0xProject/feature/web3-types
Move common types out of web3 types
Diffstat (limited to 'packages/subproviders')
14 files changed, 46 insertions, 50 deletions
diff --git a/packages/subproviders/src/globals.d.ts b/packages/subproviders/src/globals.d.ts index 2c86346f5..ebc4efe86 100644 --- a/packages/subproviders/src/globals.d.ts +++ b/packages/subproviders/src/globals.d.ts @@ -73,11 +73,11 @@ declare module 'web3-provider-engine/subproviders/subprovider' { export = Subprovider; } declare module 'web3-provider-engine/subproviders/rpc' { - import * as Web3 from 'web3'; + import { JSONRPCRequestPayload } from '@0xproject/types'; class RpcSubprovider { constructor(options: { rpcUrl: string }); public handleRequest( - payload: Web3.JSONRPCRequestPayload, + payload: JSONRPCRequestPayload, next: () => void, end: (err: Error | null, data?: any) => void, ): void; @@ -102,11 +102,11 @@ declare module 'web3-provider-engine/util/rpc-cache-utils' { export = ProviderEngineRpcUtils; } declare module 'web3-provider-engine/subproviders/fixture' { - import * as Web3 from 'web3'; + import { JSONRPCRequestPayload } from '@0xproject/types'; class FixtureSubprovider { constructor(staticResponses: any); public handleRequest( - payload: Web3.JSONRPCRequestPayload, + payload: JSONRPCRequestPayload, next: () => void, end: (err: Error | null, data?: any) => void, ): void; diff --git a/packages/subproviders/src/index.ts b/packages/subproviders/src/index.ts index d88792fd0..9786347e6 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 { ECSignature } from '@0xproject/types'; import { LedgerEthereumClient } from './types'; @@ -15,7 +16,6 @@ export { Callback, ErrorCallback, NextCallback, - ECSignature, LedgerWalletSubprovider, LedgerCommunicationClient, NonceSubproviderErrors, diff --git a/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts b/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts index dc570b152..595ec654d 100644 --- a/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts +++ b/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts @@ -1,4 +1,4 @@ -import * as Web3 from 'web3'; +import { JSONRPCRequestPayload } from '@0xproject/types'; import { Callback, ErrorCallback } from '../types'; @@ -18,7 +18,7 @@ export class EmptyWalletSubprovider 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 - public handleRequest(payload: Web3.JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { + public 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 a6f978db1..966c37d8a 100644 --- a/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts +++ b/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts @@ -1,4 +1,4 @@ -import * as Web3 from 'web3'; +import { JSONRPCRequestPayload } from '@0xproject/types'; import { Callback, ErrorCallback } from '../types'; @@ -32,7 +32,7 @@ export class FakeGasEstimateSubprovider 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 - public handleRequest(payload: Web3.JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { + public 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 fc0b9c3d2..785de792d 100644 --- a/packages/subproviders/src/subproviders/ganache.ts +++ b/packages/subproviders/src/subproviders/ganache.ts @@ -1,3 +1,4 @@ +import { JSONRPCRequestPayload } from '@0xproject/types'; import * as Ganache from 'ganache-core'; import * as Web3 from 'web3'; @@ -28,7 +29,7 @@ export class GanacheSubprovider 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 - public handleRequest(payload: Web3.JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { + public 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 cd9b0b603..edecd8bf6 100644 --- a/packages/subproviders/src/subproviders/injected_web3.ts +++ b/packages/subproviders/src/subproviders/injected_web3.ts @@ -1,3 +1,4 @@ +import { JSONRPCRequestPayload } from '@0xproject/types'; import * as _ from 'lodash'; import * as Web3 from 'web3'; @@ -30,7 +31,7 @@ export class InjectedWeb3Subprovider 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 - public handleRequest(payload: Web3.JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { + public 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/ledger.ts b/packages/subproviders/src/subproviders/ledger.ts index 8bc70d8b6..95784a391 100644 --- a/packages/subproviders/src/subproviders/ledger.ts +++ b/packages/subproviders/src/subproviders/ledger.ts @@ -1,11 +1,11 @@ import { assert } from '@0xproject/assert'; +import { JSONRPCRequestPayload } from '@0xproject/types'; import { addressUtils } from '@0xproject/utils'; import EthereumTx = require('ethereumjs-tx'); import ethUtil = require('ethereumjs-util'); import HDNode = require('hdkey'); import * as _ from 'lodash'; import { Lock } from 'semaphore-async-await'; -import * as Web3 from 'web3'; import { Callback, @@ -208,7 +208,7 @@ export class LedgerSubprovider extends Subprovider { */ // tslint:disable-next-line:async-suffix public async handleRequest( - payload: Web3.JSONRPCRequestPayload, + payload: JSONRPCRequestPayload, next: Callback, end: (err: Error | null, result?: any) => void, ) { diff --git a/packages/subproviders/src/subproviders/nonce_tracker.ts b/packages/subproviders/src/subproviders/nonce_tracker.ts index 249f16199..907330111 100644 --- a/packages/subproviders/src/subproviders/nonce_tracker.ts +++ b/packages/subproviders/src/subproviders/nonce_tracker.ts @@ -1,9 +1,8 @@ import * as _ from 'lodash'; -import { BlockParamLiteral } from '@0xproject/types'; +import { BlockParamLiteral, JSONRPCRequestPayload } from '@0xproject/types'; import EthereumTx = require('ethereumjs-tx'); import ethUtil = require('ethereumjs-util'); -import * as Web3 from 'web3'; import providerEngineUtils = require('web3-provider-engine/util/rpc-cache-utils'); import { Callback, ErrorCallback, NextCallback, NonceSubproviderErrors } from '../types'; @@ -19,7 +18,7 @@ const NONCE_TOO_LOW_ERROR_MESSAGE = 'Transaction nonce is too low'; */ export class NonceTrackerSubprovider extends Subprovider { private _nonceCache: { [address: string]: string } = {}; - private static _reconstructTransaction(payload: Web3.JSONRPCRequestPayload): EthereumTx { + private static _reconstructTransaction(payload: JSONRPCRequestPayload): EthereumTx { const raw = payload.params[0]; if (_.isUndefined(raw)) { throw new Error(NonceSubproviderErrors.EmptyParametersFound); @@ -28,7 +27,7 @@ export class NonceTrackerSubprovider extends Subprovider { const transaction = new EthereumTx(rawData); return transaction; } - private static _determineAddress(payload: Web3.JSONRPCRequestPayload): string { + private static _determineAddress(payload: JSONRPCRequestPayload): string { let address: string; switch (payload.method) { case 'eth_getTransactionCount': @@ -55,11 +54,7 @@ export class NonceTrackerSubprovider extends Subprovider { * @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, - ): Promise<void> { + public async handleRequest(payload: JSONRPCRequestPayload, next: NextCallback, end: ErrorCallback): Promise<void> { switch (payload.method) { case 'eth_getTransactionCount': const requestDefaultBlock = providerEngineUtils.blockTagForPayload(payload); @@ -92,7 +87,7 @@ export class NonceTrackerSubprovider extends Subprovider { return next(); } } - private _handleSuccessfulTransaction(payload: Web3.JSONRPCRequestPayload): void { + private _handleSuccessfulTransaction(payload: JSONRPCRequestPayload): void { const address = NonceTrackerSubprovider._determineAddress(payload); const transaction = NonceTrackerSubprovider._reconstructTransaction(payload); // Increment the nonce from the previous successfully submitted transaction @@ -105,7 +100,7 @@ export class NonceTrackerSubprovider extends Subprovider { const nextPrefixedHexNonce = `0x${nextHexNonce}`; this._nonceCache[address] = nextPrefixedHexNonce; } - private _handleSendTransactionError(payload: Web3.JSONRPCRequestPayload, err: Error): void { + private _handleSendTransactionError(payload: JSONRPCRequestPayload, err: Error): void { const address = NonceTrackerSubprovider._determineAddress(payload); if (this._nonceCache[address] && _.includes(err.message, NONCE_TOO_LOW_ERROR_MESSAGE)) { delete this._nonceCache[address]; diff --git a/packages/subproviders/src/subproviders/redundant_rpc.ts b/packages/subproviders/src/subproviders/redundant_rpc.ts index ace2ed3c8..f8ff0915d 100644 --- a/packages/subproviders/src/subproviders/redundant_rpc.ts +++ b/packages/subproviders/src/subproviders/redundant_rpc.ts @@ -1,6 +1,6 @@ +import { JSONRPCRequestPayload } from '@0xproject/types'; import { promisify } from '@0xproject/utils'; import * as _ from 'lodash'; -import * as Web3 from 'web3'; import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); import { Callback } from '../types'; @@ -16,7 +16,7 @@ export class RedundantRPCSubprovider extends Subprovider { private _rpcs: RpcSubprovider[]; private static async _firstSuccessAsync( rpcs: RpcSubprovider[], - payload: Web3.JSONRPCRequestPayload, + payload: JSONRPCRequestPayload, next: Callback, ): Promise<any> { let lastErr: Error | undefined; @@ -55,7 +55,7 @@ export class RedundantRPCSubprovider extends Subprovider { */ // tslint:disable-next-line:async-suffix public async handleRequest( - payload: Web3.JSONRPCRequestPayload, + payload: JSONRPCRequestPayload, next: Callback, end: (err: Error | null, data?: any) => void, ): Promise<void> { diff --git a/packages/subproviders/src/subproviders/subprovider.ts b/packages/subproviders/src/subproviders/subprovider.ts index 4fa351e11..26ce19305 100644 --- a/packages/subproviders/src/subproviders/subprovider.ts +++ b/packages/subproviders/src/subproviders/subprovider.ts @@ -1,3 +1,4 @@ +import { JSONRPCRequestPayload, JSONRPCResponsePayload } from '@0xproject/types'; import promisify = require('es6-promisify'); import * as Web3 from 'web3'; @@ -37,9 +38,7 @@ export class Subprovider { * @param payload JSON RPC payload * @returns JSON RPC response payload */ - public async emitPayloadAsync( - payload: Partial<JSONRPCRequestPayloadWithMethod>, - ): Promise<Web3.JSONRPCResponsePayload> { + public async emitPayloadAsync(payload: Partial<JSONRPCRequestPayloadWithMethod>): Promise<JSONRPCResponsePayload> { const finalPayload = Subprovider._createFinalPayload(payload); const response = await promisify(this._engine.sendAsync, this._engine)(finalPayload); return response; diff --git a/packages/subproviders/src/types.ts b/packages/subproviders/src/types.ts index 9bb9ff696..a1fec1882 100644 --- a/packages/subproviders/src/types.ts +++ b/packages/subproviders/src/types.ts @@ -1,8 +1,5 @@ -import { ECSignature } from '@0xproject/types'; +import { ECSignature, JSONRPCRequestPayload } from '@0xproject/types'; import * as _ from 'lodash'; -import * as Web3 from 'web3'; - -export { ECSignature } from '@0xproject/types'; export interface LedgerCommunicationClient { close: () => Promise<void>; @@ -116,6 +113,6 @@ export type Callback = () => void; export type OnNextCompleted = (err: Error | null, result: any, cb: Callback) => void; export type NextCallback = (callback?: OnNextCompleted) => void; -export interface JSONRPCRequestPayloadWithMethod extends Web3.JSONRPCRequestPayload { +export interface JSONRPCRequestPayloadWithMethod extends JSONRPCRequestPayload { method: string; } diff --git a/packages/subproviders/test/integration/ledger_subprovider_test.ts b/packages/subproviders/test/integration/ledger_subprovider_test.ts index a94cfbe3a..969081ad5 100644 --- a/packages/subproviders/test/integration/ledger_subprovider_test.ts +++ b/packages/subproviders/test/integration/ledger_subprovider_test.ts @@ -1,3 +1,4 @@ +import { JSONRPCResponsePayload } from '@0xproject/types'; import Eth from '@ledgerhq/hw-app-eth'; // HACK: This depdency is optional and tslint skips optional depdencies // tslint:disable-next-line:no-implicit-dependencies @@ -97,7 +98,7 @@ describe('LedgerSubprovider', () => { params: [], id: 1, }; - const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { + const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { expect(err).to.be.a('null'); expect(response.result.length).to.be.equal(10); done(); @@ -115,7 +116,7 @@ describe('LedgerSubprovider', () => { params: [signer, messageHex], id: 1, }; - const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { + const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { expect(err).to.be.a('null'); expect(response.result.length).to.be.equal(132); expect(response.result.substr(0, 2)).to.be.equal('0x'); @@ -135,7 +136,7 @@ describe('LedgerSubprovider', () => { params: [messageHex, signer], id: 1, }; - const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { + const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { expect(err).to.be.a('null'); expect(response.result.length).to.be.equal(132); expect(response.result.substr(0, 2)).to.be.equal('0x'); @@ -155,7 +156,7 @@ describe('LedgerSubprovider', () => { params: [tx], id: 1, }; - const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { + const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { expect(err).to.be.a('null'); expect(response.result.raw.length).to.be.equal(206); expect(response.result.raw.substr(0, 2)).to.be.equal('0x'); @@ -193,7 +194,7 @@ describe('LedgerSubprovider', () => { params: [tx], id: 1, }; - const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { + const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { expect(err).to.be.a('null'); const result = response.result; expect(result.length).to.be.equal(66); diff --git a/packages/subproviders/test/unit/ledger_subprovider_test.ts b/packages/subproviders/test/unit/ledger_subprovider_test.ts index 4c0803a29..3cb487f02 100644 --- a/packages/subproviders/test/unit/ledger_subprovider_test.ts +++ b/packages/subproviders/test/unit/ledger_subprovider_test.ts @@ -1,3 +1,4 @@ +import { JSONRPCResponsePayload } from '@0xproject/types'; import * as chai from 'chai'; import * as ethUtils from 'ethereumjs-util'; import * as _ from 'lodash'; @@ -112,7 +113,7 @@ describe('LedgerSubprovider', () => { params: [], id: 1, }; - const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { + const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { expect(err).to.be.a('null'); expect(response.result.length).to.be.equal(10); expect(response.result[0]).to.be.equal(FAKE_ADDRESS); @@ -128,7 +129,7 @@ describe('LedgerSubprovider', () => { params: ['0x0000000000000000000000000000000000000000', messageHex], id: 1, }; - const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { + const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { expect(err).to.be.a('null'); expect(response.result).to.be.equal( '0xa6cc284bff14b42bdf5e9286730c152be91719d478605ec46b3bebcd0ae491480652a1a7b742ceb0213d1e744316e285f41f878d8af0b8e632cbca4c279132d001', @@ -145,7 +146,7 @@ describe('LedgerSubprovider', () => { params: [messageHex, '0x0000000000000000000000000000000000000000'], id: 1, }; - const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { + const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { expect(err).to.be.a('null'); expect(response.result).to.be.equal( '0xa6cc284bff14b42bdf5e9286730c152be91719d478605ec46b3bebcd0ae491480652a1a7b742ceb0213d1e744316e285f41f878d8af0b8e632cbca4c279132d001', @@ -168,7 +169,7 @@ describe('LedgerSubprovider', () => { params: [tx], id: 1, }; - const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { + const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { expect(err).to.be.a('null'); expect(response.result.raw.length).to.be.equal(192); expect(response.result.raw.substr(0, 2)).to.be.equal('0x'); @@ -186,7 +187,7 @@ describe('LedgerSubprovider', () => { params: ['0x0000000000000000000000000000000000000000', nonHexMessage], id: 1, }; - const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { + const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { expect(err).to.not.be.a('null'); expect(err.message).to.be.equal('Expected data to be of type HexString, encountered: hello world'); done(); @@ -201,7 +202,7 @@ describe('LedgerSubprovider', () => { params: [nonHexMessage, '0x0000000000000000000000000000000000000000'], id: 1, }; - const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { + const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { expect(err).to.not.be.a('null'); expect(err.message).to.be.equal('Expected data to be of type HexString, encountered: hello world'); done(); @@ -219,7 +220,7 @@ describe('LedgerSubprovider', () => { params: [tx], id: 1, }; - const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { + const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { expect(err).to.not.be.a('null'); expect(err.message).to.be.equal(LedgerSubproviderErrors.SenderInvalidOrNotSupplied); done(); @@ -238,7 +239,7 @@ describe('LedgerSubprovider', () => { params: [tx], id: 1, }; - const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { + const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { expect(err).to.not.be.a('null'); expect(err.message).to.be.equal(LedgerSubproviderErrors.SenderInvalidOrNotSupplied); done(); diff --git a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts index c3170745c..a347ab765 100644 --- a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts +++ b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts @@ -1,3 +1,4 @@ +import { JSONRPCResponsePayload } from '@0xproject/types'; import * as chai from 'chai'; import * as _ from 'lodash'; import Web3 = require('web3'); @@ -26,7 +27,7 @@ describe('RedundantRpcSubprovider', () => { params: [], id: 1, }; - const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { + const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { expect(err).to.be.a('null'); expect(response.result.length).to.be.equal(10); done(); @@ -46,7 +47,7 @@ describe('RedundantRpcSubprovider', () => { params: [], id: 1, }; - const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { + const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { expect(err).to.be.a('null'); expect(response.result.length).to.be.equal(10); done(); |