diff options
author | Leonid <logvinov.leon@gmail.com> | 2018-02-09 01:15:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-09 01:15:10 +0800 |
commit | 254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd (patch) | |
tree | ff8e4c1e59bcc71253f39ee92dc9740941504f37 /packages/contracts/util/order_factory.ts | |
parent | eebf205817d3d812a40158d146110c7868a42bf0 (diff) | |
parent | 876517d4580c864359898c572df8e081430c32ce (diff) | |
download | dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar.gz dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar.bz2 dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar.lz dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar.xz dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar.zst dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.zip |
Merge pull request #377 from 0xProject/feature/signed_unsigned_order_contracts
Use SignedOrder and Order types from 0x.js
Diffstat (limited to 'packages/contracts/util/order_factory.ts')
-rw-r--r-- | packages/contracts/util/order_factory.ts | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/packages/contracts/util/order_factory.ts b/packages/contracts/util/order_factory.ts index 2b50f13e8..8ba5df24a 100644 --- a/packages/contracts/util/order_factory.ts +++ b/packages/contracts/util/order_factory.ts @@ -1,32 +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 { 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<Order>; + private _zeroEx: ZeroEx; + constructor(zeroEx: ZeroEx, defaultOrderParams: Partial<Order>) { this._defaultOrderParams = defaultOrderParams; - this._web3Wrapper = web3Wrapper; + this._zeroEx = zeroEx; } - public async newSignedOrderAsync(customOrderParams: OptionalOrderParams = {}): Promise<Order> { + public async newSignedOrderAsync(customOrderParams: Partial<Order> = {}): Promise<SignedOrder> { 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); - await order.signAsync(); - return order; + const signedOrder = { + ...order, + ecSignature, + }; + return signedOrder; } } |