From 30e3afc0fbccd01ef5ce62de4dfb0154fd7b7892 Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 5 Jul 2018 17:48:02 -0700 Subject: Add unmarshallTxData to marshaller --- packages/web3-wrapper/src/marshaller.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/web3-wrapper/src/marshaller.ts b/packages/web3-wrapper/src/marshaller.ts index e9fd35a11..15384417e 100644 --- a/packages/web3-wrapper/src/marshaller.ts +++ b/packages/web3-wrapper/src/marshaller.ts @@ -73,6 +73,19 @@ export const marshaller = { }; return tx; }, + unmarshalTxData(txDataRpc: TxDataRPC): TxData { + if (_.isUndefined(txDataRpc.from)) { + throw new Error(`txData must include valid 'from' value.`); + } + const txData = { + ...txDataRpc, + 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; + }, marshalTxData(txData: Partial): Partial { if (_.isUndefined(txData.from)) { throw new Error(`txData must include valid 'from' value.`); -- cgit v1.2.3 From a72eae7ea84be60792b214b52f2f363b881197b2 Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 5 Jul 2018 18:32:28 -0700 Subject: Unmarshall txn data in SignerSubprovider before calling web3wrapper sendTransactionAsync --- packages/subproviders/src/subproviders/signer.ts | 6 +- packages/utils/src/index.ts | 1 + packages/web3-wrapper/src/index.ts | 1 + packages/web3-wrapper/src/marshaller.ts | 74 +++++++++++++----------- packages/web3-wrapper/src/utils.ts | 58 ------------------- packages/web3-wrapper/src/web3_wrapper.ts | 3 +- 6 files changed, 46 insertions(+), 97 deletions(-) delete mode 100644 packages/web3-wrapper/src/utils.ts diff --git a/packages/subproviders/src/subproviders/signer.ts b/packages/subproviders/src/subproviders/signer.ts index 08a9daceb..1fb613da0 100644 --- a/packages/subproviders/src/subproviders/signer.ts +++ b/packages/subproviders/src/subproviders/signer.ts @@ -1,4 +1,5 @@ -import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Web3Wrapper, marshaller } from '@0xproject/web3-wrapper'; + import { JSONRPCRequestPayload, Provider } from 'ethereum-types'; import { Callback, ErrorCallback } from '../types'; @@ -51,7 +52,8 @@ export class SignerSubprovider extends Subprovider { case 'eth_sendTransaction': const [txParams] = payload.params; try { - const txHash = await this._web3Wrapper.sendTransactionAsync(txParams); + const txData = marshaller.unmarshalTxData(txParams); + const txHash = await this._web3Wrapper.sendTransactionAsync(txData); end(null, txHash); } catch (err) { end(err); diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index fd102cecb..de78f26df 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -8,3 +8,4 @@ export { logUtils } from './log_utils'; export { abiUtils } from './abi_utils'; export { NULL_BYTES } from './constants'; export { errorUtils } from './error_utils'; +export { conversion } from './conversion'; diff --git a/packages/web3-wrapper/src/index.ts b/packages/web3-wrapper/src/index.ts index 66ef0a784..19fe0836c 100644 --- a/packages/web3-wrapper/src/index.ts +++ b/packages/web3-wrapper/src/index.ts @@ -1,2 +1,3 @@ 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 15384417e..b4a1e2ce4 100644 --- a/packages/web3-wrapper/src/marshaller.ts +++ b/packages/web3-wrapper/src/marshaller.ts @@ -1,4 +1,4 @@ -import { addressUtils } from '@0xproject/utils'; +import { addressUtils, conversion } from '@0xproject/utils'; import { BlockParam, BlockParamLiteral, @@ -14,8 +14,6 @@ import { import ethUtil = require('ethereumjs-util'); import * as _ from 'lodash'; -import { utils } from './utils'; - import { BlockWithoutTransactionDataRPC, BlockWithTransactionDataRPC, @@ -31,26 +29,30 @@ export const marshaller = { ): BlockWithoutTransactionData { const block = { ...blockWithHexValues, - 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), + gasLimit: conversion.convertHexToNumber(blockWithHexValues.gasLimit), + gasUsed: conversion.convertHexToNumber(blockWithHexValues.gasUsed), + size: conversion.convertHexToNumber(blockWithHexValues.size), + timestamp: conversion.convertHexToNumber(blockWithHexValues.timestamp), + number: _.isNull(blockWithHexValues.number) + ? null + : conversion.convertHexToNumber(blockWithHexValues.number), + difficulty: conversion.convertAmountToBigNumber(blockWithHexValues.difficulty), + totalDifficulty: conversion.convertAmountToBigNumber(blockWithHexValues.totalDifficulty), }; return block; }, unmarshalIntoBlockWithTransactionData(blockWithHexValues: BlockWithTransactionDataRPC): BlockWithTransactionData { const block = { ...blockWithHexValues, - 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), + gasLimit: conversion.convertHexToNumber(blockWithHexValues.gasLimit), + gasUsed: conversion.convertHexToNumber(blockWithHexValues.gasUsed), + size: conversion.convertHexToNumber(blockWithHexValues.size), + timestamp: conversion.convertHexToNumber(blockWithHexValues.timestamp), + number: _.isNull(blockWithHexValues.number) + ? null + : conversion.convertHexToNumber(blockWithHexValues.number), + difficulty: conversion.convertAmountToBigNumber(blockWithHexValues.difficulty), + totalDifficulty: conversion.convertAmountToBigNumber(blockWithHexValues.totalDifficulty), transactions: [] as Transaction[], }; block.transactions = _.map(blockWithHexValues.transactions, (tx: TransactionRPC) => { @@ -62,14 +64,14 @@ export const marshaller = { unmarshalTransaction(txRpc: TransactionRPC): Transaction { const tx = { ...txRpc, - blockNumber: !_.isNull(txRpc.blockNumber) ? utils.convertHexToNumber(txRpc.blockNumber) : null, + blockNumber: !_.isNull(txRpc.blockNumber) ? conversion.convertHexToNumber(txRpc.blockNumber) : null, transactionIndex: !_.isNull(txRpc.transactionIndex) - ? utils.convertHexToNumber(txRpc.transactionIndex) + ? conversion.convertHexToNumber(txRpc.transactionIndex) : null, - nonce: utils.convertHexToNumber(txRpc.nonce), - gas: utils.convertHexToNumber(txRpc.gas), - gasPrice: utils.convertAmountToBigNumber(txRpc.gasPrice), - value: utils.convertAmountToBigNumber(txRpc.value), + nonce: conversion.convertHexToNumber(txRpc.nonce), + gas: conversion.convertHexToNumber(txRpc.gas), + gasPrice: conversion.convertAmountToBigNumber(txRpc.gasPrice), + value: conversion.convertAmountToBigNumber(txRpc.value), }; return tx; }, @@ -79,10 +81,12 @@ export const marshaller = { } const txData = { ...txDataRpc, - 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, + value: !_.isUndefined(txDataRpc.value) ? conversion.convertHexToNumber(txDataRpc.value) : undefined, + gas: !_.isUndefined(txDataRpc.gas) ? conversion.convertHexToNumber(txDataRpc.gas) : undefined, + gasPrice: !_.isUndefined(txDataRpc.gasPrice) + ? conversion.convertHexToNumber(txDataRpc.gasPrice) + : undefined, + nonce: !_.isUndefined(txDataRpc.nonce) ? conversion.convertHexToNumber(txDataRpc.nonce) : undefined, }; return txData; }, @@ -129,15 +133,15 @@ export const marshaller = { if (_.isUndefined(blockParam)) { return BlockParamLiteral.Latest; } - const encodedBlockParam = _.isNumber(blockParam) ? utils.numberToHex(blockParam) : blockParam; + const encodedBlockParam = _.isNumber(blockParam) ? conversion.numberToHex(blockParam) : blockParam; return encodedBlockParam; }, unmarshalLog(rawLog: RawLogEntry): LogEntry { const formattedLog = { ...rawLog, - logIndex: utils.convertHexToNumberOrNull(rawLog.logIndex), - blockNumber: utils.convertHexToNumberOrNull(rawLog.blockNumber), - transactionIndex: utils.convertHexToNumberOrNull(rawLog.transactionIndex), + logIndex: conversion.convertHexToNumberOrNull(rawLog.logIndex), + blockNumber: conversion.convertHexToNumberOrNull(rawLog.blockNumber), + transactionIndex: conversion.convertHexToNumberOrNull(rawLog.transactionIndex), }; return formattedLog; }, @@ -147,14 +151,14 @@ export const marshaller = { to: _.isUndefined(callTxDataBase.to) ? undefined : this.marshalAddress(callTxDataBase.to), gasPrice: _.isUndefined(callTxDataBase.gasPrice) ? undefined - : utils.encodeAmountAsHexString(callTxDataBase.gasPrice), - gas: _.isUndefined(callTxDataBase.gas) ? undefined : utils.encodeAmountAsHexString(callTxDataBase.gas), + : conversion.encodeAmountAsHexString(callTxDataBase.gasPrice), + gas: _.isUndefined(callTxDataBase.gas) ? undefined : conversion.encodeAmountAsHexString(callTxDataBase.gas), value: _.isUndefined(callTxDataBase.value) ? undefined - : utils.encodeAmountAsHexString(callTxDataBase.value), + : conversion.encodeAmountAsHexString(callTxDataBase.value), nonce: _.isUndefined(callTxDataBase.nonce) ? undefined - : utils.encodeAmountAsHexString(callTxDataBase.nonce), + : conversion.encodeAmountAsHexString(callTxDataBase.nonce), }; return callTxDataBaseRPC; diff --git a/packages/web3-wrapper/src/utils.ts b/packages/web3-wrapper/src/utils.ts deleted file mode 100644 index d13eb9404..000000000 --- a/packages/web3-wrapper/src/utils.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { BigNumber } from '@0xproject/utils'; -import * as _ from 'lodash'; - -export const utils = { - isBigNumber(value: any): boolean { - const isBigNumber = _.isObject(value) && value.isBigNumber; - return isBigNumber; - }, - convertHexToNumber(value: string): number { - const valueBigNumber = new BigNumber(value); - const valueNumber = valueBigNumber.toNumber(); - return valueNumber; - }, - convertHexToNumberOrNull(hex: string | null): number | null { - if (_.isNull(hex)) { - return null; - } - const decimal = this.convertHexToNumber(hex); - return decimal; - }, - convertAmountToBigNumber(value: string | number | BigNumber): BigNumber { - const num = value || 0; - const isBigNumber = utils.isBigNumber(num); - if (isBigNumber) { - return num as BigNumber; - } - - if (_.isString(num) && (num.indexOf('0x') === 0 || num.indexOf('-0x') === 0)) { - return new BigNumber(num.replace('0x', ''), 16); - } - - const baseTen = 10; - return new BigNumber((num as number).toString(baseTen), baseTen); - }, - encodeAmountAsHexString(value: string | number | BigNumber): string { - const valueBigNumber = utils.convertAmountToBigNumber(value); - const hexBase = 16; - const valueHex = valueBigNumber.toString(hexBase); - - return valueBigNumber.lessThan(0) ? '-0x' + valueHex.substr(1) : '0x' + valueHex; - }, - numberToHex(value: number): string { - if (!isFinite(value) && !this.isHexStrict(value)) { - throw new Error(`Given input ${value} is not a number.`); - } - - const valueBigNumber = new BigNumber(value); - const hexBase = 16; - const result = valueBigNumber.toString(hexBase); - - return valueBigNumber.lt(0) ? '-0x' + result.substr(1) : '0x' + result; - }, - isHexStrict(hex: string | number): boolean { - return ( - (_.isString(hex) || _.isNumber(hex)) && /^(-)?0x[0-9a-f]*$/i.test(_.isNumber(hex) ? hex.toString() : hex) - ); - }, -}; diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts index 495523e44..f6f818279 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, intervalUtils, promisify } from '@0xproject/utils'; +import { AbiDecoder, addressUtils, BigNumber, intervalUtils, promisify, conversion as utils } from '@0xproject/utils'; import { BlockParam, BlockParamLiteral, @@ -23,7 +23,6 @@ import * as _ from 'lodash'; import { marshaller } from './marshaller'; import { BlockWithoutTransactionDataRPC, BlockWithTransactionDataRPC, Web3WrapperErrors } from './types'; -import { utils } from './utils'; const BASE_TEN = 10; -- cgit v1.2.3 From aefc122cafc3e1b233450b07a1a4c70c2dc04ddd Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 5 Jul 2018 18:38:25 -0700 Subject: Add conversion utility file --- packages/utils/src/conversion.ts | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 packages/utils/src/conversion.ts diff --git a/packages/utils/src/conversion.ts b/packages/utils/src/conversion.ts new file mode 100644 index 000000000..f0eed9ee4 --- /dev/null +++ b/packages/utils/src/conversion.ts @@ -0,0 +1,59 @@ +import * as _ from 'lodash'; + +import { BigNumber } from './configured_bignumber'; + +export const conversion = { + isBigNumber(value: any): boolean { + const isBigNumber = _.isObject(value) && value.isBigNumber; + return isBigNumber; + }, + convertHexToNumber(value: string): number { + const valueBigNumber = new BigNumber(value); + const valueNumber = valueBigNumber.toNumber(); + return valueNumber; + }, + convertHexToNumberOrNull(hex: string | null): number | null { + if (_.isNull(hex)) { + return null; + } + const decimal = this.convertHexToNumber(hex); + return decimal; + }, + convertAmountToBigNumber(value: string | number | BigNumber): BigNumber { + const num = value || 0; + const isBigNumber = conversion.isBigNumber(num); + if (isBigNumber) { + return num as BigNumber; + } + + if (_.isString(num) && (num.indexOf('0x') === 0 || num.indexOf('-0x') === 0)) { + return new BigNumber(num.replace('0x', ''), 16); + } + + const baseTen = 10; + return new BigNumber((num as number).toString(baseTen), baseTen); + }, + encodeAmountAsHexString(value: string | number | BigNumber): string { + const valueBigNumber = conversion.convertAmountToBigNumber(value); + const hexBase = 16; + const valueHex = valueBigNumber.toString(hexBase); + + return valueBigNumber.lessThan(0) ? '-0x' + valueHex.substr(1) : '0x' + valueHex; + }, + numberToHex(value: number): string { + if (!isFinite(value) && !this.isHexStrict(value)) { + throw new Error(`Given input ${value} is not a number.`); + } + + const valueBigNumber = new BigNumber(value); + const hexBase = 16; + const result = valueBigNumber.toString(hexBase); + + return valueBigNumber.lt(0) ? '-0x' + result.substr(1) : '0x' + result; + }, + isHexStrict(hex: string | number): boolean { + return ( + (_.isString(hex) || _.isNumber(hex)) && /^(-)?0x[0-9a-f]*$/i.test(_.isNumber(hex) ? hex.toString() : hex) + ); + }, +}; -- cgit v1.2.3 From 608442b2e80f64c1756e2c5125812c067e5ae1f3 Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 5 Jul 2018 18:56:58 -0700 Subject: Add to changelog, rename to formatUtils and lint --- packages/utils/CHANGELOG.json | 4 ++ packages/utils/src/conversion.ts | 59 --------------------------- packages/utils/src/index.ts | 2 +- packages/web3-wrapper/src/marshaller.ts | 68 ++++++++++++++++--------------- packages/web3-wrapper/src/web3_wrapper.ts | 2 +- 5 files changed, 41 insertions(+), 94 deletions(-) delete mode 100644 packages/utils/src/conversion.ts diff --git a/packages/utils/CHANGELOG.json b/packages/utils/CHANGELOG.json index a27216be7..bea6a9566 100644 --- a/packages/utils/CHANGELOG.json +++ b/packages/utils/CHANGELOG.json @@ -12,6 +12,10 @@ { "note": "Fixes uncaught Error in abi_decoder", "pr": 763 + }, + { + "note": "Add formatUtils", + "pr": 829 } ] }, diff --git a/packages/utils/src/conversion.ts b/packages/utils/src/conversion.ts deleted file mode 100644 index f0eed9ee4..000000000 --- a/packages/utils/src/conversion.ts +++ /dev/null @@ -1,59 +0,0 @@ -import * as _ from 'lodash'; - -import { BigNumber } from './configured_bignumber'; - -export const conversion = { - isBigNumber(value: any): boolean { - const isBigNumber = _.isObject(value) && value.isBigNumber; - return isBigNumber; - }, - convertHexToNumber(value: string): number { - const valueBigNumber = new BigNumber(value); - const valueNumber = valueBigNumber.toNumber(); - return valueNumber; - }, - convertHexToNumberOrNull(hex: string | null): number | null { - if (_.isNull(hex)) { - return null; - } - const decimal = this.convertHexToNumber(hex); - return decimal; - }, - convertAmountToBigNumber(value: string | number | BigNumber): BigNumber { - const num = value || 0; - const isBigNumber = conversion.isBigNumber(num); - if (isBigNumber) { - return num as BigNumber; - } - - if (_.isString(num) && (num.indexOf('0x') === 0 || num.indexOf('-0x') === 0)) { - return new BigNumber(num.replace('0x', ''), 16); - } - - const baseTen = 10; - return new BigNumber((num as number).toString(baseTen), baseTen); - }, - encodeAmountAsHexString(value: string | number | BigNumber): string { - const valueBigNumber = conversion.convertAmountToBigNumber(value); - const hexBase = 16; - const valueHex = valueBigNumber.toString(hexBase); - - return valueBigNumber.lessThan(0) ? '-0x' + valueHex.substr(1) : '0x' + valueHex; - }, - numberToHex(value: number): string { - if (!isFinite(value) && !this.isHexStrict(value)) { - throw new Error(`Given input ${value} is not a number.`); - } - - const valueBigNumber = new BigNumber(value); - const hexBase = 16; - const result = valueBigNumber.toString(hexBase); - - return valueBigNumber.lt(0) ? '-0x' + result.substr(1) : '0x' + result; - }, - isHexStrict(hex: string | number): boolean { - return ( - (_.isString(hex) || _.isNumber(hex)) && /^(-)?0x[0-9a-f]*$/i.test(_.isNumber(hex) ? hex.toString() : hex) - ); - }, -}; diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index de78f26df..cc8592400 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -8,4 +8,4 @@ export { logUtils } from './log_utils'; export { abiUtils } from './abi_utils'; export { NULL_BYTES } from './constants'; export { errorUtils } from './error_utils'; -export { conversion } from './conversion'; +export { formatUtils } from './format_utils'; diff --git a/packages/web3-wrapper/src/marshaller.ts b/packages/web3-wrapper/src/marshaller.ts index b4a1e2ce4..584f6252d 100644 --- a/packages/web3-wrapper/src/marshaller.ts +++ b/packages/web3-wrapper/src/marshaller.ts @@ -1,4 +1,4 @@ -import { addressUtils, conversion } from '@0xproject/utils'; +import { addressUtils, formatUtils } from '@0xproject/utils'; import { BlockParam, BlockParamLiteral, @@ -29,30 +29,30 @@ export const marshaller = { ): BlockWithoutTransactionData { const block = { ...blockWithHexValues, - gasLimit: conversion.convertHexToNumber(blockWithHexValues.gasLimit), - gasUsed: conversion.convertHexToNumber(blockWithHexValues.gasUsed), - size: conversion.convertHexToNumber(blockWithHexValues.size), - timestamp: conversion.convertHexToNumber(blockWithHexValues.timestamp), + 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 - : conversion.convertHexToNumber(blockWithHexValues.number), - difficulty: conversion.convertAmountToBigNumber(blockWithHexValues.difficulty), - totalDifficulty: conversion.convertAmountToBigNumber(blockWithHexValues.totalDifficulty), + : formatUtils.convertHexToNumber(blockWithHexValues.number), + difficulty: formatUtils.convertAmountToBigNumber(blockWithHexValues.difficulty), + totalDifficulty: formatUtils.convertAmountToBigNumber(blockWithHexValues.totalDifficulty), }; return block; }, unmarshalIntoBlockWithTransactionData(blockWithHexValues: BlockWithTransactionDataRPC): BlockWithTransactionData { const block = { ...blockWithHexValues, - gasLimit: conversion.convertHexToNumber(blockWithHexValues.gasLimit), - gasUsed: conversion.convertHexToNumber(blockWithHexValues.gasUsed), - size: conversion.convertHexToNumber(blockWithHexValues.size), - timestamp: conversion.convertHexToNumber(blockWithHexValues.timestamp), + 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 - : conversion.convertHexToNumber(blockWithHexValues.number), - difficulty: conversion.convertAmountToBigNumber(blockWithHexValues.difficulty), - totalDifficulty: conversion.convertAmountToBigNumber(blockWithHexValues.totalDifficulty), + : formatUtils.convertHexToNumber(blockWithHexValues.number), + difficulty: formatUtils.convertAmountToBigNumber(blockWithHexValues.difficulty), + totalDifficulty: formatUtils.convertAmountToBigNumber(blockWithHexValues.totalDifficulty), transactions: [] as Transaction[], }; block.transactions = _.map(blockWithHexValues.transactions, (tx: TransactionRPC) => { @@ -64,14 +64,14 @@ export const marshaller = { unmarshalTransaction(txRpc: TransactionRPC): Transaction { const tx = { ...txRpc, - blockNumber: !_.isNull(txRpc.blockNumber) ? conversion.convertHexToNumber(txRpc.blockNumber) : null, + blockNumber: !_.isNull(txRpc.blockNumber) ? formatUtils.convertHexToNumber(txRpc.blockNumber) : null, transactionIndex: !_.isNull(txRpc.transactionIndex) - ? conversion.convertHexToNumber(txRpc.transactionIndex) + ? formatUtils.convertHexToNumber(txRpc.transactionIndex) : null, - nonce: conversion.convertHexToNumber(txRpc.nonce), - gas: conversion.convertHexToNumber(txRpc.gas), - gasPrice: conversion.convertAmountToBigNumber(txRpc.gasPrice), - value: conversion.convertAmountToBigNumber(txRpc.value), + nonce: formatUtils.convertHexToNumber(txRpc.nonce), + gas: formatUtils.convertHexToNumber(txRpc.gas), + gasPrice: formatUtils.convertAmountToBigNumber(txRpc.gasPrice), + value: formatUtils.convertAmountToBigNumber(txRpc.value), }; return tx; }, @@ -81,12 +81,12 @@ export const marshaller = { } const txData = { ...txDataRpc, - value: !_.isUndefined(txDataRpc.value) ? conversion.convertHexToNumber(txDataRpc.value) : undefined, - gas: !_.isUndefined(txDataRpc.gas) ? conversion.convertHexToNumber(txDataRpc.gas) : undefined, + value: !_.isUndefined(txDataRpc.value) ? formatUtils.convertHexToNumber(txDataRpc.value) : undefined, + gas: !_.isUndefined(txDataRpc.gas) ? formatUtils.convertHexToNumber(txDataRpc.gas) : undefined, gasPrice: !_.isUndefined(txDataRpc.gasPrice) - ? conversion.convertHexToNumber(txDataRpc.gasPrice) + ? formatUtils.convertHexToNumber(txDataRpc.gasPrice) : undefined, - nonce: !_.isUndefined(txDataRpc.nonce) ? conversion.convertHexToNumber(txDataRpc.nonce) : undefined, + nonce: !_.isUndefined(txDataRpc.nonce) ? formatUtils.convertHexToNumber(txDataRpc.nonce) : undefined, }; return txData; }, @@ -133,15 +133,15 @@ export const marshaller = { if (_.isUndefined(blockParam)) { return BlockParamLiteral.Latest; } - const encodedBlockParam = _.isNumber(blockParam) ? conversion.numberToHex(blockParam) : blockParam; + const encodedBlockParam = _.isNumber(blockParam) ? formatUtils.numberToHex(blockParam) : blockParam; return encodedBlockParam; }, unmarshalLog(rawLog: RawLogEntry): LogEntry { const formattedLog = { ...rawLog, - logIndex: conversion.convertHexToNumberOrNull(rawLog.logIndex), - blockNumber: conversion.convertHexToNumberOrNull(rawLog.blockNumber), - transactionIndex: conversion.convertHexToNumberOrNull(rawLog.transactionIndex), + logIndex: formatUtils.convertHexToNumberOrNull(rawLog.logIndex), + blockNumber: formatUtils.convertHexToNumberOrNull(rawLog.blockNumber), + transactionIndex: formatUtils.convertHexToNumberOrNull(rawLog.transactionIndex), }; return formattedLog; }, @@ -151,14 +151,16 @@ export const marshaller = { to: _.isUndefined(callTxDataBase.to) ? undefined : this.marshalAddress(callTxDataBase.to), gasPrice: _.isUndefined(callTxDataBase.gasPrice) ? undefined - : conversion.encodeAmountAsHexString(callTxDataBase.gasPrice), - gas: _.isUndefined(callTxDataBase.gas) ? undefined : conversion.encodeAmountAsHexString(callTxDataBase.gas), + : formatUtils.encodeAmountAsHexString(callTxDataBase.gasPrice), + gas: _.isUndefined(callTxDataBase.gas) + ? undefined + : formatUtils.encodeAmountAsHexString(callTxDataBase.gas), value: _.isUndefined(callTxDataBase.value) ? undefined - : conversion.encodeAmountAsHexString(callTxDataBase.value), + : formatUtils.encodeAmountAsHexString(callTxDataBase.value), nonce: _.isUndefined(callTxDataBase.nonce) ? undefined - : conversion.encodeAmountAsHexString(callTxDataBase.nonce), + : formatUtils.encodeAmountAsHexString(callTxDataBase.nonce), }; return callTxDataBaseRPC; diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts index f6f818279..57ad0a0db 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, intervalUtils, promisify, conversion as utils } from '@0xproject/utils'; +import { AbiDecoder, addressUtils, BigNumber, formatUtils as utils, intervalUtils, promisify } from '@0xproject/utils'; import { BlockParam, BlockParamLiteral, -- cgit v1.2.3 From 188bf000b784fe6d9e24e3758a30a72a2795bc58 Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 5 Jul 2018 18:59:01 -0700 Subject: Add formatUtils --- packages/utils/src/format_utils.ts | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 packages/utils/src/format_utils.ts diff --git a/packages/utils/src/format_utils.ts b/packages/utils/src/format_utils.ts new file mode 100644 index 000000000..101854926 --- /dev/null +++ b/packages/utils/src/format_utils.ts @@ -0,0 +1,61 @@ +import * as _ from 'lodash'; + +import { BigNumber } from './configured_bignumber'; + +// tslint:disable:restrict-plus-operands +export const formatUtils = { + isBigNumber(value: any): boolean { + const isBigNumber = _.isObject(value) && value.isBigNumber; + return isBigNumber; + }, + convertHexToNumber(value: string): number { + const valueBigNumber = new BigNumber(value); + const valueNumber = valueBigNumber.toNumber(); + return valueNumber; + }, + convertHexToNumberOrNull(hex: string | null): number | null { + if (_.isNull(hex)) { + return null; + } + const decimal = this.convertHexToNumber(hex); + return decimal; + }, + convertAmountToBigNumber(value: string | number | BigNumber): BigNumber { + const num = value || 0; + const isBigNumber = formatUtils.isBigNumber(num); + if (isBigNumber) { + return num as BigNumber; + } + + if (_.isString(num) && (num.indexOf('0x') === 0 || num.indexOf('-0x') === 0)) { + return new BigNumber(num.replace('0x', ''), 16); + } + + const baseTen = 10; + return new BigNumber((num as number).toString(baseTen), baseTen); + }, + encodeAmountAsHexString(value: string | number | BigNumber): string { + const valueBigNumber = formatUtils.convertAmountToBigNumber(value); + const hexBase = 16; + const valueHex = valueBigNumber.toString(hexBase); + + return valueBigNumber.lessThan(0) ? '-0x' + valueHex.substr(1) : '0x' + valueHex; + }, + numberToHex(value: number): string { + if (!isFinite(value) && !this.isHexStrict(value)) { + throw new Error(`Given input ${value} is not a number.`); + } + + const valueBigNumber = new BigNumber(value); + const hexBase = 16; + const result = valueBigNumber.toString(hexBase); + + return valueBigNumber.lt(0) ? '-0x' + result.substr(1) : '0x' + result; + }, + isHexStrict(hex: string | number): boolean { + return ( + (_.isString(hex) || _.isNumber(hex)) && /^(-)?0x[0-9a-f]*$/i.test(_.isNumber(hex) ? hex.toString() : hex) + ); + }, +}; +// tslint:enable:restrict-plus-operands -- cgit v1.2.3 From acfbba5476d48645eee7f471ecaa4b1142709939 Mon Sep 17 00:00:00 2001 From: fragosti Date: Fri, 6 Jul 2018 10:23:24 -0700 Subject: Revert moving formatUtils into utils --- packages/subproviders/src/subproviders/signer.ts | 6 +- packages/utils/CHANGELOG.json | 4 -- packages/utils/src/format_utils.ts | 61 ------------------- packages/utils/src/index.ts | 1 - packages/web3-wrapper/src/index.ts | 1 - packages/web3-wrapper/src/marshaller.ts | 76 +++++++++++------------- packages/web3-wrapper/src/utils.ts | 58 ++++++++++++++++++ packages/web3-wrapper/src/web3_wrapper.ts | 3 +- 8 files changed, 97 insertions(+), 113 deletions(-) delete mode 100644 packages/utils/src/format_utils.ts create mode 100644 packages/web3-wrapper/src/utils.ts 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/format_utils.ts b/packages/utils/src/format_utils.ts deleted file mode 100644 index 101854926..000000000 --- a/packages/utils/src/format_utils.ts +++ /dev/null @@ -1,61 +0,0 @@ -import * as _ from 'lodash'; - -import { BigNumber } from './configured_bignumber'; - -// tslint:disable:restrict-plus-operands -export const formatUtils = { - isBigNumber(value: any): boolean { - const isBigNumber = _.isObject(value) && value.isBigNumber; - return isBigNumber; - }, - convertHexToNumber(value: string): number { - const valueBigNumber = new BigNumber(value); - const valueNumber = valueBigNumber.toNumber(); - return valueNumber; - }, - convertHexToNumberOrNull(hex: string | null): number | null { - if (_.isNull(hex)) { - return null; - } - const decimal = this.convertHexToNumber(hex); - return decimal; - }, - convertAmountToBigNumber(value: string | number | BigNumber): BigNumber { - const num = value || 0; - const isBigNumber = formatUtils.isBigNumber(num); - if (isBigNumber) { - return num as BigNumber; - } - - if (_.isString(num) && (num.indexOf('0x') === 0 || num.indexOf('-0x') === 0)) { - return new BigNumber(num.replace('0x', ''), 16); - } - - const baseTen = 10; - return new BigNumber((num as number).toString(baseTen), baseTen); - }, - encodeAmountAsHexString(value: string | number | BigNumber): string { - const valueBigNumber = formatUtils.convertAmountToBigNumber(value); - const hexBase = 16; - const valueHex = valueBigNumber.toString(hexBase); - - return valueBigNumber.lessThan(0) ? '-0x' + valueHex.substr(1) : '0x' + valueHex; - }, - numberToHex(value: number): string { - if (!isFinite(value) && !this.isHexStrict(value)) { - throw new Error(`Given input ${value} is not a number.`); - } - - const valueBigNumber = new BigNumber(value); - const hexBase = 16; - const result = valueBigNumber.toString(hexBase); - - return valueBigNumber.lt(0) ? '-0x' + result.substr(1) : '0x' + result; - }, - isHexStrict(hex: string | number): boolean { - return ( - (_.isString(hex) || _.isNumber(hex)) && /^(-)?0x[0-9a-f]*$/i.test(_.isNumber(hex) ? hex.toString() : hex) - ); - }, -}; -// tslint:enable:restrict-plus-operands 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/web3-wrapper/src/utils.ts b/packages/web3-wrapper/src/utils.ts new file mode 100644 index 000000000..d13eb9404 --- /dev/null +++ b/packages/web3-wrapper/src/utils.ts @@ -0,0 +1,58 @@ +import { BigNumber } from '@0xproject/utils'; +import * as _ from 'lodash'; + +export const utils = { + isBigNumber(value: any): boolean { + const isBigNumber = _.isObject(value) && value.isBigNumber; + return isBigNumber; + }, + convertHexToNumber(value: string): number { + const valueBigNumber = new BigNumber(value); + const valueNumber = valueBigNumber.toNumber(); + return valueNumber; + }, + convertHexToNumberOrNull(hex: string | null): number | null { + if (_.isNull(hex)) { + return null; + } + const decimal = this.convertHexToNumber(hex); + return decimal; + }, + convertAmountToBigNumber(value: string | number | BigNumber): BigNumber { + const num = value || 0; + const isBigNumber = utils.isBigNumber(num); + if (isBigNumber) { + return num as BigNumber; + } + + if (_.isString(num) && (num.indexOf('0x') === 0 || num.indexOf('-0x') === 0)) { + return new BigNumber(num.replace('0x', ''), 16); + } + + const baseTen = 10; + return new BigNumber((num as number).toString(baseTen), baseTen); + }, + encodeAmountAsHexString(value: string | number | BigNumber): string { + const valueBigNumber = utils.convertAmountToBigNumber(value); + const hexBase = 16; + const valueHex = valueBigNumber.toString(hexBase); + + return valueBigNumber.lessThan(0) ? '-0x' + valueHex.substr(1) : '0x' + valueHex; + }, + numberToHex(value: number): string { + if (!isFinite(value) && !this.isHexStrict(value)) { + throw new Error(`Given input ${value} is not a number.`); + } + + const valueBigNumber = new BigNumber(value); + const hexBase = 16; + const result = valueBigNumber.toString(hexBase); + + return valueBigNumber.lt(0) ? '-0x' + result.substr(1) : '0x' + result; + }, + isHexStrict(hex: string | number): boolean { + return ( + (_.isString(hex) || _.isNumber(hex)) && /^(-)?0x[0-9a-f]*$/i.test(_.isNumber(hex) ? hex.toString() : hex) + ); + }, +}; 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; -- cgit v1.2.3 From c753e24f0a84ae6410128cd05f1ad6932a4110a4 Mon Sep 17 00:00:00 2001 From: fragosti Date: Fri, 6 Jul 2018 10:35:13 -0700 Subject: Export marshaller and use it to unmarshal tx dataa --- packages/subproviders/src/subproviders/signer.ts | 5 +++-- packages/web3-wrapper/CHANGELOG.json | 9 +++++++++ packages/web3-wrapper/src/index.ts | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/subproviders/src/subproviders/signer.ts b/packages/subproviders/src/subproviders/signer.ts index 08a9daceb..c6b25a7da 100644 --- a/packages/subproviders/src/subproviders/signer.ts +++ b/packages/subproviders/src/subproviders/signer.ts @@ -1,4 +1,4 @@ -import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Web3Wrapper, marshaller } from '@0xproject/web3-wrapper'; import { JSONRPCRequestPayload, Provider } from 'ethereum-types'; import { Callback, ErrorCallback } from '../types'; @@ -51,7 +51,8 @@ export class SignerSubprovider extends Subprovider { case 'eth_sendTransaction': const [txParams] = payload.params; try { - const txHash = await this._web3Wrapper.sendTransactionAsync(txParams); + const txData = marshaller.unmarshalTxData(txParams); + const txHash = await this._web3Wrapper.sendTransactionAsync(txData); end(null, txHash); } catch (err) { end(err); diff --git a/packages/web3-wrapper/CHANGELOG.json b/packages/web3-wrapper/CHANGELOG.json index f8b1dab85..fcbedbbf2 100644 --- a/packages/web3-wrapper/CHANGELOG.json +++ b/packages/web3-wrapper/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "0.7.3", + "changes": [ + { + "note": "Export `marshaller` utility file.", + "pr": 829 + } + ] + }, { "timestamp": 1529397769, "version": "0.7.2", diff --git a/packages/web3-wrapper/src/index.ts b/packages/web3-wrapper/src/index.ts index 66ef0a784..19fe0836c 100644 --- a/packages/web3-wrapper/src/index.ts +++ b/packages/web3-wrapper/src/index.ts @@ -1,2 +1,3 @@ export { Web3Wrapper, uniqueVersionIds, NodeType } from './web3_wrapper'; export { Web3WrapperErrors } from './types'; +export { marshaller } from './marshaller'; -- cgit v1.2.3 From 72fb1ee36f5ca7bceebb1ad2eac707295ccbe9c2 Mon Sep 17 00:00:00 2001 From: fragosti Date: Fri, 6 Jul 2018 11:30:01 -0700 Subject: Fix linting issues --- packages/subproviders/src/subproviders/signer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/subproviders/src/subproviders/signer.ts b/packages/subproviders/src/subproviders/signer.ts index c6b25a7da..f7329e00c 100644 --- a/packages/subproviders/src/subproviders/signer.ts +++ b/packages/subproviders/src/subproviders/signer.ts @@ -1,4 +1,4 @@ -import { Web3Wrapper, marshaller } from '@0xproject/web3-wrapper'; +import { marshaller, Web3Wrapper } from '@0xproject/web3-wrapper'; import { JSONRPCRequestPayload, Provider } from 'ethereum-types'; import { Callback, ErrorCallback } from '../types'; -- cgit v1.2.3