diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-07-07 01:23:24 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-07-07 01:23:24 +0800 |
commit | acfbba5476d48645eee7f471ecaa4b1142709939 (patch) | |
tree | 8e62f46a85c50cf3685d3a02fe63bc56fd3d6028 | |
parent | 188bf000b784fe6d9e24e3758a30a72a2795bc58 (diff) | |
download | dexon-sol-tools-acfbba5476d48645eee7f471ecaa4b1142709939.tar dexon-sol-tools-acfbba5476d48645eee7f471ecaa4b1142709939.tar.gz dexon-sol-tools-acfbba5476d48645eee7f471ecaa4b1142709939.tar.bz2 dexon-sol-tools-acfbba5476d48645eee7f471ecaa4b1142709939.tar.lz dexon-sol-tools-acfbba5476d48645eee7f471ecaa4b1142709939.tar.xz dexon-sol-tools-acfbba5476d48645eee7f471ecaa4b1142709939.tar.zst dexon-sol-tools-acfbba5476d48645eee7f471ecaa4b1142709939.zip |
Revert moving formatUtils into utils
-rw-r--r-- | packages/subproviders/src/subproviders/signer.ts | 6 | ||||
-rw-r--r-- | packages/utils/CHANGELOG.json | 4 | ||||
-rw-r--r-- | packages/utils/src/index.ts | 1 | ||||
-rw-r--r-- | packages/web3-wrapper/src/index.ts | 1 | ||||
-rw-r--r-- | packages/web3-wrapper/src/marshaller.ts | 76 | ||||
-rw-r--r-- | packages/web3-wrapper/src/utils.ts (renamed from packages/utils/src/format_utils.ts) | 11 | ||||
-rw-r--r-- | packages/web3-wrapper/src/web3_wrapper.ts | 3 |
7 files changed, 43 insertions, 59 deletions
diff --git a/packages/subproviders/src/subproviders/signer.ts b/packages/subproviders/src/subproviders/signer.ts index 1fb613da0..08a9daceb 100644 --- a/packages/subproviders/src/subproviders/signer.ts +++ b/packages/subproviders/src/subproviders/signer.ts @@ -1,5 +1,4 @@ -import { Web3Wrapper, marshaller } from '@0xproject/web3-wrapper'; - +import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { JSONRPCRequestPayload, Provider } from 'ethereum-types'; import { Callback, ErrorCallback } from '../types'; @@ -52,8 +51,7 @@ export class SignerSubprovider extends Subprovider { case 'eth_sendTransaction': const [txParams] = payload.params; try { - const txData = marshaller.unmarshalTxData(txParams); - const txHash = await this._web3Wrapper.sendTransactionAsync(txData); + const txHash = await this._web3Wrapper.sendTransactionAsync(txParams); end(null, txHash); } catch (err) { end(err); diff --git a/packages/utils/CHANGELOG.json b/packages/utils/CHANGELOG.json index bea6a9566..a27216be7 100644 --- a/packages/utils/CHANGELOG.json +++ b/packages/utils/CHANGELOG.json @@ -12,10 +12,6 @@ { "note": "Fixes uncaught Error in abi_decoder", "pr": 763 - }, - { - "note": "Add formatUtils", - "pr": 829 } ] }, diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index cc8592400..fd102cecb 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -8,4 +8,3 @@ export { logUtils } from './log_utils'; export { abiUtils } from './abi_utils'; export { NULL_BYTES } from './constants'; export { errorUtils } from './error_utils'; -export { formatUtils } from './format_utils'; diff --git a/packages/web3-wrapper/src/index.ts b/packages/web3-wrapper/src/index.ts index 19fe0836c..66ef0a784 100644 --- a/packages/web3-wrapper/src/index.ts +++ b/packages/web3-wrapper/src/index.ts @@ -1,3 +1,2 @@ export { Web3Wrapper, uniqueVersionIds, NodeType } from './web3_wrapper'; export { Web3WrapperErrors } from './types'; -export { marshaller } from './marshaller'; diff --git a/packages/web3-wrapper/src/marshaller.ts b/packages/web3-wrapper/src/marshaller.ts index 584f6252d..15384417e 100644 --- a/packages/web3-wrapper/src/marshaller.ts +++ b/packages/web3-wrapper/src/marshaller.ts @@ -1,4 +1,4 @@ -import { addressUtils, formatUtils } from '@0xproject/utils'; +import { addressUtils } from '@0xproject/utils'; import { BlockParam, BlockParamLiteral, @@ -14,6 +14,8 @@ import { import ethUtil = require('ethereumjs-util'); import * as _ from 'lodash'; +import { utils } from './utils'; + import { BlockWithoutTransactionDataRPC, BlockWithTransactionDataRPC, @@ -29,30 +31,26 @@ export const marshaller = { ): BlockWithoutTransactionData { const block = { ...blockWithHexValues, - gasLimit: formatUtils.convertHexToNumber(blockWithHexValues.gasLimit), - gasUsed: formatUtils.convertHexToNumber(blockWithHexValues.gasUsed), - size: formatUtils.convertHexToNumber(blockWithHexValues.size), - timestamp: formatUtils.convertHexToNumber(blockWithHexValues.timestamp), - number: _.isNull(blockWithHexValues.number) - ? null - : formatUtils.convertHexToNumber(blockWithHexValues.number), - difficulty: formatUtils.convertAmountToBigNumber(blockWithHexValues.difficulty), - totalDifficulty: formatUtils.convertAmountToBigNumber(blockWithHexValues.totalDifficulty), + gasLimit: utils.convertHexToNumber(blockWithHexValues.gasLimit), + gasUsed: utils.convertHexToNumber(blockWithHexValues.gasUsed), + size: utils.convertHexToNumber(blockWithHexValues.size), + timestamp: utils.convertHexToNumber(blockWithHexValues.timestamp), + number: _.isNull(blockWithHexValues.number) ? null : utils.convertHexToNumber(blockWithHexValues.number), + difficulty: utils.convertAmountToBigNumber(blockWithHexValues.difficulty), + totalDifficulty: utils.convertAmountToBigNumber(blockWithHexValues.totalDifficulty), }; return block; }, unmarshalIntoBlockWithTransactionData(blockWithHexValues: BlockWithTransactionDataRPC): BlockWithTransactionData { const block = { ...blockWithHexValues, - gasLimit: formatUtils.convertHexToNumber(blockWithHexValues.gasLimit), - gasUsed: formatUtils.convertHexToNumber(blockWithHexValues.gasUsed), - size: formatUtils.convertHexToNumber(blockWithHexValues.size), - timestamp: formatUtils.convertHexToNumber(blockWithHexValues.timestamp), - number: _.isNull(blockWithHexValues.number) - ? null - : formatUtils.convertHexToNumber(blockWithHexValues.number), - difficulty: formatUtils.convertAmountToBigNumber(blockWithHexValues.difficulty), - totalDifficulty: formatUtils.convertAmountToBigNumber(blockWithHexValues.totalDifficulty), + gasLimit: utils.convertHexToNumber(blockWithHexValues.gasLimit), + gasUsed: utils.convertHexToNumber(blockWithHexValues.gasUsed), + size: utils.convertHexToNumber(blockWithHexValues.size), + timestamp: utils.convertHexToNumber(blockWithHexValues.timestamp), + number: _.isNull(blockWithHexValues.number) ? null : utils.convertHexToNumber(blockWithHexValues.number), + difficulty: utils.convertAmountToBigNumber(blockWithHexValues.difficulty), + totalDifficulty: utils.convertAmountToBigNumber(blockWithHexValues.totalDifficulty), transactions: [] as Transaction[], }; block.transactions = _.map(blockWithHexValues.transactions, (tx: TransactionRPC) => { @@ -64,14 +62,14 @@ export const marshaller = { unmarshalTransaction(txRpc: TransactionRPC): Transaction { const tx = { ...txRpc, - blockNumber: !_.isNull(txRpc.blockNumber) ? formatUtils.convertHexToNumber(txRpc.blockNumber) : null, + blockNumber: !_.isNull(txRpc.blockNumber) ? utils.convertHexToNumber(txRpc.blockNumber) : null, transactionIndex: !_.isNull(txRpc.transactionIndex) - ? formatUtils.convertHexToNumber(txRpc.transactionIndex) + ? utils.convertHexToNumber(txRpc.transactionIndex) : null, - nonce: formatUtils.convertHexToNumber(txRpc.nonce), - gas: formatUtils.convertHexToNumber(txRpc.gas), - gasPrice: formatUtils.convertAmountToBigNumber(txRpc.gasPrice), - value: formatUtils.convertAmountToBigNumber(txRpc.value), + nonce: utils.convertHexToNumber(txRpc.nonce), + gas: utils.convertHexToNumber(txRpc.gas), + gasPrice: utils.convertAmountToBigNumber(txRpc.gasPrice), + value: utils.convertAmountToBigNumber(txRpc.value), }; return tx; }, @@ -81,12 +79,10 @@ export const marshaller = { } const txData = { ...txDataRpc, - value: !_.isUndefined(txDataRpc.value) ? formatUtils.convertHexToNumber(txDataRpc.value) : undefined, - gas: !_.isUndefined(txDataRpc.gas) ? formatUtils.convertHexToNumber(txDataRpc.gas) : undefined, - gasPrice: !_.isUndefined(txDataRpc.gasPrice) - ? formatUtils.convertHexToNumber(txDataRpc.gasPrice) - : undefined, - nonce: !_.isUndefined(txDataRpc.nonce) ? formatUtils.convertHexToNumber(txDataRpc.nonce) : undefined, + value: !_.isUndefined(txDataRpc.value) ? utils.convertHexToNumber(txDataRpc.value) : undefined, + gas: !_.isUndefined(txDataRpc.gas) ? utils.convertHexToNumber(txDataRpc.gas) : undefined, + gasPrice: !_.isUndefined(txDataRpc.gasPrice) ? utils.convertHexToNumber(txDataRpc.gasPrice) : undefined, + nonce: !_.isUndefined(txDataRpc.nonce) ? utils.convertHexToNumber(txDataRpc.nonce) : undefined, }; return txData; }, @@ -133,15 +129,15 @@ export const marshaller = { if (_.isUndefined(blockParam)) { return BlockParamLiteral.Latest; } - const encodedBlockParam = _.isNumber(blockParam) ? formatUtils.numberToHex(blockParam) : blockParam; + const encodedBlockParam = _.isNumber(blockParam) ? utils.numberToHex(blockParam) : blockParam; return encodedBlockParam; }, unmarshalLog(rawLog: RawLogEntry): LogEntry { const formattedLog = { ...rawLog, - logIndex: formatUtils.convertHexToNumberOrNull(rawLog.logIndex), - blockNumber: formatUtils.convertHexToNumberOrNull(rawLog.blockNumber), - transactionIndex: formatUtils.convertHexToNumberOrNull(rawLog.transactionIndex), + logIndex: utils.convertHexToNumberOrNull(rawLog.logIndex), + blockNumber: utils.convertHexToNumberOrNull(rawLog.blockNumber), + transactionIndex: utils.convertHexToNumberOrNull(rawLog.transactionIndex), }; return formattedLog; }, @@ -151,16 +147,14 @@ export const marshaller = { to: _.isUndefined(callTxDataBase.to) ? undefined : this.marshalAddress(callTxDataBase.to), gasPrice: _.isUndefined(callTxDataBase.gasPrice) ? undefined - : formatUtils.encodeAmountAsHexString(callTxDataBase.gasPrice), - gas: _.isUndefined(callTxDataBase.gas) - ? undefined - : formatUtils.encodeAmountAsHexString(callTxDataBase.gas), + : utils.encodeAmountAsHexString(callTxDataBase.gasPrice), + gas: _.isUndefined(callTxDataBase.gas) ? undefined : utils.encodeAmountAsHexString(callTxDataBase.gas), value: _.isUndefined(callTxDataBase.value) ? undefined - : formatUtils.encodeAmountAsHexString(callTxDataBase.value), + : utils.encodeAmountAsHexString(callTxDataBase.value), nonce: _.isUndefined(callTxDataBase.nonce) ? undefined - : formatUtils.encodeAmountAsHexString(callTxDataBase.nonce), + : utils.encodeAmountAsHexString(callTxDataBase.nonce), }; return callTxDataBaseRPC; diff --git a/packages/utils/src/format_utils.ts b/packages/web3-wrapper/src/utils.ts index 101854926..d13eb9404 100644 --- a/packages/utils/src/format_utils.ts +++ b/packages/web3-wrapper/src/utils.ts @@ -1,9 +1,7 @@ +import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; -import { BigNumber } from './configured_bignumber'; - -// tslint:disable:restrict-plus-operands -export const formatUtils = { +export const utils = { isBigNumber(value: any): boolean { const isBigNumber = _.isObject(value) && value.isBigNumber; return isBigNumber; @@ -22,7 +20,7 @@ export const formatUtils = { }, convertAmountToBigNumber(value: string | number | BigNumber): BigNumber { const num = value || 0; - const isBigNumber = formatUtils.isBigNumber(num); + const isBigNumber = utils.isBigNumber(num); if (isBigNumber) { return num as BigNumber; } @@ -35,7 +33,7 @@ export const formatUtils = { return new BigNumber((num as number).toString(baseTen), baseTen); }, encodeAmountAsHexString(value: string | number | BigNumber): string { - const valueBigNumber = formatUtils.convertAmountToBigNumber(value); + const valueBigNumber = utils.convertAmountToBigNumber(value); const hexBase = 16; const valueHex = valueBigNumber.toString(hexBase); @@ -58,4 +56,3 @@ export const formatUtils = { ); }, }; -// tslint:enable:restrict-plus-operands diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts index 57ad0a0db..495523e44 100644 --- a/packages/web3-wrapper/src/web3_wrapper.ts +++ b/packages/web3-wrapper/src/web3_wrapper.ts @@ -1,6 +1,6 @@ import { assert } from '@0xproject/assert'; import { schemas } from '@0xproject/json-schemas'; -import { AbiDecoder, addressUtils, BigNumber, formatUtils as utils, intervalUtils, promisify } from '@0xproject/utils'; +import { AbiDecoder, addressUtils, BigNumber, intervalUtils, promisify } from '@0xproject/utils'; import { BlockParam, BlockParamLiteral, @@ -23,6 +23,7 @@ import * as _ from 'lodash'; import { marshaller } from './marshaller'; import { BlockWithoutTransactionDataRPC, BlockWithTransactionDataRPC, Web3WrapperErrors } from './types'; +import { utils } from './utils'; const BASE_TEN = 10; |