diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2017-12-20 13:44:08 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-12-20 22:30:25 +0800 |
commit | cb11aec84df346d5180c7d5874859c1c34f0bf1c (patch) | |
tree | b959a65bdcfc3e8b01dca1bc160f93a0df8a4bf9 /packages/subproviders/src | |
parent | 972e1675f6490bc10e8d9fd64cce2f7945cd4840 (diff) | |
download | dexon-sol-tools-cb11aec84df346d5180c7d5874859c1c34f0bf1c.tar.gz dexon-sol-tools-cb11aec84df346d5180c7d5874859c1c34f0bf1c.tar.zst dexon-sol-tools-cb11aec84df346d5180c7d5874859c1c34f0bf1c.zip |
Add new underscore-privates rule to @0xproject/tslint-config and fix lint errors
Diffstat (limited to 'packages/subproviders/src')
4 files changed, 41 insertions, 41 deletions
diff --git a/packages/subproviders/src/subproviders/injected_web3.ts b/packages/subproviders/src/subproviders/injected_web3.ts index 25d747a62..b963f0c9b 100644 --- a/packages/subproviders/src/subproviders/injected_web3.ts +++ b/packages/subproviders/src/subproviders/injected_web3.ts @@ -9,29 +9,29 @@ import Web3ProviderEngine = require('web3-provider-engine'); * Source: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js */ export class InjectedWeb3Subprovider { - private injectedWeb3: Web3; + private _injectedWeb3: Web3; constructor(injectedWeb3: Web3) { - this.injectedWeb3 = injectedWeb3; + this._injectedWeb3 = injectedWeb3; } public handleRequest( payload: Web3.JSONRPCRequestPayload, next: () => void, end: (err: Error|null, result: any) => void, ) { switch (payload.method) { case 'web3_clientVersion': - this.injectedWeb3.version.getNode(end); + this._injectedWeb3.version.getNode(end); return; case 'eth_accounts': - this.injectedWeb3.eth.getAccounts(end); + this._injectedWeb3.eth.getAccounts(end); return; case 'eth_sendTransaction': const [txParams] = payload.params; - this.injectedWeb3.eth.sendTransaction(txParams, end); + this._injectedWeb3.eth.sendTransaction(txParams, end); return; case 'eth_sign': const [address, message] = payload.params; - this.injectedWeb3.eth.sign(address, message, end); + this._injectedWeb3.eth.sign(address, message, end); return; default: diff --git a/packages/subproviders/src/subproviders/ledger.ts b/packages/subproviders/src/subproviders/ledger.ts index f9922fdda..f19e6fadd 100644 --- a/packages/subproviders/src/subproviders/ledger.ts +++ b/packages/subproviders/src/subproviders/ledger.ts @@ -32,7 +32,7 @@ export class LedgerSubprovider extends Subprovider { private _ledgerEthereumClientFactoryAsync: LedgerEthereumClientFactoryAsync; private _ledgerClientIfExists?: LedgerEthereumClient; private _shouldAlwaysAskForConfirmation: boolean; - private static validateSender(sender: string) { + private static _validateSender(sender: string) { if (_.isUndefined(sender) || !addressUtils.isAddress(sender)) { throw new Error(LedgerSubproviderErrors.SenderInvalidOrNotSupplied); } @@ -88,8 +88,8 @@ export class LedgerSubprovider extends Subprovider { case 'eth_sendTransaction': txParams = payload.params[0]; try { - LedgerSubprovider.validateSender(txParams.from); - const result = await this.sendTransactionAsync(txParams); + LedgerSubprovider._validateSender(txParams.from); + const result = await this._sendTransactionAsync(txParams); end(null, result); } catch (err) { end(err); @@ -99,7 +99,7 @@ export class LedgerSubprovider extends Subprovider { case 'eth_signTransaction': txParams = payload.params[0]; try { - const result = await this.signTransactionWithoutSendingAsync(txParams); + const result = await this._signTransactionWithoutSendingAsync(txParams); end(null, result); } catch (err) { end(err); @@ -126,7 +126,7 @@ export class LedgerSubprovider extends Subprovider { } } public async getAccountsAsync(): Promise<string[]> { - this._ledgerClientIfExists = await this.createLedgerClientAsync(); + this._ledgerClientIfExists = await this._createLedgerClientAsync(); let ledgerResponse; try { @@ -134,7 +134,7 @@ export class LedgerSubprovider extends Subprovider { this._derivationPath, this._shouldAlwaysAskForConfirmation, SHOULD_GET_CHAIN_CODE, ); } finally { - await this.destoryLedgerClientAsync(); + await this._destroyLedgerClientAsync(); } const hdKey = new HDNode(); @@ -155,7 +155,7 @@ export class LedgerSubprovider extends Subprovider { return accounts; } public async signTransactionAsync(txParams: PartialTxParams): Promise<string> { - this._ledgerClientIfExists = await this.createLedgerClientAsync(); + this._ledgerClientIfExists = await this._createLedgerClientAsync(); const tx = new EthereumTx(txParams); @@ -166,7 +166,7 @@ export class LedgerSubprovider extends Subprovider { const txHex = tx.serialize().toString('hex'); try { - const derivationPath = this.getDerivationPath(); + const derivationPath = this._getDerivationPath(); const result = await this._ledgerClientIfExists.signTransaction_async(derivationPath, txHex); // Store signature in transaction tx.r = Buffer.from(result.r, 'hex'); @@ -176,23 +176,23 @@ export class LedgerSubprovider extends Subprovider { // EIP155: v should be chain_id * 2 + {35, 36} const signedChainId = Math.floor((tx.v[0] - 35) / 2); if (signedChainId !== this._networkId) { - await this.destoryLedgerClientAsync(); + await this._destroyLedgerClientAsync(); const err = new Error(LedgerSubproviderErrors.TooOldLedgerFirmware); throw err; } const signedTxHex = `0x${tx.serialize().toString('hex')}`; - await this.destoryLedgerClientAsync(); + await this._destroyLedgerClientAsync(); return signedTxHex; } catch (err) { - await this.destoryLedgerClientAsync(); + await this._destroyLedgerClientAsync(); throw err; } } public async signPersonalMessageAsync(data: string): Promise<string> { - this._ledgerClientIfExists = await this.createLedgerClientAsync(); + this._ledgerClientIfExists = await this._createLedgerClientAsync(); try { - const derivationPath = this.getDerivationPath(); + const derivationPath = this._getDerivationPath(); const result = await this._ledgerClientIfExists.signPersonalMessage_async( derivationPath, ethUtil.stripHexPrefix(data)); const v = result.v - 27; @@ -201,18 +201,18 @@ export class LedgerSubprovider extends Subprovider { vHex = `0${v}`; } const signature = `0x${result.r}${result.s}${vHex}`; - await this.destoryLedgerClientAsync(); + await this._destroyLedgerClientAsync(); return signature; } catch (err) { - await this.destoryLedgerClientAsync(); + await this._destroyLedgerClientAsync(); throw err; } } - private getDerivationPath() { + private _getDerivationPath() { const derivationPath = `${this.getPath()}/${this._derivationPathIndex}`; return derivationPath; } - private async createLedgerClientAsync(): Promise<LedgerEthereumClient> { + private async _createLedgerClientAsync(): Promise<LedgerEthereumClient> { await this._connectionLock.wait(); if (!_.isUndefined(this._ledgerClientIfExists)) { this._connectionLock.signal(); @@ -222,7 +222,7 @@ export class LedgerSubprovider extends Subprovider { this._connectionLock.signal(); return ledgerEthereumClient; } - private async destoryLedgerClientAsync() { + private async _destroyLedgerClientAsync() { await this._connectionLock.wait(); if (_.isUndefined(this._ledgerClientIfExists)) { this._connectionLock.signal(); @@ -232,11 +232,11 @@ export class LedgerSubprovider extends Subprovider { this._ledgerClientIfExists = undefined; this._connectionLock.signal(); } - private async sendTransactionAsync(txParams: PartialTxParams): Promise<Web3.JSONRPCResponsePayload> { + private async _sendTransactionAsync(txParams: PartialTxParams): Promise<Web3.JSONRPCResponsePayload> { await this._nonceLock.wait(); try { // fill in the extras - const filledParams = await this.populateMissingTxParamsAsync(txParams); + const filledParams = await this._populateMissingTxParamsAsync(txParams); // sign it const signedTx = await this.signTransactionAsync(filledParams); // emit a submit @@ -252,11 +252,11 @@ export class LedgerSubprovider extends Subprovider { throw err; } } - private async signTransactionWithoutSendingAsync(txParams: PartialTxParams): Promise<ResponseWithTxParams> { + private async _signTransactionWithoutSendingAsync(txParams: PartialTxParams): Promise<ResponseWithTxParams> { await this._nonceLock.wait(); try { // fill in the extras - const filledParams = await this.populateMissingTxParamsAsync(txParams); + const filledParams = await this._populateMissingTxParamsAsync(txParams); // sign it const signedTx = await this.signTransactionAsync(filledParams); @@ -271,7 +271,7 @@ export class LedgerSubprovider extends Subprovider { throw err; } } - private async populateMissingTxParamsAsync(txParams: PartialTxParams): Promise<PartialTxParams> { + private async _populateMissingTxParamsAsync(txParams: PartialTxParams): Promise<PartialTxParams> { if (_.isUndefined(txParams.gasPrice)) { const gasPriceResult = await this.emitPayloadAsync({ method: 'eth_gasPrice', diff --git a/packages/subproviders/src/subproviders/redundant_rpc.ts b/packages/subproviders/src/subproviders/redundant_rpc.ts index f688061ea..67e2a857b 100644 --- a/packages/subproviders/src/subproviders/redundant_rpc.ts +++ b/packages/subproviders/src/subproviders/redundant_rpc.ts @@ -7,8 +7,8 @@ import {JSONRPCPayload} from '../types'; import {Subprovider} from './subprovider'; export class RedundantRPCSubprovider extends Subprovider { - private rpcs: RpcSubprovider[]; - private static async firstSuccessAsync( + private _rpcs: RpcSubprovider[]; + private static async _firstSuccessAsync( rpcs: RpcSubprovider[], payload: JSONRPCPayload, next: () => void, ): Promise<any> { let lastErr: Error|undefined; @@ -27,7 +27,7 @@ export class RedundantRPCSubprovider extends Subprovider { } constructor(endpoints: string[]) { super(); - this.rpcs = _.map(endpoints, endpoint => { + this._rpcs = _.map(endpoints, endpoint => { return new RpcSubprovider({ rpcUrl: endpoint, }); @@ -36,9 +36,9 @@ export class RedundantRPCSubprovider extends Subprovider { // tslint:disable-next-line:async-suffix public async handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error|null, data?: any) => void): Promise<void> { - const rpcsCopy = this.rpcs.slice(); + const rpcsCopy = this._rpcs.slice(); try { - const data = await RedundantRPCSubprovider.firstSuccessAsync(rpcsCopy, payload, next); + const data = await RedundantRPCSubprovider._firstSuccessAsync(rpcsCopy, payload, next); end(null, data); } catch (err) { end(err); diff --git a/packages/subproviders/src/subproviders/subprovider.ts b/packages/subproviders/src/subproviders/subprovider.ts index 41dde4238..56ead214d 100644 --- a/packages/subproviders/src/subproviders/subprovider.ts +++ b/packages/subproviders/src/subproviders/subprovider.ts @@ -10,9 +10,9 @@ import { * Altered version of: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js */ export class Subprovider { - private engine: any; + private _engine: any; // Ported from: https://github.com/MetaMask/provider-engine/blob/master/util/random-id.js - private static getRandomId() { + private static _getRandomId() { const extraDigits = 3; // 13 time digits const datePart = new Date().getTime() * Math.pow(10, extraDigits); @@ -21,10 +21,10 @@ export class Subprovider { // 16 digits return datePart + extraPart; } - private static createFinalPayload(payload: JSONRPCPayload): Web3.JSONRPCRequestPayload { + private static _createFinalPayload(payload: JSONRPCPayload): Web3.JSONRPCRequestPayload { const finalPayload = { // defaults - id: Subprovider.getRandomId(), + id: Subprovider._getRandomId(), jsonrpc: '2.0', params: [], ...payload, @@ -32,11 +32,11 @@ export class Subprovider { return finalPayload; } public setEngine(engine: any): void { - this.engine = engine; + this._engine = engine; } public async emitPayloadAsync(payload: JSONRPCPayload): Promise<any> { - const finalPayload = Subprovider.createFinalPayload(payload); - const response = await promisify(this.engine.sendAsync, this.engine)(finalPayload); + const finalPayload = Subprovider._createFinalPayload(payload); + const response = await promisify(this._engine.sendAsync, this._engine)(finalPayload); return response; } } |