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

regression in eth.getLogs #999

Closed
schmir opened this issue Aug 10, 2018 · 2 comments
Closed

regression in eth.getLogs #999

schmir opened this issue Aug 10, 2018 · 2 comments
Assignees

Comments

@schmir
Copy link

schmir commented Aug 10, 2018

  • Version: 4.5.0
  • Python: 3.6
  • OS: linux

What was wrong?

The following code call eth.getLogs with address being a list of addresses. This works fine in web3 4.4.1, but is broken in web3 4.5.0.

from web3 import Web3

web3 = Web3(Web3.HTTPProvider("http://localhost:8545"))

logs = web3.eth.getLogs(
    {
        "fromBlock": 1,
        "toBlock": 1000,
        "address": [
            "0x55bdaAf9f941A5BB3EacC8D876eeFf90b90ddac9",
            "0xC0B33D88C704455075a0724AA167a286da778DDE",
        ],
    }
)
print(logs)

This produces the following error on 4.5.0:

Traceback (most recent call last):
  File "get-logs.py", line 11, in <module>
    "0xC0B33D88C704455075a0724AA167a286da778DDE",
  File "/home/ralf/local/lib/python3.6/site-packages/web3/eth.py", line 354, in getLogs
    "eth_getLogs", [filter_params],
  File "/home/ralf/local/lib/python3.6/site-packages/web3/manager.py", line 107, in request_blocking
    response = self._make_request(method, params)
  File "/home/ralf/local/lib/python3.6/site-packages/web3/manager.py", line 90, in _make_request
    return request_func(method, params)
  File "/home/ralf/local/lib/python3.6/site-packages/web3/middleware/gas_price_strategy.py", line 18, in middleware
    return make_request(method, params)
  File "cytoolz/functoolz.pyx", line 236, in cytoolz.functoolz.curry.__call__
  File "cytoolz/functoolz.pyx", line 232, in cytoolz.functoolz.curry.__call__
  File "/home/ralf/local/lib/python3.6/site-packages/web3/middleware/formatting.py", line 48, in apply_formatters
    response = make_request(method, formatted_params)
  File "/home/ralf/local/lib/python3.6/site-packages/web3/middleware/attrdict.py", line 18, in middleware
    response = make_request(method, params)
  File "cytoolz/functoolz.pyx", line 236, in cytoolz.functoolz.curry.__call__
  File "cytoolz/functoolz.pyx", line 232, in cytoolz.functoolz.curry.__call__
  File "/home/ralf/local/lib/python3.6/site-packages/web3/middleware/formatting.py", line 48, in apply_formatters
    response = make_request(method, formatted_params)
  File "/home/ralf/local/lib/python3.6/site-packages/web3/middleware/normalize_errors.py", line 9, in middleware
    result = make_request(method, params)
  File "cytoolz/functoolz.pyx", line 236, in cytoolz.functoolz.curry.__call__
  File "cytoolz/functoolz.pyx", line 232, in cytoolz.functoolz.curry.__call__
  File "/home/ralf/local/lib/python3.6/site-packages/web3/middleware/formatting.py", line 50, in apply_formatters
    response = make_request(method, params)
  File "cytoolz/functoolz.pyx", line 236, in cytoolz.functoolz.curry.__call__
  File "cytoolz/functoolz.pyx", line 232, in cytoolz.functoolz.curry.__call__
  File "/home/ralf/local/lib/python3.6/site-packages/web3/middleware/formatting.py", line 47, in apply_formatters
    formatted_params = formatter(params)
  File "cytoolz/functoolz.pyx", line 236, in cytoolz.functoolz.curry.__call__
  File "cytoolz/functoolz.pyx", line 232, in cytoolz.functoolz.curry.__call__
  File "/home/ralf/local/lib/python3.6/site-packages/eth_utils/functional.py", line 22, in inner
    return callback(fn(*args, **kwargs))
  File "/home/ralf/local/lib/python3.6/site-packages/web3/utils/formatters.py", line 41, in apply_formatter_at_index
    yield formatter(item)
  File "cytoolz/functoolz.pyx", line 236, in cytoolz.functoolz.curry.__call__
  File "cytoolz/functoolz.pyx", line 232, in cytoolz.functoolz.curry.__call__
  File "/home/ralf/local/lib/python3.6/site-packages/web3/utils/rpc_abi.py", line 69, in apply_abi_formatters_to_dict
    [data[field] for field in fields],
  File "cytoolz/functoolz.pyx", line 236, in cytoolz.functoolz.curry.__call__
  File "cytoolz/functoolz.pyx", line 232, in cytoolz.functoolz.curry.__call__
  File "/home/ralf/local/lib/python3.6/site-packages/web3/utils/abi.py", line 442, in map_abi_data
    return pipe(data, *pipeline)
  File "cytoolz/functoolz.pyx", line 589, in cytoolz.functoolz.pipe
  File "cytoolz/functoolz.pyx", line 565, in cytoolz.functoolz.c_pipe
  File "cytoolz/functoolz.pyx", line 236, in cytoolz.functoolz.curry.__call__
  File "cytoolz/functoolz.pyx", line 232, in cytoolz.functoolz.curry.__call__
  File "/home/ralf/local/lib/python3.6/site-packages/web3/utils/abi.py", line 474, in data_tree_map
    return recursive_map(map_to_typed_data, data_tree)
  File "/home/ralf/local/lib/python3.6/site-packages/web3/utils/decorators.py", line 35, in wrapped
    wrapped_val = to_wrap(*args)
  File "/home/ralf/local/lib/python3.6/site-packages/web3/utils/formatters.py", line 115, in recursive_map
    items_mapped = map_collection(recurse, data)
  File "/home/ralf/local/lib/python3.6/site-packages/web3/utils/formatters.py", line 102, in map_collection
    return datatype(map(func, collection))
  File "/home/ralf/local/lib/python3.6/site-packages/web3/utils/formatters.py", line 114, in recurse
    return recursive_map(func, item)
  File "/home/ralf/local/lib/python3.6/site-packages/web3/utils/decorators.py", line 35, in wrapped
    wrapped_val = to_wrap(*args)
  File "/home/ralf/local/lib/python3.6/site-packages/web3/utils/formatters.py", line 116, in recursive_map
    return func(items_mapped)
  File "/home/ralf/local/lib/python3.6/site-packages/web3/utils/abi.py", line 471, in map_to_typed_data
    return ABITypedData(func(*elements))
  File "/home/ralf/local/lib/python3.6/site-packages/web3/utils/normalizers.py", line 45, in wrapper
    modified = to_wrap(abi_type, data)
  File "/home/ralf/local/lib/python3.6/site-packages/web3/utils/normalizers.py", line 124, in abi_address_to_hex
    validate_address(data)
  File "/home/ralf/local/lib/python3.6/site-packages/web3/utils/validation.py", line 152, in validate_address
    raise TypeError('Address {} must be provided as a string'.format(value))
