Skip to main content

Schema

Struct Schema 

Source
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

Source

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

Source

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

Source

pub fn chain_data(&self) -> &ChainData

Get the chain data for the schema.

Source

pub fn metadata_hash(&self) -> Result<[u8; 32], SchemaError>

Source

pub fn rollup_expected_index( &self, rollup_type: RollupRoots, ) -> Result<usize, SchemaError>

Source

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

Source

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).

Source

pub fn types(&self) -> &[Ty<IndexLinking>]

Source

pub fn serde_metadata(&self) -> &[ContainerSerdeMetadata]

Source

pub fn root_types(&self) -> &[usize]

Trait Implementations§

Source§

impl BorshDeserialize for Schema

Source§

fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl BorshSerialize for Schema

Source§

fn serialize<__W: Write>(&self, writer: &mut __W) -> Result<(), Error>

Source§

impl Debug for Schema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Schema

Source§

fn default() -> Schema

Returns the “default value” for a type. Read more
Source§

impl TypeResolver for Schema

Auto Trait Implementations§

§

impl !Freeze for Schema

§

impl !RefUnwindSafe for Schema

§

impl Send for Schema

§

impl Sync for Schema

§

impl Unpin for Schema

§

impl UnsafeUnpin for Schema

§

impl !UnwindSafe for Schema

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.