diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-09-05 02:22:31 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-09-05 02:22:31 +0800 |
commit | a14450f367d1a1f651f85ac6b0ad710fc2785e83 (patch) | |
tree | d4794b722e27285f0978a99eb1ac890177df23de /packages | |
parent | e61dbbb6cf395d3bf807340cac8f99f224ec616e (diff) | |
download | dexon-sol-tools-a14450f367d1a1f651f85ac6b0ad710fc2785e83.tar dexon-sol-tools-a14450f367d1a1f651f85ac6b0ad710fc2785e83.tar.gz dexon-sol-tools-a14450f367d1a1f651f85ac6b0ad710fc2785e83.tar.bz2 dexon-sol-tools-a14450f367d1a1f651f85ac6b0ad710fc2785e83.tar.lz dexon-sol-tools-a14450f367d1a1f651f85ac6b0ad710fc2785e83.tar.xz dexon-sol-tools-a14450f367d1a1f651f85ac6b0ad710fc2785e83.tar.zst dexon-sol-tools-a14450f367d1a1f651f85ac6b0ad710fc2785e83.zip |
Add order parsers to order-util
Diffstat (limited to 'packages')
-rw-r--r-- | packages/order-utils/src/index.ts | 3 | ||||
-rw-r--r-- | packages/order-utils/src/parsing_utils.ts | 27 |
2 files changed, 29 insertions, 1 deletions
diff --git a/packages/order-utils/src/index.ts b/packages/order-utils/src/index.ts index 354299304..e727b3ef7 100644 --- a/packages/order-utils/src/index.ts +++ b/packages/order-utils/src/index.ts @@ -6,6 +6,7 @@ export { eip712Utils } from './eip712_utils'; export { marketUtils } from './market_utils'; export { rateUtils } from './rate_utils'; export { sortingUtils } from './sorting_utils'; +export { orderParsingUtils } from './parsing_utils'; export { OrderStateUtils } from './order_state_utils'; export { AbstractBalanceAndProxyAllowanceFetcher } from './abstract/abstract_balance_and_proxy_allowance_fetcher'; @@ -45,4 +46,4 @@ export { FindOrdersThatCoverMakerAssetFillAmountOpts, FeeOrdersAndRemainingFeeAmount, OrdersAndRemainingFillAmount, -} from './types'; +} from './types';
\ No newline at end of file diff --git a/packages/order-utils/src/parsing_utils.ts b/packages/order-utils/src/parsing_utils.ts new file mode 100644 index 000000000..73841c1a2 --- /dev/null +++ b/packages/order-utils/src/parsing_utils.ts @@ -0,0 +1,27 @@ +import { BigNumber } from '@0xproject/utils'; +import * as _ from 'lodash'; + +export const orderParsingUtils = { + convertStringsFieldsToBigNumbers(obj: any, fields: string[]): any { + const result = _.assign({}, obj); + _.each(fields, field => { + _.update(result, field, (value: string) => { + if (_.isUndefined(value)) { + throw new Error(`Could not find field '${field}' while converting string fields to BigNumber.`); + } + return new BigNumber(value); + }); + }); + return result; + }, + convertOrderStringFieldsToBigNumber(order: any): any { + return orderParsingUtils.convertStringsFieldsToBigNumbers(order, [ + 'makerAssetAmount', + 'takerAssetAmount', + 'makerFee', + 'takerFee', + 'expirationTimeSeconds', + 'salt', + ]); + } +}
\ No newline at end of file |