polkascan / py-substrate-interface

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

Keypair sign returns bytes, not string #215

Closed Maharacha closed 2 years ago

Maharacha commented 2 years ago

https://github.com/polkascan/py-substrate-interface/blob/5119bcf87f9a07e570f0c5e9c1bedddf1db1d1fd/substrateinterface/base.py#L354 Sign method return bytes, but the docstring says string.

I noticed this because https://github.com/polkascan/py-substrate-interface/blob/5119bcf87f9a07e570f0c5e9c1bedddf1db1d1fd/substrateinterface/base.py#L1755 requires string. So to make it work I have to convert the signature to hex string before creating the extrinsic, signature.hex()

I did not have to do this before, not sure when it started to fail though...

arjanz commented 2 years ago

The docstring is indeed outdated, it was changed to the more native representation bytes. And it is not very intuitive to convert it first to be able to use it for create_signed_extrinsic(), for backwards compatibility sake I will convert the type to a Union[str, bytes] so both types can be used and internally converted.

Just like in:

https://github.com/polkascan/py-substrate-interface/blob/a5418355a66cacbe2340bd1de00f4bf759d61788/substrateinterface/base.py#L381)

Maharacha commented 2 years ago

The docstring is indeed outdated, it was changed to the more native representation bytes. And it is not very intuitive to convert it first to be able to use it for create_signed_extrinsic(), for backwards compatibility sake I will convert the type to a Union[str, bytes] so both types can be used and internally converted.

Just like in:

https://github.com/polkascan/py-substrate-interface/blob/a5418355a66cacbe2340bd1de00f4bf759d61788/substrateinterface/base.py#L381

)

Sounds great!