Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MetadataV15 support #112

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 53 additions & 26 deletions scalecodec/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,42 +532,69 @@ def add_portable_registry(self, metadata: 'GenericMetadataVersioned', prefix=Non

# Process extrinsic type in metadata to register correct Address and ExtrinsicSignature types
try:
# Retrieve Extrinsic using common namespace
extrinsic_type = self.get_decoder_class("sp_runtime::generic::unchecked_extrinsic::UncheckedExtrinsic")

# Try to fall back on extrinsic type in metadata
if extrinsic_type is None:
extrinsic_type_id = metadata[1][1]['extrinsic']['ty'].value
extrinsic_type = self.get_decoder_class(f"{prefix}::{extrinsic_type_id}")
if metadata.version >= 15:

if extrinsic_type is not None:
# Extract Address and Signature type and set in type registry
extrinsic_dict = metadata[1][1]['extrinsic'].value

types_dict = {}
address_type_string = f"{prefix}::{extrinsic_dict['address_type']}"

for param in extrinsic_type.scale_info_type.value['params']:
if param['name'] == 'Address':
# Update type registry
types_dict = {
"Address": address_type_string,
"AccountId": address_type_string,
"LookupSource": address_type_string,
"ExtrinsicSignature": f"{prefix}::{extrinsic_dict['signature_type']}"
}

type_string = f'{prefix}::{param["type"]}'
# Check if Address is MultiAddress
addres_type = self.get_decoder_class(address_type_string)

types_dict['Address'] = type_string
types_dict['AccountId'] = type_string
types_dict['LookupSource'] = type_string
if addres_type is self.get_decoder_class('sp_runtime::multiaddress::MultiAddress'):
for address_param in addres_type.scale_info_type.value['params']:
if address_param['name'] == 'AccountId':
# Set AccountId
types_dict['AccountId'] = f'{prefix}::{address_param["type"]}'

# Check if Address is MultiAddress
addres_type = self.get_decoder_class(type_string)
self.update_type_registry_types(types_dict)
else:

if addres_type is self.get_decoder_class('sp_runtime::multiaddress::MultiAddress'):
for address_param in addres_type.scale_info_type.value['params']:
if address_param['name'] == 'AccountId':
# Set AccountId
types_dict['AccountId'] = f'{prefix}::{address_param["type"]}'
# Retrieve Extrinsic using common namespace
extrinsic_type = self.get_decoder_class("sp_runtime::generic::unchecked_extrinsic::UncheckedExtrinsic")

elif param['name'] == 'Signature':
types_dict['ExtrinsicSignature'] = f'{prefix}::{param["type"]}'
# Try to fall back on extrinsic type in metadata
if extrinsic_type is None:
extrinsic_type_id = metadata[1][1]['extrinsic']['ty'].value
extrinsic_type = self.get_decoder_class(f"{prefix}::{extrinsic_type_id}")

# Update type registry
self.update_type_registry_types(types_dict)
if extrinsic_type is not None:
# Extract Address and Signature type and set in type registry

types_dict = {}

for param in extrinsic_type.scale_info_type.value['params']:
if param['name'] == 'Address':

type_string = f'{prefix}::{param["type"]}'

types_dict['Address'] = type_string
types_dict['AccountId'] = type_string
types_dict['LookupSource'] = type_string

# Check if Address is MultiAddress
addres_type = self.get_decoder_class(type_string)

if addres_type is self.get_decoder_class('sp_runtime::multiaddress::MultiAddress'):
for address_param in addres_type.scale_info_type.value['params']:
if address_param['name'] == 'AccountId':
# Set AccountId
types_dict['AccountId'] = f'{prefix}::{address_param["type"]}'

elif param['name'] == 'Signature':
types_dict['ExtrinsicSignature'] = f'{prefix}::{param["type"]}'

# Update type registry
self.update_type_registry_types(types_dict)
except NotImplementedError:
pass

Expand Down
272 changes: 231 additions & 41 deletions scalecodec/type_registry/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,10 @@
[
"V14",
"MetadataV14"
],
[
"V15",
"MetadataV15"
]
]
},
Expand Down Expand Up @@ -1021,6 +1025,231 @@
]
]
},
"MetadataV15": {
"type": "struct",
"type_mapping": [
[
"types",
"PortableRegistry"
],
[
"pallets",
"Vec<PalletMetadataV15>"
],
[
"extrinsic",
"ExtrinsicMetadataV15"
],
[
"runtime_type",
"SiLookupTypeId"
],
[
"apis",
"Vec<RuntimeApiMetadataV15>"
],
[
"outer_enums",
"OuterEnums15"
],
[
"custom",
"Vec<CustomMetadata15>"
]
]
},
"PalletMetadataV15": {
"type": "struct",
"base_class": "ScaleInfoPalletMetadata",
"type_mapping": [
[
"name",
"Text"
],
[
"storage",
"Option<StorageMetadataV14>"
],
[
"calls",
"Option<PalletCallMetadataV14>"
],
[
"event",
"Option<PalletEventMetadataV14>"
],
[
"constants",
"Vec<PalletConstantMetadataV14>"
],
[
"error",
"Option<PalletErrorMetadataV14>"
],
[
"index",
"u8"
],
[
"docs",
"Vec<Text>"
]
]
},
"ExtrinsicMetadataV15": {
"type": "struct",
"type_mapping": [
[
"version",
"u8"
],
[
"address_type",
"SiLookupTypeId"
],
[
"call_type",
"SiLookupTypeId"
],
[
"signature_type",
"SiLookupTypeId"
],
[
"extra_type",
"SiLookupTypeId"
],
[
"signed_extensions",
"Vec<SignedExtensionMetadataV14>"
]
]
},
"OuterEnums15": {
"type": "struct",
"type_mapping": [
[
"call_type",
"SiLookupTypeId"
],
[
"event_type",
"SiLookupTypeId"
],
[
"error_type",
"SiLookupTypeId"
]
]
},
"CustomMetadata15": "BTreeMap<Text, CustomValueMetadata15>",
"CustomValueMetadata15": "Bytes",
"RuntimeApiMetadataV15": {
"type": "struct",
"base_class": "GenericRuntimeApiMetadata",
"type_mapping": [
[
"name",
"Text"
],
[
"methods",
"Vec<RuntimeApiMethodMetadataV15>"
],
[
"docs",
"Vec<Text>"
]
]
},
"RuntimeApiMethodMetadataV15": {
"type": "struct",
"base_class": "GenericRuntimeApiMethodMetadata",
"type_mapping": [
[
"name",
"Text"
],
[
"inputs",
"Vec<RuntimeApiMethodParamMetadataV15>"
],
[
"output",
"SiLookupTypeId"
],
[
"docs",
"Vec<Text>"
]
]
},
"RuntimeApiMethodParamMetadataV15": {
"type": "struct",
"type_mapping": [
[
"name",
"Text"
],
[
"type",
"SiLookupTypeId"
]
]
},
"RuntimeApiMetadataV14": {
"type": "struct",
"base_class": "LegacyRuntimeApiMetadata",
"type_mapping": [
[
"name",
"Text"
],
[
"methods",
"Vec<RuntimeApiMethodMetadataV14>"
],
[
"docs",
"Vec<Text>"
]
]
},
"RuntimeApiMethodMetadataV14": {
"type": "struct",
"base_class": "LegacyRuntimeApiMethodMetadata",
"type_mapping": [
[
"name",
"Text"
],
[
"inputs",
"Vec<RuntimeApiMethodParamMetadataV14>"
],
[
"output",
"String"
],
[
"docs",
"Vec<Text>"
]
]
},
"RuntimeApiMethodParamMetadataV14": {
"type": "struct",
"type_mapping": [
[
"name",
"Text"
],
[
"type",
"String"
]
]
},
"PalletMetadataV14": {
"type": "struct",
"base_class": "ScaleInfoPalletMetadata",
Expand Down Expand Up @@ -1735,46 +1964,7 @@
]
]
},
"ContractExecResult": "ContractExecResultTo267",
"RuntimeCallDefinition": {
"type": "struct",
"base_class": "GenericRuntimeCallDefinition",
"type_mapping": [
[
"api",
"String"
],
[
"method",
"String"
],
[
"description",
"String"
],
[
"params",
"Vec<RuntimeCallDefinitionParam>"
],
[
"type",
"String"
]
]
},
"RuntimeCallDefinitionParam": {
"type": "struct",
"type_mapping": [
[
"name",
"String"
],
[
"type",
"String"
]
]
}
"ContractExecResult": "ContractExecResultTo267"
},
"runtime_api": {
"AccountNonceApi": {
Expand Down Expand Up @@ -2834,8 +3024,8 @@
["nonce", "H64"]
]
},
"EthBloom": "H2048",
"H2048": "[u8; 256]",
"EthBloom": "H2048",
"H64": "[u8; 8]",
"Permill": "u32",
"TransactionV2": {
Expand Down
Loading
Loading