Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Filtering with checksum addresses #97

Closed
carver opened this issue Apr 4, 2018 · 11 comments
Closed

Filtering with checksum addresses #97

carver opened this issue Apr 4, 2018 · 11 comments

Comments

@carver
Copy link

carver commented Apr 4, 2018

Cross-linked from: #494

Expected Behavior

  • A deployed contract is emitting logs.
  • A filter is created that specifies a from address using the checksum address format from EIP-55
  • The events are triggered in new blocks
  • A client requests new entries tied to the created filter
  • The logs are returned

Current Behavior

Everything as expected, except the last step: no logs are returned.

Note that if the lower-case address is used in the filter instead, that logs are returned. So all other steps appear to be configured correctly.

Possible Solution

Force addresses to lower-case in the filter before searching? (optionally, verifying checksums)

Steps to Reproduce (for bugs)

I'm cross-posting from a web3py bug report, which includes source: ethereum/web3.py#674

Given the simplicity of the workaround, it seems that the problem should be easy to reproduce.

Context

Without this fix, ganache filters will appear broken in the next stable release of web3py, which is likely within a week or two. All other nodes appear to work as expected.

Your Environment

I'll ask the original posters on the web3.py issue to fill in this info:

  • Version used:
  • Version of Truffle/Remix/Other tools used:
  • NodeJS Version: [ ] 6.x, [ ] 7.x (unsupported), [ ] 8.x, [ ] 9.x
  • Operating System and version (include distro if Linux):
  • Link to your project or repro gist:
  • Commit hash to use with above link for reproduction:
  • I intend to submit a pull request to fix this issue: [ ]
@edevil
Copy link
Contributor

edevil commented Jun 1, 2018

Is there a workaround for this issue that does not involve monkey patching either web3.py or Ganache?

It seems that web3.py does not want to be able to accept non-checksum addresses and Ganache does not want to do a simple lowercase conversion of the addresses it gets.

@carver
Copy link
Author

carver commented Jun 11, 2018

This is believed to be resolved in ganache-cli@v6.1.2

@mikeseese
Copy link
Contributor

This should be resolved per the release of ganache-core@v2.1.1 and ganache-cli@v6.1.2. Please let myself or @benjamincburns know if there are any issues! Thanks!

@edevil
Copy link
Contributor

edevil commented Jun 14, 2018

@seesemichaelj @benjamincburns @carver I've tried ganache-cli 6.1.2 and I still get an empty list of events back. Can anyone else try to see if they get different results?

@smartcontracts
Copy link

smartcontracts commented Jun 14, 2018

@edevil Same problem. Duplicating my comment here for posterity:

I'm still having this issue with:

  • ganache-core@v2.1.1
  • ganache-cli@v6.1.3
  • web3==4.3.0

The following filter does not work:

event_filter = web3.eth.filter({
    "address": contract.address
})

but this does:

event_filter = web3.eth.filter({
    "address": contract.address.lower()
})

Where contract.address is checksummed.

@smartcontracts
Copy link

smartcontracts commented Jun 14, 2018

@edevil My (awful) hack for this currently is to set the contract's address to None and then check that the event address == the contract's address. Wanted things to work without monkey patching.

contract_address =contract.address
contract.address = None
event_filter = contract.events.<EventName>.createFilter('latest')
contract.address = contract_address
...
if (event['address'] == contract_address):
    # do stuff

(yes this is awful)

@mikeseese
Copy link
Contributor

If I'm correct, #127 should fix this! Going to close this, should be in the next release

@carver
Copy link
Author

carver commented Jun 26, 2018

@seesemichaelj could you update the issue with the version numbers when it's released? I'd like to include that info in the related web3py issue.

@mikeseese
Copy link
Contributor

@carver ganache-core@2.1.3 and ganache-cli@6.1.4 were just released

@Zatonskikh
Copy link

Hello @carver, I still have the same type of issue: I'm using ganache-cli 6.1.8 with web3.py and i can't catch emited event with it! btw block filter and transaction filter works perfectly, but event filter doesn't, also i tried catch event with web3.js and it worked!
my contract:

pragma solidity ^0.4.0;

contract Greeter {
    string public greeting;

    function Greeter() public {
        greeting = "Hello";
    }

    function setGreeting(string _greeting) public {
        greeting = _greeting;
    }

    function greet(uint tokens) public view returns (uint) {
        return tokens;
    }

    function greet1() public view returns (string) {
        return greeting;
    }

    event Instructor(
       string name,
       uint age
    );

   string fName;
   uint age;

   function setInstructor(string _fName, uint _age) public {
       fName = _fName;
       age = _age;
       emit Instructor(_fName, _age);
   }

   function getInstructor() view public returns (string, uint) {
       return (fName, age);
   }
}

web3 filter:

contract = w3.eth.contract(
    address=CONTRACT,
    abi=contract_interface['abi'],
)

event_filter = contract.events.Instructor.createFilter(fromBlock='latest')
event_filter.get_all_entries()

@carver
Copy link
Author

carver commented Nov 12, 2018

@Zatonskikh this is OT for this repository. I'll give my first guess about what's wrong below. If you have any more questions, I recommend opening an ethereum.stackexchange question or a new issue on ethereum/web3.py

Since you're setting fromBlock='latest', you won't see the event unless it was emitted in the very latest block.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants