Expand description
This crate provides a set of types which build on each other. The ultimate goal is to be able to define the necessary type information needed to describe how historic Substrate types are SCALE encoded.
The main types exposed here are as follows:
TypeRegistry: the lowest level type which one can populate with type information (viaTypeRegistry::insert()andTypeRegistry::insert_runtime_api()), and then query to resolve some type name to the relevant information (viaTypeRegistry::resolve_type()andTypeRegistry::runtime_api()).TypeRegistrySet: a set of the above, which will resolve types (viaTypeRegistrySet::resolve_type()) by working through the inner type registries until it finds the relevant information (or doesn’t find anything). This allows us to combine type registries in different ways to alter how we resolve things.ChainTypeRegistry: this type is constructed by deserializing some JSON (or similar) which describes all of the types that we need to know about on a given chain. The main function here isChainTypeRegistry::for_spec_version(), which returns aTypeRegistrySetfor resolving types for the given spec version.
We also expose an InsertName, which is built by parsing type names like Vec<T> from strings, and used in
TypeRegistry::insert() to insert types, and then LookupName, which is built by parsing type names like
Vec<T>, [u8; 32] and (bool, u32) and is used to lookup the corresponding type information via TypeRegistry::resolve_type()
and similar. Finally, TypeShape is an enum used to describe the shape of the type inserted via TypeRegistry::insert().
This crate, like scale-info, can be used in conjunction with crates like:
scale-decodeto decode SCALE encoded bytes into custom types based on this type information.scale-encodeto SCALE encode custom types into bytes based on this type information.scale-valueto SCALE encode or decode from aValuetype (a bit likeserde_json’sValuetype).
Re-exports§
pub use chain_types::ChainTypeRegistry;pub use insert_name::InsertName;pub use lookup_name::LookupName;pub use type_registry::RuntimeApiInput;pub use type_registry::TypeRegistry;pub use type_registry_set::TypeRegistrySet;pub use type_shape::TypeShape;
Modules§
- chain_
types - This module provides a
ChainTypeRegistry, which is constructed by deserializing some data into it. JSON is the expected input format, though in theory others can be used too. - insert_
name - This module provides the name used to insert types in a registry.
- lookup_
name - This module provides a struct,
LookupName. This struct represents a single concrete type that can be looked up in thecrate::TypeRegistry. - type_
registry - This module provides a
TypeRegistry, which can be used to store and resolve type information for types based on their names. - type_
registry_ set - This module provides a
TypeRegistrySet, which is constructed from a selection ofcrate::TypeRegistry’s, and will resolve types by looking through each one in a known order until a match is found. This allows us to compose different sets of types into a single thing which itself also implementsscale_type_resolver::TypeResolver. - type_
shape - This module provides a
TypeShapeenum, which describes the shape of a type, or in other words, how it should be SCALE encoded/decoded.