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

getPastEvents works or not works depending on the event's location at the smart contract #3738

Closed
ouoabcde opened this issue Oct 7, 2020 · 2 comments
Assignees
Labels
1.x 1.0 related issues Bug Addressing a bug In Progress Currently being worked on

Comments

@ouoabcde
Copy link

ouoabcde commented Oct 7, 2020

Expected behavior

getPastEvents should work correctly regardless of the event's location at the smart contract.

Actual behavior

Throws an error like this when the event which is producing this bug is right below the another event.

Error: data out-of-bounds (length=0, offset=32, code=BUFFER_OVERRUN, version=abi/5.0.0-beta.153)

Steps to reproduce the behavior

  1. [This produces the error]

Here's my full code. LogRequest event which is the first located event works fine on getPastEvents. But, LogResponse event which is located below the LogRequest event produces this error.

pragma solidity ^0.5.0;

contract Logger {
    event LogRequest(bytes32 indexed requester, bytes source, bytes indexed target, bytes indexed command, uint256 requestedTime); // this works fine
    event LogResponse(bytes32 indexed requester, bytes source, bytes indexed target, bytes indexed command, bytes result); // this produces the error

    function request(bytes32 requester, bytes memory source, bytes memory target, bytes memory command, uint256 requestedTime) public {
        emit LogRequest(requester, source, target, command, requestedTime);
    }

    function response(bytes32 requester, bytes memory source, bytes memory target, bytes memory command, bytes memory result) public {
        emit LogResponse(requester, source, target, command, result);
    }
}
  1. [This works fine]

When I put the LogResponse event between two functions, this works fine. Weird... It's structure looks like this below.

event LogRequest(...);
function request() {...}
event LogResponse(...);
function response() {...}

Logs

The error log is at the Actual behavior corner.

Environment

npm: 6.14.6
Node: 12.18.3
Truffle: 5.1.37
solc: 0.5.0
web3.js: 1.3.0
OS: macOS Catalina 10.15.6

@spacesailor24
Copy link
Contributor

Hi there, I've tested your example code via my test repo and it seems to be working in the latest release candidate. Can you confirm that your original issue is resolved using the release candidate?

FYI, I removed the indexed tags from your events LogRequest and LogResponse because Solidity returns the hash of an array in an event instead of the actual value. If you'd like the actual value to be emitted, you must remove the indexed tag

Here is the above found in the Solidity docs:

If you use arrays (including string and bytes) as indexed arguments, its Keccak-256 hash is stored as a topic instead, this is because a topic can only hold a single word (32 bytes).

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

@github-actions github-actions bot added the Stale Has not received enough activity label Jan 11, 2021
@GregTheGreek GregTheGreek removed the Stale Has not received enough activity label Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Bug Addressing a bug In Progress Currently being worked on
Projects
None yet
Development

No branches or pull requests

3 participants