Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
Fix decodeLog() for non indexed params
Browse files Browse the repository at this point in the history
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: web3#2268
  • Loading branch information
AlexanderC authored Jan 30, 2019
1 parent 7ff0082 commit 95ab267
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/web3-eth-abi/src/AbiCoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 95ab267

Please sign in to comment.