From 568e4d33f29db2f5c0195585438e18ab4b2aea18 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 7 Feb 2018 13:41:30 +0100 Subject: Use Order and SignedOrder type from 0x.js --- packages/contracts/util/order_factory.ts | 44 +++++++++++++++++--------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'packages/contracts/util/order_factory.ts') diff --git a/packages/contracts/util/order_factory.ts b/packages/contracts/util/order_factory.ts index 788f60a88..8ba5df24a 100644 --- a/packages/contracts/util/order_factory.ts +++ b/packages/contracts/util/order_factory.ts @@ -1,33 +1,37 @@ -import { ZeroEx } from '0x.js'; +import { Order, SignedOrder, ZeroEx } from '0x.js'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; -import { Order } from './order'; -import { SignedOrder } from './signed_order'; -import { DefaultOrderParams, OptionalOrderParams, OrderParams } from './types'; +import { DefaultOrderParams } from './types'; export class OrderFactory { - private _defaultOrderParams: DefaultOrderParams; - private _web3Wrapper: Web3Wrapper; - constructor(web3Wrapper: Web3Wrapper, defaultOrderParams: DefaultOrderParams) { + private _defaultOrderParams: Partial; + private _zeroEx: ZeroEx; + constructor(zeroEx: ZeroEx, defaultOrderParams: Partial) { this._defaultOrderParams = defaultOrderParams; - this._web3Wrapper = web3Wrapper; + this._zeroEx = zeroEx; } - public async newSignedOrderAsync(customOrderParams: OptionalOrderParams = {}): Promise { + public async newSignedOrderAsync(customOrderParams: Partial = {}): Promise { const randomExpiration = new BigNumber(Math.floor((Date.now() + Math.random() * 100000000000) / 1000)); - const orderParams: OrderParams = _.assign( - {}, - { - expirationTimestampInSec: randomExpiration, - salt: ZeroEx.generatePseudoRandomSalt(), - taker: ZeroEx.NULL_ADDRESS, - }, - this._defaultOrderParams, - customOrderParams, + const order = ({ + expirationUnixTimestampSec: randomExpiration, + salt: ZeroEx.generatePseudoRandomSalt(), + taker: ZeroEx.NULL_ADDRESS, + ...this._defaultOrderParams, + ...customOrderParams, + } as any) as Order; + const orderHashHex = ZeroEx.getOrderHashHex(order); + const shouldAddPersonalMessagePrefix = false; + const ecSignature = await this._zeroEx.signOrderHashAsync( + orderHashHex, + order.maker, + shouldAddPersonalMessagePrefix, ); - const order = new Order(this._web3Wrapper, orderParams); - const signedOrder = await order.signAsync(); + const signedOrder = { + ...order, + ecSignature, + }; return signedOrder; } } -- cgit v1.2.3