From f12e4f8889d887952c2cd0b129fa926d1f3b9044 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Mon, 12 Feb 2018 18:25:45 -0800 Subject: Use new logDecoder interface --- packages/contracts/src/utils/exchange_wrapper.ts | 14 +++++++------- packages/contracts/src/utils/log_decoder.ts | 9 ++++++--- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/exchange_wrapper.ts b/packages/contracts/src/utils/exchange_wrapper.ts index f86b507e9..788bf07f4 100644 --- a/packages/contracts/src/utils/exchange_wrapper.ts +++ b/packages/contracts/src/utils/exchange_wrapper.ts @@ -36,7 +36,7 @@ export class ExchangeWrapper { const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.tryToDecodeLogOrNoop(log); + const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); wrapLogBigNumbers(logWithDecodedArgs); return logWithDecodedArgs; }); @@ -57,7 +57,7 @@ export class ExchangeWrapper { const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.tryToDecodeLogOrNoop(log); + const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); wrapLogBigNumbers(logWithDecodedArgs); return logWithDecodedArgs; }); @@ -81,7 +81,7 @@ export class ExchangeWrapper { const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.tryToDecodeLogOrNoop(log); + const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); wrapLogBigNumbers(logWithDecodedArgs); return logWithDecodedArgs; }); @@ -105,7 +105,7 @@ export class ExchangeWrapper { const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.tryToDecodeLogOrNoop(log); + const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); wrapLogBigNumbers(logWithDecodedArgs); return logWithDecodedArgs; }); @@ -129,7 +129,7 @@ export class ExchangeWrapper { const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.tryToDecodeLogOrNoop(log); + const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); wrapLogBigNumbers(logWithDecodedArgs); return logWithDecodedArgs; }); @@ -153,7 +153,7 @@ export class ExchangeWrapper { const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.tryToDecodeLogOrNoop(log); + const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); wrapLogBigNumbers(logWithDecodedArgs); return logWithDecodedArgs; }); @@ -174,7 +174,7 @@ export class ExchangeWrapper { const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); tx.logs = _.map(tx.logs, log => { - const logWithDecodedArgs = this._logDecoder.tryToDecodeLogOrNoop(log); + const logWithDecodedArgs = this._logDecoder.decodeLogOrThrow(log); wrapLogBigNumbers(logWithDecodedArgs); return logWithDecodedArgs; }); diff --git a/packages/contracts/src/utils/log_decoder.ts b/packages/contracts/src/utils/log_decoder.ts index 89f641078..d8685e3d7 100644 --- a/packages/contracts/src/utils/log_decoder.ts +++ b/packages/contracts/src/utils/log_decoder.ts @@ -22,8 +22,11 @@ export class LogDecoder { }); this._abiDecoder = new AbiDecoder(abiArrays); } - public tryToDecodeLogOrNoop(log: Web3.LogEntry): LogWithDecodedArgs | RawLog { - const logWithDecodedArgs = this._abiDecoder.tryToDecodeLogOrNoop(log); - return logWithDecodedArgs; + public decodeLogOrThrow(log: Web3.LogEntry): LogWithDecodedArgs | RawLog { + const logWithDecodedArgsOrLog = this._abiDecoder.tryToDecodeLogOrNoop(log); + if (_.isUndefined((logWithDecodedArgsOrLog as LogWithDecodedArgs).args)) { + throw new Error(`Unable to decode log: ${JSON.stringify(log)}`); + } + return logWithDecodedArgsOrLog; } } -- cgit v1.2.3