pub struct Schema { /* private fields */ }Expand description
A schema, representing set of types (i.e. rust code) as a data structure. The schema allows any included type’s borsh serialization to be displayed as a human readable string, and the type’s JSON serialisation to be re-serialised to borsh without depending on the original Rust type. It is also serialisable and therefore, once generated for a rollup, can be imported and used with non-Rust languages, enabling toolkits in any language to implement the same functionality as above.
A schema can be instantiated for any type that implements either UniversalWallet or
OverrideSchema. In turn, UniversalWallet is intended to be automatically derived using the
UniversalWallet macro.
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn of_single_type<T: UniversalWallet>() -> Result<Self, SchemaError>
pub fn of_single_type<T: UniversalWallet>() -> Result<Self, SchemaError>
Instantiate a schema for a single type. This root type will be at index 0
Sourcepub fn of_rollup_types_with_chain_data<Transaction: UniversalWallet, UnsignedTransaction: UniversalWallet, RuntimeCall: UniversalWallet, Address: UniversalWallet>(
chain_data: ChainData,
) -> Result<Self, SchemaError>
pub fn of_rollup_types_with_chain_data<Transaction: UniversalWallet, UnsignedTransaction: UniversalWallet, RuntimeCall: UniversalWallet, Address: UniversalWallet>( chain_data: ChainData, ) -> Result<Self, SchemaError>
Instantiate a schema for a standard set of rollup types: its complete transaction, its
unsigned transaction, and its call message type.
The types will be accessible using the indices stored in root_type_indices (in the above
order); they can also be queried using the RollupRoots enum through the _rollup-tagged
functions on the schema
Sourcepub fn chain_data(&self) -> &ChainData
pub fn chain_data(&self) -> &ChainData
Get the chain data for the schema.
pub fn metadata_hash(&self) -> Result<[u8; 32], SchemaError>
pub fn rollup_expected_index( &self, rollup_type: RollupRoots, ) -> Result<usize, SchemaError>
Sourcepub fn display(
&self,
type_index: usize,
input: &[u8],
) -> Result<String, SchemaError>
pub fn display( &self, type_index: usize, input: &[u8], ) -> Result<String, SchemaError>
Use the schema to display the given type using the provided borsh encoded input
Sourcepub fn chain_hash(&self) -> Result<[u8; 32], SchemaError>
pub fn chain_hash(&self) -> Result<[u8; 32], SchemaError>
Returns the chain ID calculated using the merkle root of all the schema types, combined with any chain-specific metadata. This allows the chain ID to be used for verification of the schema (and thus verification that a transaction claiming to correspond to a given schema will have the effect it claims).