From 95ab267da6a2296a32189e786e874d585ee75fb0 Mon Sep 17 00:00:00 2001 From: AlexanderC Date: Wed, 30 Jan 2019 12:48:32 +0200 Subject: [PATCH] Fix decodeLog() for non indexed params Fix `decodeLog()` for non indexed params. The issue can be reproduced for events like this: ``` event Authorize( bytes32 indexed platformId, bytes32 indexed uid, address indexed user, AuthorizationRequest request ); ``` It is cause by `_mapTypes(types)` used in `decodeParameters(outputs, bytes)` (`var res = this.ethersAbiCoder.decode(this._mapTypes(outputs), "0x".concat(bytes.replace(/0x/i, '')));`) which returns `[ { indexed: false, name: 'request', type: 'address' } ]` for `types = outputs = [null, null, null, {"indexed":false,"name":"request","type":"address"}]` passed as argument. So when the iteration `outputs.forEach(function (output, i) {}` is performed the `returnValues` do not get `res[i]` assigned correctly because the index is shifted due to empty types cleanup. The fix might be linked to the following issue: https://github.com/ethereum/web3.js/issues/2268 --- packages/web3-eth-abi/src/AbiCoder.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/web3-eth-abi/src/AbiCoder.js b/packages/web3-eth-abi/src/AbiCoder.js index 86f999b72f6..027d86a40f1 100644 --- a/packages/web3-eth-abi/src/AbiCoder.js +++ b/packages/web3-eth-abi/src/AbiCoder.js @@ -296,15 +296,18 @@ export default class AbiCoder { const nonIndexedData = data; - const notIndexedParams = nonIndexedData ? this.decodeParameters(notIndexedInputs, nonIndexedData) : []; + const notIndexedParams = nonIndexedData ? this.decodeParameters(notIndexedInputs.filter(Boolean), nonIndexedData) : []; + var notIndexedOffset = 0; const returnValues = {}; inputs.forEach((res, i) => { + if (res.indexed) notIndexedOffset++; + returnValues[i] = res.type === 'string' ? '' : null; - if (typeof notIndexedParams[i] !== 'undefined') { - returnValues[i] = notIndexedParams[i]; + if (!res.indexed && typeof notIndexedParams[i - notIndexedOffset] !== 'undefined') { + returnValues[i] = notIndexedParams[i - notIndexedOffset]; } if (typeof indexedParams[i] !== 'undefined') { returnValues[i] = indexedParams[i];