From fd004032cb23998184a78ac4a0a486ef1bd04c25 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 7 Feb 2018 12:22:22 +0100 Subject: Introduce SignedOrder class and remove type assertions --- packages/contracts/util/exchange_wrapper.ts | 50 ++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'packages/contracts/util/exchange_wrapper.ts') diff --git a/packages/contracts/util/exchange_wrapper.ts b/packages/contracts/util/exchange_wrapper.ts index e44a0eab6..ff263246f 100644 --- a/packages/contracts/util/exchange_wrapper.ts +++ b/packages/contracts/util/exchange_wrapper.ts @@ -6,7 +6,7 @@ import * as Web3 from 'web3'; import { ExchangeContract } from '../src/contract_wrappers/generated/exchange'; import { formatters } from './formatters'; -import { Order } from './order'; +import { SignedOrder } from './signed_order'; export class ExchangeWrapper { private _exchange: ExchangeContract; @@ -16,7 +16,7 @@ export class ExchangeWrapper { this._zeroEx = zeroEx; } public async fillOrderAsync( - order: Order, + signedOrder: SignedOrder, from: string, opts: { fillTakerTokenAmount?: BigNumber; @@ -24,15 +24,15 @@ export class ExchangeWrapper { } = {}, ): Promise { const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance; - const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount); + const params = signedOrder.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount); const txHash = await this._exchange.fillOrder.sendTransactionAsync( params.orderAddresses, params.orderValues, params.fillTakerTokenAmount, params.shouldThrowOnInsufficientBalanceOrAllowance, - params.v as number, - params.r as string, - params.s as string, + params.v, + params.r, + params.s, { from }, ); const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); @@ -41,11 +41,11 @@ export class ExchangeWrapper { return tx; } public async cancelOrderAsync( - order: Order, + signedOrder: SignedOrder, from: string, opts: { cancelTakerTokenAmount?: BigNumber } = {}, ): Promise { - const params = order.createCancel(opts.cancelTakerTokenAmount); + const params = signedOrder.createCancel(opts.cancelTakerTokenAmount); const txHash = await this._exchange.cancelOrder.sendTransactionAsync( params.orderAddresses, params.orderValues, @@ -58,19 +58,19 @@ export class ExchangeWrapper { return tx; } public async fillOrKillOrderAsync( - order: Order, + signedOrder: SignedOrder, from: string, opts: { fillTakerTokenAmount?: BigNumber } = {}, ): Promise { const shouldThrowOnInsufficientBalanceOrAllowance = true; - const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount); + const params = signedOrder.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount); const txHash = await this._exchange.fillOrKillOrder.sendTransactionAsync( params.orderAddresses, params.orderValues, params.fillTakerTokenAmount, - params.v as number, - params.r as string, - params.s as string, + params.v, + params.r, + params.s, { from }, ); const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); @@ -79,7 +79,7 @@ export class ExchangeWrapper { return tx; } public async batchFillOrdersAsync( - orders: Order[], + orders: SignedOrder[], from: string, opts: { fillTakerTokenAmounts?: BigNumber[]; @@ -108,7 +108,7 @@ export class ExchangeWrapper { return tx; } public async batchFillOrKillOrdersAsync( - orders: Order[], + orders: SignedOrder[], from: string, opts: { fillTakerTokenAmounts?: BigNumber[]; shouldThrowOnInsufficientBalanceOrAllowance?: boolean } = {}, ): Promise { @@ -133,7 +133,7 @@ export class ExchangeWrapper { return tx; } public async fillOrdersUpToAsync( - orders: Order[], + orders: SignedOrder[], from: string, opts: { fillTakerTokenAmount: BigNumber; shouldThrowOnInsufficientBalanceOrAllowance?: boolean }, ): Promise { @@ -159,7 +159,7 @@ export class ExchangeWrapper { return tx; } public async batchCancelOrdersAsync( - orders: Order[], + orders: SignedOrder[], from: string, opts: { cancelTakerTokenAmounts?: BigNumber[] } = {}, ): Promise { @@ -175,19 +175,19 @@ export class ExchangeWrapper { _.each(tx.logs, log => wrapLogBigNumbers(log)); return tx; } - public async getOrderHashAsync(order: Order): Promise { + public async getOrderHashAsync(signedOrder: SignedOrder): Promise { const shouldThrowOnInsufficientBalanceOrAllowance = false; - const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance); + const params = signedOrder.createFill(shouldThrowOnInsufficientBalanceOrAllowance); const orderHash = await this._exchange.getOrderHash(params.orderAddresses, params.orderValues); return orderHash; } - public async isValidSignatureAsync(order: Order): Promise { + public async isValidSignatureAsync(signedOrder: SignedOrder): Promise { const isValidSignature = await this._exchange.isValidSignature( - order.params.maker, - order.getOrderHashHex(), - order.params.v as number, - order.params.r as string, - order.params.s as string, + signedOrder.params.maker, + signedOrder.getOrderHashHex(), + signedOrder.params.v, + signedOrder.params.r, + signedOrder.params.s, ); return isValidSignature; } -- cgit v1.2.3