pub struct Schema {
pub version: u8,
pub schema_id: Hash,
pub name: String,
pub global_types: Vec<GlobalStateType>,
pub owned_types: Vec<OwnedStateType>,
pub transitions: Vec<TransitionDef>,
pub root_script: Vec<u8>,
}Expand description
Contract schema
A schema defines the rules that govern a class of contracts: what state types exist, what transitions are valid, and how to validate them.
Fields§
§version: u8Schema version
schema_id: HashUnique schema identifier
name: StringHuman-readable name
global_types: Vec<GlobalStateType>Defined global state types
owned_types: Vec<OwnedStateType>Defined owned state types
transitions: Vec<TransitionDef>Defined transition types
root_script: Vec<u8>Root validation script (runs on every transition)
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn new(
schema_id: Hash,
name: impl Into<String>,
global_types: Vec<GlobalStateType>,
owned_types: Vec<OwnedStateType>,
transitions: Vec<TransitionDef>,
root_script: Vec<u8>,
) -> Self
pub fn new( schema_id: Hash, name: impl Into<String>, global_types: Vec<GlobalStateType>, owned_types: Vec<OwnedStateType>, transitions: Vec<TransitionDef>, root_script: Vec<u8>, ) -> Self
Create a new schema
Sourcepub fn global_type(&self, type_id: StateTypeId) -> Option<&GlobalStateType>
pub fn global_type(&self, type_id: StateTypeId) -> Option<&GlobalStateType>
Get a global state type by ID
Sourcepub fn owned_type(&self, type_id: StateTypeId) -> Option<&OwnedStateType>
pub fn owned_type(&self, type_id: StateTypeId) -> Option<&OwnedStateType>
Get an owned state type by ID
Sourcepub fn transition_def(&self, transition_id: u16) -> Option<&TransitionDef>
pub fn transition_def(&self, transition_id: u16) -> Option<&TransitionDef>
Get a transition definition by ID
Sourcepub fn has_type(&self, type_id: StateTypeId) -> bool
pub fn has_type(&self, type_id: StateTypeId) -> bool
Validate that a type ID is defined in the schema
Sourcepub fn has_transition(&self, transition_id: u16) -> bool
pub fn has_transition(&self, transition_id: u16) -> bool
Validate that a transition ID is defined in the schema
Sourcepub fn validate_transition(
&self,
transition: &Transition,
) -> Result<(), SchemaError>
pub fn validate_transition( &self, transition: &Transition, ) -> Result<(), SchemaError>
Validate a transition against this schema
Sourcepub fn fungible_token(schema_id: Hash, name: impl Into<String>) -> Self
pub fn fungible_token(schema_id: Hash, name: impl Into<String>) -> Self
Create a minimal fungible token schema
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Schema
impl<'de> Deserialize<'de> for Schema
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Schema
impl StructuralPartialEq 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more