diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-09-06 23:29:15 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-09-06 23:29:15 +0800 |
commit | 7c61b09dce6ea294013a4745895b58ad855817a0 (patch) | |
tree | 9462c3d2bc5a56bb2108538cbb6988fd322bf173 /src/contract_wrappers | |
parent | b38aff8808db0ade04746f69bbb25b62147d17a4 (diff) | |
download | dexon-sol-tools-7c61b09dce6ea294013a4745895b58ad855817a0.tar dexon-sol-tools-7c61b09dce6ea294013a4745895b58ad855817a0.tar.gz dexon-sol-tools-7c61b09dce6ea294013a4745895b58ad855817a0.tar.bz2 dexon-sol-tools-7c61b09dce6ea294013a4745895b58ad855817a0.tar.lz dexon-sol-tools-7c61b09dce6ea294013a4745895b58ad855817a0.tar.xz dexon-sol-tools-7c61b09dce6ea294013a4745895b58ad855817a0.tar.zst dexon-sol-tools-7c61b09dce6ea294013a4745895b58ad855817a0.zip |
Add zeroEx.exchange.throwLogErrorsAsErrors
Diffstat (limited to 'src/contract_wrappers')
-rw-r--r-- | src/contract_wrappers/exchange_wrapper.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 115bd1110..79b2ea582 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -26,6 +26,7 @@ import { LogErrorContractEventArgs, LogFillContractEventArgs, LogCancelContractEventArgs, + LogWithDecodedArgs, } from '../types'; import {assert} from '../utils/assert'; import {utils} from '../utils/utils'; @@ -46,6 +47,14 @@ export class ExchangeWrapper extends ContractWrapper { private _exchangeLogEventEmitters: ContractEventEmitter[]; private _orderValidationUtils: OrderValidationUtils; private _tokenWrapper: TokenWrapper; + private _exchangeContractErrCodesToMsg = { + [ExchangeContractErrCodes.ERROR_FILL_EXPIRED]: ExchangeContractErrs.OrderFillExpired, + [ExchangeContractErrCodes.ERROR_CANCEL_EXPIRED]: ExchangeContractErrs.OrderFillExpired, + [ExchangeContractErrCodes.ERROR_FILL_NO_VALUE]: ExchangeContractErrs.OrderRemainingFillAmountZero, + [ExchangeContractErrCodes.ERROR_CANCEL_NO_VALUE]: ExchangeContractErrs.OrderRemainingFillAmountZero, + [ExchangeContractErrCodes.ERROR_FILL_TRUNCATION]: ExchangeContractErrs.OrderFillRoundingError, + [ExchangeContractErrCodes.ERROR_FILL_BALANCE_ALLOWANCE]: ExchangeContractErrs.FillBalanceAllowanceError, + }; private static _getOrderAddressesAndValues(order: Order): [OrderAddresses, OrderValues] { const orderAddresses: OrderAddresses = [ order.maker, @@ -674,6 +683,20 @@ export class ExchangeWrapper extends ContractWrapper { ); return isRoundingError; } + /** + * Checks if logs contain LogError, which is emited by Exchange contract on transfer failure + * and throws an appropriate error. + * @param logsWithdecodedArgs Transaction logs as returned by `zeroEx.awaitTransactionMinedAsync` + */ + public throwLogErrorsAsErrors(logsWithdecodedArgs: LogWithDecodedArgs[]): void { + const errLog = _.find(logsWithdecodedArgs, {event: 'LogError'}); + if (!_.isUndefined(errLog)) { + const logArgs: LogErrorContractEventArgs = errLog.args as any; + const errCode = logArgs.errorId.toNumber(); + const errMessage = this._exchangeContractErrCodesToMsg[errCode]; + throw new Error(errMessage); + } + } private async _invalidateContractInstancesAsync(): Promise<void> { await this.stopWatchingAllEventsAsync(); delete this._exchangeContractIfExists; |