Move bigNumberToBN to utils module

This commit is contained in:
Fabio Berger 2017-05-29 09:06:24 +02:00
parent f338c68f12
commit 281b9eaa5d
2 changed files with 20 additions and 17 deletions

View File

@ -1,9 +1,9 @@
import * as BigNumber from 'bignumber.js'; import * as BigNumber from 'bignumber.js';
import * as BN from 'bn.js';
import * as ethUtil from 'ethereumjs-util'; import * as ethUtil from 'ethereumjs-util';
import * as ethABI from 'ethereumjs-abi'; import * as ethABI from 'ethereumjs-abi';
import * as _ from 'lodash'; import * as _ from 'lodash';
import {constants} from './utils/constants'; import {constants} from './utils/constants';
import {utils} from './utils/utils';
import {assert} from './utils/assert'; import {assert} from './utils/assert';
import {ECSignatureSchema} from './schemas/ec_signature_schema'; import {ECSignatureSchema} from './schemas/ec_signature_schema';
import {SolidityTypes} from './types'; import {SolidityTypes} from './types';
@ -49,12 +49,12 @@ export class ZeroEx {
{value: tokenMAddress, type: SolidityTypes.address}, {value: tokenMAddress, type: SolidityTypes.address},
{value: tokenTAddress, type: SolidityTypes.address}, {value: tokenTAddress, type: SolidityTypes.address},
{value: feeRecipient, type: SolidityTypes.address}, {value: feeRecipient, type: SolidityTypes.address},
{value: this.bigNumberToBN(valueM), type: SolidityTypes.uint256}, {value: utils.bigNumberToBN(valueM), type: SolidityTypes.uint256},
{value: this.bigNumberToBN(valueT), type: SolidityTypes.uint256}, {value: utils.bigNumberToBN(valueT), type: SolidityTypes.uint256},
{value: this.bigNumberToBN(makerFee), type: SolidityTypes.uint256}, {value: utils.bigNumberToBN(makerFee), type: SolidityTypes.uint256},
{value: this.bigNumberToBN(takerFee), type: SolidityTypes.uint256}, {value: utils.bigNumberToBN(takerFee), type: SolidityTypes.uint256},
{value: this.bigNumberToBN(expiration), type: SolidityTypes.uint256}, {value: utils.bigNumberToBN(expiration), type: SolidityTypes.uint256},
{value: this.bigNumberToBN(salt), type: SolidityTypes.uint256}, {value: utils.bigNumberToBN(salt), type: SolidityTypes.uint256},
]; ];
const types = _.map(orderParts, o => o.type); const types = _.map(orderParts, o => o.type);
const values = _.map(orderParts, o => o.value); const values = _.map(orderParts, o => o.value);
@ -129,14 +129,4 @@ export class ZeroEx {
const baseUnitAmount = amount.times(unit); const baseUnitAmount = amount.times(unit);
return baseUnitAmount; return baseUnitAmount;
} }
/**
* Converts BigNumber instance to BN
* The only we convert to BN is to remain compatible with `ethABI. soliditySHA3 ` that
* expects values of Solidity type `uint` to be of type `BN`.
* We do not use BN anywhere else in the codebase.
*/
private static bigNumberToBN(value: BigNumber.BigNumber) {
return new BN(value.toString(), 10);
}
} }

13
src/ts/utils/utils.ts Normal file
View File

@ -0,0 +1,13 @@
import * as BN from 'bn.js';
export const utils = {
/**
* Converts BigNumber instance to BN
* The only we convert to BN is to remain compatible with `ethABI. soliditySHA3 ` that
* expects values of Solidity type `uint` to be of type `BN`.
* We do not use BN anywhere else in the codebase.
*/
bigNumberToBN(value: BigNumber.BigNumber) {
return new BN(value.toString(), 10);
},
};