Add cancelOrderInternal, use within batchCancelOrders

This commit is contained in:
Amir Bandeali 2018-08-30 12:10:24 -07:00
parent eb4517d737
commit 09b4d5e0e4
5 changed files with 31 additions and 9 deletions

View File

@ -107,14 +107,7 @@ contract MixinExchangeCore is
public public
nonReentrant nonReentrant
{ {
// Fetch current order status cancelOrderInternal(order);
OrderInfo memory orderInfo = getOrderInfo(order);
// Validate context
assertValidCancel(order, orderInfo);
// Perform cancel
updateCancelledState(order, orderInfo.orderHash);
} }
/// @dev Gets information about an order: status, hash, and amount filled. /// @dev Gets information about an order: status, hash, and amount filled.
@ -236,6 +229,22 @@ contract MixinExchangeCore is
return fillResults; return fillResults;
} }
/// @dev After calling, the order can not be filled anymore.
/// Throws if order is invalid or sender does not have permission to cancel.
/// @param order Order to cancel. Order must be OrderStatus.FILLABLE.
function cancelOrderInternal(Order memory order)
internal
{
// Fetch current order status
OrderInfo memory orderInfo = getOrderInfo(order);
// Validate context
assertValidCancel(order, orderInfo);
// Perform cancel
updateCancelledState(order, orderInfo.orderHash);
}
/// @dev Updates state with results of a fill order. /// @dev Updates state with results of a fill order.
/// @param order that was filled. /// @param order that was filled.
/// @param takerAddress Address of taker who filled the order. /// @param takerAddress Address of taker who filled the order.

View File

@ -377,10 +377,11 @@ contract MixinWrapperFunctions is
/// @param orders Array of order specifications. /// @param orders Array of order specifications.
function batchCancelOrders(LibOrder.Order[] memory orders) function batchCancelOrders(LibOrder.Order[] memory orders)
public public
nonReentrant
{ {
uint256 ordersLength = orders.length; uint256 ordersLength = orders.length;
for (uint256 i = 0; i != ordersLength; i++) { for (uint256 i = 0; i != ordersLength; i++) {
cancelOrder(orders[i]); cancelOrderInternal(orders[i]);
} }
} }

View File

@ -72,6 +72,11 @@ contract MExchangeCore is
internal internal
returns (LibFillResults.FillResults memory fillResults); returns (LibFillResults.FillResults memory fillResults);
/// @dev After calling, the order can not be filled anymore.
/// @param order Order struct containing order specifications.
function cancelOrderInternal(LibOrder.Order memory order)
internal;
/// @dev Updates state with results of a fill order. /// @dev Updates state with results of a fill order.
/// @param order that was filled. /// @param order that was filled.
/// @param takerAddress Address of taker who filled the order. /// @param takerAddress Address of taker who filled the order.

View File

@ -51,6 +51,7 @@ contract ReentrantERC20Token is
MARKET_SELL_ORDERS, MARKET_SELL_ORDERS,
MATCH_ORDERS, MATCH_ORDERS,
CANCEL_ORDER, CANCEL_ORDER,
BATCH_CANCEL_ORDERS,
CANCEL_ORDERS_UP_TO, CANCEL_ORDERS_UP_TO,
SET_SIGNATURE_VALIDATOR_APPROVAL SET_SIGNATURE_VALIDATOR_APPROVAL
} }
@ -150,6 +151,11 @@ contract ReentrantERC20Token is
EXCHANGE.cancelOrder.selector, EXCHANGE.cancelOrder.selector,
order order
); );
} else if (currentFunctionId == uint8(ExchangeFunction.BATCH_CANCEL_ORDERS)) {
calldata = abi.encodeWithSelector(
EXCHANGE.batchCancelOrders.selector,
orders
);
} else if (currentFunctionId == uint8(ExchangeFunction.CANCEL_ORDERS_UP_TO)) { } else if (currentFunctionId == uint8(ExchangeFunction.CANCEL_ORDERS_UP_TO)) {
calldata = abi.encodeWithSelector( calldata = abi.encodeWithSelector(
EXCHANGE.cancelOrdersUpTo.selector, EXCHANGE.cancelOrdersUpTo.selector,

View File

@ -60,6 +60,7 @@ export const constants = {
'MARKET_SELL_ORDERS', 'MARKET_SELL_ORDERS',
'MATCH_ORDERS', 'MATCH_ORDERS',
'CANCEL_ORDER', 'CANCEL_ORDER',
'BATCH_CANCEL_ORDERS',
'CANCEL_ORDERS_UP_TO', 'CANCEL_ORDERS_UP_TO',
'SET_SIGNATURE_VALIDATOR_APPROVAL', 'SET_SIGNATURE_VALIDATOR_APPROVAL',
], ],