From 5458a1c1b741fb2ccb477cf2ac0ba81d4e351402 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 5 Feb 2018 12:59:10 +0100 Subject: Fix an exception when a signature collision happens --- packages/utils/src/abi_decoder.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'packages/utils') diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts index f96ee2edb..2dd7134a7 100644 --- a/packages/utils/src/abi_decoder.ts +++ b/packages/utils/src/abi_decoder.ts @@ -36,9 +36,14 @@ export class AbiDecoder { const dataTypes = _.map(nonIndexedInputs, input => input.type); const decodedData = SolidityCoder.decodeParams(dataTypes, logData.slice('0x'.length)); + let failedToDecode = false; _.map(event.inputs, (param: Web3.EventParameter) => { // Indexed parameters are stored in topics. Non-indexed ones in decodedData let value: BigNumber | string = param.indexed ? log.topics[topicsIndex++] : decodedData[dataIndex++]; + if (_.isUndefined(value)) { + failedToDecode = true; + return; + } if (param.type === SolidityTypes.Address) { value = AbiDecoder._padZeros(new BigNumber(value).toString(16)); } else if ( @@ -51,11 +56,15 @@ export class AbiDecoder { decodedParams[param.name] = value; }); - return { - ...log, - event: event.name, - args: decodedParams, - }; + if (failedToDecode) { + return log; + } else { + return { + ...log, + event: event.name, + args: decodedParams, + }; + } } private _addABI(abiArray: Web3.AbiDefinition[]): void { _.map(abiArray, (abi: Web3.AbiDefinition) => { -- cgit v1.2.3 From 1f4cbb747976560df0e67e703311db8f21f75604 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 5 Feb 2018 13:04:49 +0100 Subject: Use forEach instead of map --- packages/utils/CHANGELOG.md | 8 ++++++-- packages/utils/src/abi_decoder.ts | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'packages/utils') diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md index efee30dd1..0abe835b8 100644 --- a/packages/utils/CHANGELOG.md +++ b/packages/utils/CHANGELOG.md @@ -1,6 +1,10 @@ # CHANGELOG +## v0.x.x - _TBD, 2018_ + + * Fix a bug causing abi_decoder to throw on unknown events with the same signature (#366) + ## v0.2.0 - _January 17, 2018_ -* Add `onError` parameter to `intervalUtils.setAsyncExcludingInterval` (#312) -* Add `intervalUtils.setInterval` (#312) + * Add `onError` parameter to `intervalUtils.setAsyncExcludingInterval` (#312) + * Add `intervalUtils.setInterval` (#312) diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts index 2dd7134a7..368973b1b 100644 --- a/packages/utils/src/abi_decoder.ts +++ b/packages/utils/src/abi_decoder.ts @@ -18,7 +18,7 @@ export class AbiDecoder { return `0x${formatted}`; } constructor(abiArrays: Web3.AbiDefinition[][]) { - _.map(abiArrays, this._addABI.bind(this)); + _.forEach(abiArrays, this._addABI.bind(this)); } // This method can only decode logs from the 0x & ERC20 smart contracts public tryToDecodeLogOrNoop(log: Web3.LogEntry): LogWithDecodedArgs | RawLog { @@ -37,7 +37,7 @@ export class AbiDecoder { const decodedData = SolidityCoder.decodeParams(dataTypes, logData.slice('0x'.length)); let failedToDecode = false; - _.map(event.inputs, (param: Web3.EventParameter) => { + _.forEach(event.inputs, (param: Web3.EventParameter) => { // Indexed parameters are stored in topics. Non-indexed ones in decodedData let value: BigNumber | string = param.indexed ? log.topics[topicsIndex++] : decodedData[dataIndex++]; if (_.isUndefined(value)) { -- cgit v1.2.3 From 6fce02d25e8133da16b1965cbd51b1edb74fcf7a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 5 Feb 2018 21:50:57 +0100 Subject: Change CHANGELOGs --- packages/utils/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/utils') diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md index 0abe835b8..d1c3264fa 100644 --- a/packages/utils/CHANGELOG.md +++ b/packages/utils/CHANGELOG.md @@ -2,7 +2,7 @@ ## v0.x.x - _TBD, 2018_ - * Fix a bug causing abi_decoder to throw on unknown events with the same signature (#366) + * Fix a bug related to event signature collisions (argument indexes aren't included in event signatures) in the abi_decoder. The decoder used to throw on unknown events with identical signatures as a known event (except indexes). (#366) ## v0.2.0 - _January 17, 2018_ -- cgit v1.2.3