diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-10-04 14:14:55 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-10-04 14:22:13 +0800 |
commit | 059162a90a3d26e5fdfefd8553bb1f721a3116fc (patch) | |
tree | bb3dfc2ef2cefb1d78d65fb7318e8e1c6884a09e /packages/order-utils/src | |
parent | 250a9a480940ae4fca48109aae97ee0323d57a52 (diff) | |
download | dexon-sol-tools-059162a90a3d26e5fdfefd8553bb1f721a3116fc.tar dexon-sol-tools-059162a90a3d26e5fdfefd8553bb1f721a3116fc.tar.gz dexon-sol-tools-059162a90a3d26e5fdfefd8553bb1f721a3116fc.tar.bz2 dexon-sol-tools-059162a90a3d26e5fdfefd8553bb1f721a3116fc.tar.lz dexon-sol-tools-059162a90a3d26e5fdfefd8553bb1f721a3116fc.tar.xz dexon-sol-tools-059162a90a3d26e5fdfefd8553bb1f721a3116fc.tar.zst dexon-sol-tools-059162a90a3d26e5fdfefd8553bb1f721a3116fc.zip |
Add additional order factory methods and refactor test to use them
Diffstat (limited to 'packages/order-utils/src')
-rw-r--r-- | packages/order-utils/src/order_factory.ts | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/packages/order-utils/src/order_factory.ts b/packages/order-utils/src/order_factory.ts index 46a69ae4d..b1292903a 100644 --- a/packages/order-utils/src/order_factory.ts +++ b/packages/order-utils/src/order_factory.ts @@ -8,8 +8,21 @@ import { orderHashUtils } from './order_hash'; import { generatePseudoRandomSalt } from './salt'; import { signatureUtils } from './signature_utils'; import { CreateOrderOpts } from './types'; - export const orderFactory = { + createOrderFromPartial(partialOrder: Partial<Order>): Order { + const defaultOrder = generateEmptyOrder(); + return { + ...defaultOrder, + ...partialOrder, + }; + }, + createSignedOrderFromPartial(partialSignedOrder: Partial<SignedOrder>): SignedOrder { + const defaultOrder = generateEmptySignedOrder(); + return { + ...defaultOrder, + ...partialSignedOrder, + }; + }, createOrder( makerAddress: string, makerAssetAmount: BigNumber, @@ -69,6 +82,30 @@ export const orderFactory = { }, }; +function generateEmptySignedOrder(): SignedOrder { + return { + ...generateEmptyOrder(), + signature: constants.NULL_BYTES, + }; +} +function generateEmptyOrder(): Order { + return { + senderAddress: constants.NULL_ADDRESS, + makerAddress: constants.NULL_ADDRESS, + takerAddress: constants.NULL_ADDRESS, + makerFee: constants.ZERO_AMOUNT, + takerFee: constants.ZERO_AMOUNT, + makerAssetAmount: constants.ZERO_AMOUNT, + takerAssetAmount: constants.ZERO_AMOUNT, + makerAssetData: constants.NULL_BYTES, + takerAssetData: constants.NULL_BYTES, + salt: generatePseudoRandomSalt(), + exchangeAddress: constants.NULL_ADDRESS, + feeRecipientAddress: constants.NULL_ADDRESS, + expirationTimeSeconds: constants.INFINITE_TIMESTAMP_SEC, + }; +} + function generateDefaultCreateOrderOpts(): { takerAddress: string; senderAddress: string; |