Skip to content

Commit

Permalink
Merge pull request #2272 from AlexanderC/patch-1
Browse files Browse the repository at this point in the history
Fix decodeLog() for non indexed params
  • Loading branch information
nivida authored Feb 6, 2019
2 parents f34c646 + fcc2744 commit 8d4da2d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 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) : [];

let 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
2 changes: 1 addition & 1 deletion packages/web3-eth-abi/tests/AbiCoderTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('AbiCoderTest', () => {
}
];

expect(abiCoder.decodeLog(inputs, '0x0', ['0x0', '0x0'])).toEqual({'0': '0', '1': '0x0', '2': '0', input: '0'});
expect(abiCoder.decodeLog(inputs, '0x0', ['0x0', '0x0'])).toEqual({'0': '0', '1': '0x0', '2': '', input: ''});

expect(ethersAbiCoderMock.decode).toHaveBeenNthCalledWith(1, [inputs[0].type], '0x0');

Expand Down

0 comments on commit 8d4da2d

Please sign in to comment.