polkascan / py-scale-codec

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

How to convert AccountID to SCALE encoded? #8

Closed kaigedong closed 4 years ago

kaigedong commented 4 years ago

When querying the storage, params should be SCALE encoded.

I saw many encoding test for int types. But as for AccountID (Alice): 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY, it should be converted to 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d

But how can I convert AccountID to SCALE encoded? Could you please show an example?

kaigedong commented 4 years ago

I didn't figure out now...

arjanz commented 4 years ago

The account public key you mentioned (0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d) is basically already SCALE encoded, that means you can use ('d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d') already as a param for storage calls.

I think you mean how to convert the SS58 encoded address '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' into the account public key '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', which is covered on the Substrate wiki here:

https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)

We have an implemention for this in our substrate-interface repos here:

https://github.com/polkascan/py-substrate-interface/blob/master/substrateinterface/utils/ss58.py#L32

Hope this helps!

kaigedong commented 4 years ago

Great! Thanks a lot!