polkascan / py-substrate-interface

Python Substrate Interface
https://polkascan.github.io/py-substrate-interface/
Apache License 2.0
240 stars 116 forks source link

subscribing to new block headers #138

Closed Nadro-J closed 3 years ago

Nadro-J commented 3 years ago

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 commented 3 years ago

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

Nadro-J commented 3 years ago

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