Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decodeLog() for non indexed params #2272

Merged
merged 9 commits into from
Feb 6, 2019
Merged
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