From 10e8e89fee0cb36e2c5c06255cb65e2b8b9eced8 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Sat, 10 Jun 2017 13:55:36 +0200 Subject: Add initial error handling decorator implementation --- src/contract_wrappers/exchange_wrapper.ts | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/contract_wrappers/exchange_wrapper.ts') diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 65a873a9f..b03e55d8c 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -35,6 +35,7 @@ import {orderFillOrKillRequestsSchema} from '../schemas/order_fill_or_kill_reque import {signedOrderSchema, orderSchema} from '../schemas/order_schemas'; import {constants} from '../utils/constants'; import {TokenWrapper} from './token_wrapper'; +import {decorators} from '../utils/decorators'; export class ExchangeWrapper extends ContractWrapper { private exchangeContractErrCodesToMsg = { @@ -121,6 +122,7 @@ export class ExchangeWrapper extends ContractWrapper { * executing, the parties do not have sufficient balances/allowances, preserving gas costs. Setting it to * false forgoes this check and causes the smart contract to throw instead. */ + @decorators.contractCallErrorHandler public async fillOrderAsync(signedOrder: SignedOrder, takerTokenFillAmount: BigNumber.BigNumber, shouldCheckTransfer: boolean, takerAddress: string): Promise { assert.doesConformToSchema('signedOrder', signedOrder, signedOrderSchema); @@ -165,6 +167,7 @@ export class ExchangeWrapper extends ContractWrapper { * If the fill amount is reached - it succeeds and does not fill the rest of the orders. * If fill amount is not reached - it fills as much of the fill amount as possible and succeeds. */ + @decorators.contractCallErrorHandler public async fillOrdersUpToAsync(signedOrders: SignedOrder[], takerTokenFillAmount: BigNumber.BigNumber, shouldCheckTransfer: boolean, takerAddress: string): Promise { const takerTokenAddresses = _.map(signedOrders, signedOrder => signedOrder.takerTokenAddress); @@ -229,6 +232,7 @@ export class ExchangeWrapper extends ContractWrapper { * If shouldCheckTransfer is set to true, it will continue filling subsequent orders even when earlier ones fail. * When shouldCheckTransfer is set to false, if any fill fails, the entire batch fails. */ + @decorators.contractCallErrorHandler public async batchFillOrderAsync(orderFillRequests: OrderFillRequest[], shouldCheckTransfer: boolean, takerAddress: string): Promise { assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer); @@ -288,6 +292,7 @@ export class ExchangeWrapper extends ContractWrapper { * Attempts to fill a specific amount of an order. If the entire amount specified cannot be filled, * the fill order is abandoned. */ + @decorators.contractCallErrorHandler public async fillOrKillOrderAsync(signedOrder: SignedOrder, fillTakerAmount: BigNumber.BigNumber, takerAddress: string) { assert.doesConformToSchema('signedOrder', signedOrder, signedOrderSchema); @@ -331,6 +336,7 @@ export class ExchangeWrapper extends ContractWrapper { * Batch version of fillOrKill. Allows a taker to specify a batch of orders that will either be atomically * filled (each to the specified fillAmount) or aborted. */ + @decorators.contractCallErrorHandler public async batchFillOrKillAsync(orderFillOrKillRequests: OrderFillOrKillRequest[], takerAddress: string) { await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); @@ -383,6 +389,7 @@ export class ExchangeWrapper extends ContractWrapper { /** * Cancel a given fill amount of an order. Cancellations are cumulative. */ + @decorators.contractCallErrorHandler public async cancelOrderAsync( order: Order|SignedOrder, takerTokenCancelAmount: BigNumber.BigNumber): Promise { assert.doesConformToSchema('order', order, orderSchema); @@ -416,6 +423,7 @@ export class ExchangeWrapper extends ContractWrapper { * Batch version of cancelOrderAsync. Atomically cancels multiple orders in a single transaction. * All orders must be from the same maker. */ + @decorators.contractCallErrorHandler public async batchCancelOrderAsync(orderCancellationRequests: OrderCancellationRequest[]): Promise { const makers = _.map(orderCancellationRequests, cancellationRequest => cancellationRequest.order.maker); assert.hasAtMostOneUniqueValue(makers, ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH_DISALLOWED); -- cgit From 6b41ef680c90ec19fabc603e9288bde7ec3bc6b1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Sat, 10 Jun 2017 15:25:14 +0200 Subject: Remove Hex suffix from public functions parameters names --- src/contract_wrappers/exchange_wrapper.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/contract_wrappers/exchange_wrapper.ts') diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 76f86e464..9e1eb609f 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -79,44 +79,44 @@ export class ExchangeWrapper extends ContractWrapper { * Returns the unavailable takerAmount of an order. Unavailable amount is defined as the total * amount that has been filled or cancelled. The remaining takerAmount can be calculated by * subtracting the unavailable amount from the total order takerAmount. - * @param orderHashHex The hex encoded orderHash for which you would like to retrieve the - * unavailable takerAmount. + * @param orderHash The hex encoded orderHash for which you would like to retrieve the + * unavailable takerAmount. * @return The amount of the order (in taker tokens) that has either been filled or canceled. */ - public async getUnavailableTakerAmountAsync(orderHashHex: string): Promise { - assert.isValidOrderHash('orderHashHex', orderHashHex); + public async getUnavailableTakerAmountAsync(orderHash: string): Promise { + assert.isValidOrderHash('orderHash', orderHash); const exchangeContract = await this.getExchangeContractAsync(); - let unavailableAmountInBaseUnits = await exchangeContract.getUnavailableValueT.call(orderHashHex); + let unavailableAmountInBaseUnits = await exchangeContract.getUnavailableValueT.call(orderHash); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber unavailableAmountInBaseUnits = new BigNumber(unavailableAmountInBaseUnits); return unavailableAmountInBaseUnits; } /** * Retrieve the takerAmount of an order that has already been filled. - * @param orderHashHex The hex encoded orderHash for which you would like to retrieve the filled takerAmount. + * @param orderHash The hex encoded orderHash for which you would like to retrieve the filled takerAmount. * @return The amount of the order (in taker tokens) that has already been filled. */ - public async getFilledTakerAmountAsync(orderHashHex: string): Promise { - assert.isValidOrderHash('orderHashHex', orderHashHex); + public async getFilledTakerAmountAsync(orderHash: string): Promise { + assert.isValidOrderHash('orderHash', orderHash); const exchangeContract = await this.getExchangeContractAsync(); - let fillAmountInBaseUnits = await exchangeContract.filled.call(orderHashHex); + let fillAmountInBaseUnits = await exchangeContract.filled.call(orderHash); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber fillAmountInBaseUnits = new BigNumber(fillAmountInBaseUnits); return fillAmountInBaseUnits; } /** * Retrieve the takerAmount of an order that has been cancelled. - * @param orderHashHex The hex encoded orderHash for which you would like to retrieve the - * cancelled takerAmount. + * @param orderHash The hex encoded orderHash for which you would like to retrieve the + * cancelled takerAmount. * @return The amount of the order (in taker tokens) that has been cancelled. */ - public async getCanceledTakerAmountAsync(orderHashHex: string): Promise { - assert.isValidOrderHash('orderHashHex', orderHashHex); + public async getCanceledTakerAmountAsync(orderHash: string): Promise { + assert.isValidOrderHash('orderHash', orderHash); const exchangeContract = await this.getExchangeContractAsync(); - let cancelledAmountInBaseUnits = await exchangeContract.cancelled.call(orderHashHex); + let cancelledAmountInBaseUnits = await exchangeContract.cancelled.call(orderHash); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber cancelledAmountInBaseUnits = new BigNumber(cancelledAmountInBaseUnits); return cancelledAmountInBaseUnits; -- cgit