TypeError: Address ['0x55bdaAf9f941A5BB3EacC8D876eeFf90b90ddac9', '0xC0B33D88C704455075a0724AA167a286da778DDE'] must be provided as a string

How can it be fixed?

The following patch fixes the issue for me, but would prevent passing in a single address as string.
I fail to see if/how one can declare a union type for the address parameter, something like address | address[]

Completely removing the type specification for the address field would also solve it.

diff --git a/web3/utils/rpc_abi.py b/web3/utils/rpc_abi.py
index 9adfa89..2392e8b 100644
--- a/web3/utils/rpc_abi.py
+++ b/web3/utils/rpc_abi.py
@@ -24,7 +24,7 @@ TRANSACTION_PARAMS_ABIS = {
 
 FILTER_PARAMS_ABIS = {
     'to': 'address',
-    'address': 'address',
+    'address': 'address[]',
 }
 
 TRACE_PARAMS_ABIS = {
schmir added a commit to trustlines-protocol/py-eth-index that referenced this issue Aug 10, 2018
We need this for testing interaction with the blockchain. This adds eth-tester
together with py-evm as a backend. This introduces lot's of new (indirect)
dependencies (as can be seen in the constraints.txt file)

Currently we don't deploy any of our contracts. Instead we test that eth_getLogs
works. I ran into a regresssion with that function while trying to update to
web3 4.5.0. See ethereum/web3.py#999
@pipermerriam
Copy link
Member

Hrm, looks like we should do two things.

  1. switch the ABI to use address[] like the diff above.
  2. Add an additional normalization layer to inspect whether the value is any string type, and if so, wrap it in a list.

@dylanjw dylanjw self-assigned this Aug 14, 2018
schmir added a commit to trustlines-protocol/py-eth-index that referenced this issue Aug 16, 2018
@dylanjw
Copy link
Contributor

dylanjw commented Aug 21, 2018

Fixed in #1005

@dylanjw dylanjw closed this as completed Aug 21, 2018
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

3 participants