Consensys / Consensys/abi-decoder

decodeLogs not work for event logs with struct parameter

Open
#61 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
641
Forks
215
PR merge metrics
No merged PRs in 30d

Description

decodeLogs can not decode events with struct tuple logs, it show empty value.

### Environment

$ truffle version
Truffle v5.1.37 (core: 5.1.37)
Solidity - 0.7.1 (solc-js)
Node v10.20.0
Web3.js v1.2.1

### Steps to reproduce
1. get test contract
```
pragma solidity ^0.7.1;
pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: MIT

contract SimpleStructStorage {
struct Data {
uint a;
string b;
}

Data storedData;

event SET(Data d);
function set(Data memory x) public {
storedData = x;
emit SET(x);
}

function get() public view returns (Data memory x) {
return storedData;
}
}

```
2. compile with truffle and run test
```
const SimpleStructStorage = artifacts.require('SimpleStructStorage')
const Web3 = require('web3');


contract('SimpleStructStorage', (accounts) => {
let instance
const web3 = new Web3('http://localhost:8545');

before('setup', async () => {
instance = await SimpleStructStorage.new()
console.log("instance", instance.address);

})

describe('test struct input parameter', () => {
it('should set struct data', async () => {
const data = {a: 100, b: "test"}
const {receipt: {transactionHash}} = await instance.set(data)
console.log(transactionHash)
const {a, b} = await instance.get()
assert.equal(a, 100)
assert.equal(b, 'test')

web3.eth.getTransactionReceipt(transactionHash, function(e, receipt) {
const decodedLogs = abiDecoder.decodeLogs(receipt.logs);
console.log(decodeLogs)
});
})
})
})

```
3. run decodeLogs test script
node test_abi_decoder.js 0xxxx
```
//test_abi_decoder.js
const Web3 = require('web3');
const web3 = new Web3('http://localhost:8545');
const {addABI, decodeMethod, decodeLogs}= require('abi-decoder');

const abiJson = require('./build/contracts/SimpleStructStorage.json')
const ABI = abiJson.abi
addABI(ABI);

const transactionHash=process.argv[2] //you set tx hash

//Input Data
web3.eth.getTransaction(transactionHash, function(e, data) {
const inputData = data.input;
const decodedData = decodeMethod(inputData);
console.log(decodedData.params[0].value);
});


//Event Logs
web3.eth.getTransactionReceipt(transactionHash, function(e, receipt) {
const decodedLogs = decodeLogs(receipt.logs);
console.log(decodedLogs[0].events)
});

```
### Expected behaviour
decodeLogs Should show below output
[ { name: 'd', type: 'tuple', value: [ '100', 'test' ] } ]

### Actual behaviour
decodeLogs show empty value
[ { name: 'd', type: 'tuple', value: [] } ]

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the decodeLogs entry point and reproduce the issue with test_abi_decoder.js using the provided SimpleStructStorage ABI and transaction receipt. Trace tuple event decoding for the struct parameter and verify that the result changes from an empty value to ["100", "test"] as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, solidity
Domain
blockchain
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.