polkascan / py-scale-codec

Python SCALE-Codec
https://polkascan.github.io/py-scale-codec/
Apache License 2.0
54 stars 54 forks source link

Decoder class for "MerkleRoot" not found #73

Closed khssnv closed 2 years ago

khssnv commented 2 years ago

Hi there :wave:

I tried to use py-substrate-interface to work with Crust Network and by an error message (below) it seems like py-scale-codec misses a type registry file for it.

I would like to add the type registry JSON file if you may tell me how I can get it.

Code sample:

crust_network_place_storage_order.py ```python import substrateinterface CID = "QmYoEcsE1aCCDPrgNfEtiLdPZBj4dncFNUvD6vZLSokeXa" SIZE = 7388569 MNEMONIC = "bottom drive obey lake curtain smoke basket hold race lonely fit walk" # well known account def place_storage_order(cid: str, size: int) -> None: keypair = substrateinterface.Keypair.create_from_mnemonic(MNEMONIC) crust = substrateinterface.SubstrateInterface( url="wss://rpc.crust.network", ) call = crust.compose_call( call_module="Market", call_function="place_storage_order", call_params=dict( cid=cid, reported_file_size=size, tips=0, memo="", ) ) extrinsic = crust.create_signed_extrinsic( call=call, keypair=keypair, ) receipt = crust.submit_extrinsic(extrinsic, wait_for_finalization=True) return receipt if __name__ == "__main__": receipt = place_storage_order(CID, SIZE) print(receipt) ```

Error message:

$ python crust_network_place_storage_order.py 
Traceback (most recent call last):
  File "crust_network_place_storage_order.py", line 32, in <module>
    receipt = place_storage_order(CID, SIZE)
  File "crust_network_place_storage_order.py", line 13, in place_storage_order
    call = crust.compose_call(
  File "/home/khassanov/.cache/pypoetry/virtualenvs/crust-network-python-example-Zg3OD2BK-py3.8/lib/python3.8/site-packages/substrateinterface/base.py", line 1622, in compose_call
    call.encode({
  File "/home/khassanov/.cache/pypoetry/virtualenvs/crust-network-python-example-Zg3OD2BK-py3.8/lib/python3.8/site-packages/scalecodec/base.py", line 709, in encode
    self.data = self.process_encode(self.value_serialized)
  File "/home/khassanov/.cache/pypoetry/virtualenvs/crust-network-python-example-Zg3OD2BK-py3.8/lib/python3.8/site-packages/scalecodec/types.py", line 1483, in process_encode
    arg_obj = self.runtime_config.create_scale_object(
  File "/home/khassanov/.cache/pypoetry/virtualenvs/crust-network-python-example-Zg3OD2BK-py3.8/lib/python3.8/site-packages/scalecodec/base.py", line 160, in create_scale_object
    raise NotImplementedError('Decoder class for "{}" not found'.format(type_string))
NotImplementedError: Decoder class for "MerkleRoot" not found
arjanz commented 2 years ago

Ok I found a type registry for Crust in the PolkadotJS repos, so I converted the format and it seems to work.

The only change in your supplied sample I did was change the call param memo to _memo.

arjanz commented 2 years ago

Released in https://github.com/polkascan/py-scale-codec/releases/tag/v1.0.37

khssnv commented 2 years ago

Closed by https://github.com/polkascan/py-scale-codec/commit/6622087927cfeeaa0e5e92ad19c75959944869c6