From ef96bff6ec379b7d3a78e385db4aa5052de72d23 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Sun, 12 May 2019 13:28:07 -0700 Subject: [PATCH] Add cancelOrderNoThrow and batchCancelOrdersNoThrow --- .../contracts/src/MixinWrapperFunctions.sol | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/contracts/exchange/contracts/src/MixinWrapperFunctions.sol b/contracts/exchange/contracts/src/MixinWrapperFunctions.sol index 3da63dbd4f..958e8c4492 100644 --- a/contracts/exchange/contracts/src/MixinWrapperFunctions.sol +++ b/contracts/exchange/contracts/src/MixinWrapperFunctions.sol @@ -374,6 +374,19 @@ contract MixinWrapperFunctions is return totalFillResults; } + /// @dev After calling, the order can not be filled anymore. + /// @return True if the order was cancelled successfully. + /// @param order Order to cancel. Order must be OrderStatus.FILLABLE. + function cancelOrderNoThrow(LibOrder.Order memory order) + public + returns (bool didCancel) + { + // bytes4(keccak256("cancelOrder((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes))")) = 0xd46b02c3 + bytes memory cancelOrderCallData = abi.encodeWithSelector(0xd46b02c3, order); + (didCancel,) = address(this).delegatecall(cancelOrderCallData); + return didCancel; + } + /// @dev Synchronously cancels multiple orders in a single transaction. /// @param orders Array of order specifications. function batchCancelOrders(LibOrder.Order[] memory orders) @@ -386,6 +399,21 @@ contract MixinWrapperFunctions is } } + /// @dev Synchronously cancels multiple orders in a single transaction. + /// @param orders Array of order specifications. + /// @return Bool array containing results of each individual cancellation. + function batchCancelOrdersNoThrow(LibOrder.Order[] memory orders) + public + returns (bool[] memory) + { + uint256 ordersLength = orders.length; + bool[] memory didCancel = new bool[](ordersLength); + for (uint256 i = 0; i != ordersLength; i++) { + didCancel[i] = cancelOrderNoThrow(orders[i]); + } + return didCancel; + } + /// @dev Fetches information for all passed in orders. /// @param orders Array of order specifications. /// @return Array of OrderInfo instances that correspond to each order.