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

subscribing to new block headers #138

Closed
Nadro-J opened this issue Oct 13, 2021 · 2 comments
Closed

subscribing to new block headers #138

Nadro-J opened this issue Oct 13, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@Nadro-J
Copy link

Nadro-J commented Oct 13, 2021

The code below works

from substrateinterface import SubstrateInterface

substrate = SubstrateInterface(
    url="wss://rpc.polkadot.io"
)

def new_block(obj, update_nr, subscription_id):
    print(obj['header']['parentHash'])

result = substrate.subscribe_block_headers(subscription_handler=new_block)

but when I add include_author=True to subscribe_block_headers I get the following :

Traceback (most recent call last):
  File "/root/py-subalert/test.py", line 10, in <module>
    result = substrate.subscribe_block_headers(new_block, include_author=True)
  File "/usr/local/lib/python3.9/dist-packages/substrateinterface/base.py", line 2427, in subscribe_block_headers
    return self.__get_block_handler(
  File "/usr/local/lib/python3.9/dist-packages/substrateinterface/utils/caching.py", line 38, in wrapper
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/substrateinterface/base.py", line 2280, in __get_block_handler
    result = self.rpc_request(f"chain_subscribe{rpc_method_prefix}Heads", [], result_handler=result_handler)
  File "/usr/local/lib/python3.9/dist-packages/substrateinterface/base.py", line 567, in rpc_request
    callback_result = result_handler(message, update_nr, subscription_id)
  File "/usr/local/lib/python3.9/dist-packages/substrateinterface/base.py", line 2270, in result_handler
    new_block = decode_block({'header': message['params']['result']})
  File "/usr/local/lib/python3.9/dist-packages/substrateinterface/base.py", line 2246, in decode_block
    if log_digest.value['PreRuntime']['engine'] == 'BABE':
TypeError: tuple indices must be integers or slices, not str

python: 3.9
scalecodec: 1.0.6
substrate-interface: 1.0.2

Does this reproduce for anyone else?

@arjanz arjanz added the bug Something isn't working label Oct 13, 2021
@arjanz
Copy link
Member

arjanz commented Oct 14, 2021

Fix released in https://github.com/polkascan/py-substrate-interface/releases/tag/v1.0.3

@Nadro-J
Copy link
Author

Nadro-J commented Oct 14, 2021

Working nicely :) Thanks for your work Arjanz, appreciated!

@Nadro-J Nadro-J closed this as completed Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants