aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers/exchange_wrapper.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-06-07 20:40:28 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-06-07 20:40:28 +0800
commitc3cd5812e61359b18c469f70c9f0240db777e67a (patch)
tree829eb263a6fc8b036632ba0c769de0f67b78d209 /src/contract_wrappers/exchange_wrapper.ts
parent91101eb8ec4057617e644df4439c626093d4b3cc (diff)
downloaddexon-sol-tools-c3cd5812e61359b18c469f70c9f0240db777e67a.tar
dexon-sol-tools-c3cd5812e61359b18c469f70c9f0240db777e67a.tar.gz
dexon-sol-tools-c3cd5812e61359b18c469f70c9f0240db777e67a.tar.bz2
dexon-sol-tools-c3cd5812e61359b18c469f70c9f0240db777e67a.tar.lz
dexon-sol-tools-c3cd5812e61359b18c469f70c9f0240db777e67a.tar.xz
dexon-sol-tools-c3cd5812e61359b18c469f70c9f0240db777e67a.tar.zst
dexon-sol-tools-c3cd5812e61359b18c469f70c9f0240db777e67a.zip
Refactor to use OrderCancellationRequest
Diffstat (limited to 'src/contract_wrappers/exchange_wrapper.ts')
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index fec75e6df..f67a125aa 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -18,7 +18,7 @@ import {
CreateContractEvent,
ContractEventObj,
EventCallback,
- ContractResponse,
+ ContractResponse, OrderCancellationRequest,
} from '../types';
import {assert} from '../utils/assert';
import {utils} from '../utils/utils';
@@ -208,29 +208,31 @@ export class ExchangeWrapper extends ContractWrapper {
/**
* Batch version of cancelOrderAsync. Atomically cancels multiple orders in a single transaction.
*/
- public async batchCancelOrderAsync(
- orders: Array<Order|SignedOrder>, takerTokenCancelAmounts: BigNumber.BigNumber[]): Promise<void> {
- const makers = _.map(orders, order => order.maker);
- assert.isSameLength('orders', orders, 'takerTokenCancelAmounts', takerTokenCancelAmounts);
- assert.assert(!_.isEmpty(orders), 'Can not cancel an empty batch');
+ public async batchCancelOrderAsync(cancellationRequestsBatch: OrderCancellationRequest[]): Promise<void> {
+ const makers = _.map(cancellationRequestsBatch, cancellationRequest => cancellationRequest.order.maker);
+ assert.assert(!_.isEmpty(cancellationRequestsBatch), 'Can not cancel an empty batch');
assert.assert(_.uniq(makers).length === 1, 'Can not cancel orders from multiple makers in a single batch');
const maker = makers[0];
- // _.zip doesn't type check if values have different types :'(
- const ordersAndTakerTokenCancelAmounts = _.zip<any>(orders, takerTokenCancelAmounts);
- _.forEach(ordersAndTakerTokenCancelAmounts,
- async ([order, takerTokenCancelAmount]: [Order|SignedOrder, BigNumber.BigNumber]) => {
+ _.forEach(cancellationRequestsBatch,
+ async (cancellationRequest: OrderCancellationRequest) => {
assert.doesConformToSchema('order',
- SchemaValidator.convertToJSONSchemaCompatibleObject(order as object), orderSchema);
- assert.isBigNumber('takerTokenCancelAmount', takerTokenCancelAmount);
- await assert.isSenderAddressAvailableAsync(this.web3Wrapper, 'order.maker', order.maker);
- await this.validateCancelOrderAndThrowIfInvalidAsync(order, takerTokenCancelAmount);
+ SchemaValidator.convertToJSONSchemaCompatibleObject(cancellationRequest.order as object), orderSchema);
+ assert.isBigNumber('takerTokenCancelAmount', cancellationRequest.takerTokenCancelAmount);
+ await assert.isSenderAddressAvailableAsync(this.web3Wrapper, 'order.maker',
+ cancellationRequest.order.maker);
+ await this.validateCancelOrderAndThrowIfInvalidAsync(
+ cancellationRequest.order, cancellationRequest.takerTokenCancelAmount);
});
const exchangeInstance = await this.getExchangeContractAsync();
- const orderAddressesAndValues = _.map(orders, order => {
- return ExchangeWrapper.getOrderAddressesAndValues(order);
+ const orderAddressesValuesAndTakerTokenCancelAmounts = _.map(cancellationRequestsBatch, cancellationRequest => {
+ return [
+ ...ExchangeWrapper.getOrderAddressesAndValues(cancellationRequest.order),
+ cancellationRequest.takerTokenCancelAmount,
+ ];
});
// _.unzip doesn't type check if values have different types :'(
- const [orderAddresses, orderValues] = _.unzip<any>(orderAddressesAndValues);
+ const [orderAddresses, orderValues, takerTokenCancelAmounts] =
+ _.unzip<any>(orderAddressesValuesAndTakerTokenCancelAmounts);
const gas = await exchangeInstance.batchCancel.estimateGas(
orderAddresses,
orderValues,