polkascan / py-scale-codec

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

Use struct in stead of tuples for variants with named fields #68

Closed arjanz closed 2 years ago

arjanz commented 2 years ago

For variant type definitions in the PortableRegistry with named fields, for example:

{'name': 'Deposit', 'fields': [{'name': 'who', 'type': 0, 'typeName': 'T::AccountId', 'docs': []}, {'name': 'amount', 'type': 6, 'typeName': 'T::Balance', 'docs': []}], 'index': 7, 'docs': ['Some amount was deposited (e.g. for transaction fees).']}

were until now converted to tuples, discarding the name of the field.

Proposal is to use structs in stead of tuples when names are defined.

For example the attributes of the event Balances.Deposit:

was ('F3opxRbN5ZbjJNU511Kj2TLuzFcDq9BGduA9TgiECafpg29', 33599708)

and will now be {'who': 'F3opxRbN5ZbjJNU511Kj2TLuzFcDq9BGduA9TgiECafpg29', 'amount': 33599708}

arjanz commented 2 years ago

https://github.com/polkascan/py-scale-codec/commit/ad2f86db8a71582ca68126d0adb1892facb3339a