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

error creating filter for event with array arguments #1569

Closed
KaiRo-at opened this issue Jan 23, 2020 · 3 comments
Closed

error creating filter for event with array arguments #1569

KaiRo-at opened this issue Jan 23, 2020 · 3 comments

Comments

@KaiRo-at
Copy link

KaiRo-at commented Jan 23, 2020

  • Version: 5.4.0
  • Python: 3.7
  • OS: linux
  • pip freeze output
asn1crypto==1.3.0
attrdict==2.0.1
attrs==19.3.0
base58==1.0.3
blinker==1.4
certifi==2019.11.28
cffi==1.13.2
chardet==3.0.4
Click==7.0
coincurve==13.0.0
cryptography==2.8
cytoolz==0.10.1
eciespy==0.3.3
eth-abi==2.1.0
eth-account==0.4.0
eth-hash==0.2.0
eth-keyfile==0.5.1
eth-keys==0.3.1
eth-rlp==0.1.2
eth-typing==2.2.1
eth-utils==1.8.4
flasgger==0.9.3
Flask==1.1.1
Flask-Cors==3.0.8
Flask-Mail==0.9.1
gevent==1.4.0
greenlet==0.4.15
hexbytes==0.2.0
idna==2.8
importlib-metadata==1.3.0
ipfshttpclient==0.4.12
itsdangerous==1.1.0
Jinja2==2.10.3
jsonschema==3.2.0
lru-dict==1.1.6
MarkupSafe==1.1.1
mistune==0.8.4
more-itertools==8.0.2
multiaddr==0.0.9
mypy-extensions==0.4.3
netaddr==0.7.19
parsimonious==0.8.1
protobuf==3.11.2
psycopg2==2.8.4
pycparser==2.19
pycryptodome==3.9.4
pyrsistent==0.15.7
PyYAML==5.3
requests==2.22.0
rlp==1.2.0
six==1.13.0
SQLAlchemy==1.3.12
SQLAlchemy-Utils==0.36.1
toolz==0.10.0
typing-extensions==3.7.4.1
urllib3==1.25.7
varint==1.0.2
web3==5.4.0
websockets==8.1
Werkzeug==0.16.0
zipp==0.6.0

What was wrong?

I'm trying to set up event filters for ERC 1155 transfer events (see https://eips.ethereum.org/EIPS/eip-1155#specification for the spec) with code like this (simplified):

    for ev in ["TransferSingle", "TransferBatch"]:
        contract = w3.eth.contract(address=mycontract_address, abi=mycontract_abi)
        # the below should work but for some reason does not:
        #event_filter = contract.events.__getattr__(ev).createFilter(fromBlock=mycontract_deployblock, toBlock="latest")
        event_filter = None
        for cevent in contract.events:
            if cevent.event_name == ev:
                event_filter = cevent.createFilter(fromBlock=mycontract_deployblock, toBlock="latest")
                break

This works for TransferSingle, but for TransferBatch it fails like this:

Traceback (most recent call last):
  File "./mycode-rest.py", line 2080, in check_background_threads
    event_filter = cevent.createFilter(fromBlock=mycontract_deployblock, toBlock="latest")
  File "/mnt/dev/project/rest-backend/venv/lib/python3.7/site-packages/eth_utils/decorators.py", line 20, in _wrapper
    return self.method(objtype, *args, **kwargs)
  File "/mnt/dev/project/rest-backend/venv/lib/python3.7/site-packages/web3/contract.py", line 1158, in createFilter
    log_filter = filter_builder.deploy(self.web3)
  File "/mnt/dev/project/rest-backend/venv/lib/python3.7/site-packages/web3/_utils/events.py", line 397, in deploy
    for arg in self.args.values():
TypeError: 'DataArgumentFilter' object is not callable

Now, TransferBatch is specified like this:
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _values);

Note the arrays for _ids and _values - I suspect that's what causes the error, as the same code has worked fine for me for all kinds of events so far, but none had arrays in it before this one.

How can it be fixed?

Not sure, I know too little of handling events in the guts of web3.py to speculate on that.

@KaiRo-at
Copy link
Author

I have worked around this for the moment with a generic web3.eth.filter() on the topic, which I read out of the contract's .json file and then dedode the arguments from the event's data field via eth_abi.decode_single() but this is pretty cumbersome code when it should be supported straight-forward by web3.py instead.

@kclowes
Copy link
Collaborator

kclowes commented Feb 19, 2020

Thanks for posting an update @KaiRo-at. I'm glad you were able to figure out a workaround. I'll leave this open so we can dig in.

@kclowes
Copy link
Collaborator

kclowes commented Feb 26, 2024

This should be working with the latest versions of web3 and eth-abi. Tuple support has been added.

@kclowes kclowes closed this as completed Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants