pub struct AccountComponent { /* private fields */ }Expand description
An AccountComponent defines a Library of code and the initial
value and types of the StorageSlots it accesses.
One or more components can be used to built AccountCode and
AccountStorage.
Each component is independent of other components and can only access its own storage slots. Each component defines its own storage layout starting at index 0 up to the length of the storage slots vector.
Components define the AccountTypes they support, meaning whether the component can be used
to instantiate an account of that type. For example, a component implementing a fungible faucet
would only specify support for AccountType::FungibleFaucet. Using it to instantiate a
regular account would fail. By default, the set of supported types is empty, so each component
is forced to explicitly define what it supports.
Implementations§
Source§impl AccountComponent
impl AccountComponent
Sourcepub fn new(
code: impl Into<AccountComponentCode>,
storage_slots: Vec<StorageSlot>,
) -> Result<Self, AccountError>
pub fn new( code: impl Into<AccountComponentCode>, storage_slots: Vec<StorageSlot>, ) -> Result<Self, AccountError>
Returns a new AccountComponent constructed from the provided library and
storage_slots.
All procedures exported from the provided code will become members of the account’s public
interface when added to an AccountCode.
§Errors
The following list of errors is exhaustive and can be relied upon for expecting the call
to this function. It is recommended that custom components ensure these conditions by design
or in their fallible constructors.
Returns an error if:
- The number of given
StorageSlots exceeds 255.
Sourcepub fn from_package(
package: &Package,
init_storage_data: &InitStorageData,
) -> Result<Self, AccountError>
pub fn from_package( package: &Package, init_storage_data: &InitStorageData, ) -> Result<Self, AccountError>
Creates an AccountComponent from a Package using InitStorageData.
This method provides type safety by leveraging the component’s metadata to validate storage initialization data. The package must contain explicit account component metadata.
§Arguments
package- The package containing theLibraryand account component metadatainit_storage_data- The initialization data for storage slots
§Errors
Returns an error if:
- The package does not contain a library artifact
- The package does not contain account component metadata
- The metadata cannot be deserialized from the package
- The storage initialization fails due to invalid or missing data
- The component creation fails
Sourcepub fn from_library(
library: &AccountComponentCode,
account_component_metadata: &AccountComponentMetadata,
init_storage_data: &InitStorageData,
) -> Result<Self, AccountError>
pub fn from_library( library: &AccountComponentCode, account_component_metadata: &AccountComponentMetadata, init_storage_data: &InitStorageData, ) -> Result<Self, AccountError>
Creates an AccountComponent from an AccountComponentCode and
AccountComponentMetadata.
This method provides type safety by leveraging the component’s metadata to validate
the passed storage initialization data (InitStorageData).
§Arguments
library- The component’s assembled codeaccount_component_metadata- The component’s metadata, which describes the storage layoutinit_storage_data- The initialization data for storage slots
§Errors
Returns an error if:
- The package does not contain a library artifact
- The package does not contain account component metadata
- The metadata cannot be deserialized from the package
- The storage initialization fails due to invalid or missing data
- The component creation fails
Sourcepub fn storage_size(&self) -> u8
pub fn storage_size(&self) -> u8
Returns the number of storage slots accessible from this component.
Sourcepub fn component_code(&self) -> &AccountComponentCode
pub fn component_code(&self) -> &AccountComponentCode
Returns a reference to the underlying AccountComponentCode of this component.
Sourcepub fn mast_forest(&self) -> &MastForest
pub fn mast_forest(&self) -> &MastForest
Returns a reference to the underlying MastForest of this component.
Sourcepub fn storage_slots(&self) -> &[StorageSlot]
pub fn storage_slots(&self) -> &[StorageSlot]
Returns a slice of the underlying StorageSlots of this component.
Sourcepub fn metadata(&self) -> Option<&AccountComponentMetadata>
pub fn metadata(&self) -> Option<&AccountComponentMetadata>
Returns the component metadata, if any.
Sourcepub fn storage_schema(&self) -> Option<&StorageSchema>
pub fn storage_schema(&self) -> Option<&StorageSchema>
Returns the storage schema associated with this component, if any.
Sourcepub fn supported_types(&self) -> &BTreeSet<AccountType>
pub fn supported_types(&self) -> &BTreeSet<AccountType>
Returns a reference to the supported AccountTypes.
Sourcepub fn supports_type(&self, account_type: AccountType) -> bool
pub fn supports_type(&self, account_type: AccountType) -> bool
Returns true if this component supports the given account_type, false otherwise.
Sourcepub fn get_procedures(&self) -> Vec<(Word, bool)>
pub fn get_procedures(&self) -> Vec<(Word, bool)>
Returns a vector of tuples (digest, is_auth) for all procedures in this component.
Sourcepub fn get_procedure_root_by_path(
&self,
proc_name: impl AsRef<Path>,
) -> Option<Word>
pub fn get_procedure_root_by_path( &self, proc_name: impl AsRef<Path>, ) -> Option<Word>
Returns the digest of the procedure with the specified path, or None if it was not found
in this component’s library or its library path is malformed.
Sourcepub fn with_supported_type(self, supported_type: AccountType) -> Self
pub fn with_supported_type(self, supported_type: AccountType) -> Self
Adds supported_type to the set of AccountTypes supported by this component.
This function has the semantics of BTreeSet::insert, i.e. adding a type twice is fine
and it can be called multiple times with different account types.
Sourcepub fn with_supported_types(
self,
supported_types: BTreeSet<AccountType>,
) -> Self
pub fn with_supported_types( self, supported_types: BTreeSet<AccountType>, ) -> Self
Overwrites any previously set supported types with the given set.
This can be used to reset the supported types of a component to a chosen set, which may be useful after cloning an existing component.
Sourcepub fn with_metadata(self, metadata: AccountComponentMetadata) -> Self
pub fn with_metadata(self, metadata: AccountComponentMetadata) -> Self
Attaches metadata to this component for downstream schema commitments and introspection.
Sourcepub fn with_supports_all_types(self) -> Self
pub fn with_supports_all_types(self) -> Self
Sets the AccountTypes supported by this component to all account types.
Trait Implementations§
Source§impl Clone for AccountComponent
impl Clone for AccountComponent
Source§fn clone(&self) -> AccountComponent
fn clone(&self) -> AccountComponent
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AccountComponent
impl Debug for AccountComponent
Source§impl From<AccountComponent> for AccountComponentCode
impl From<AccountComponent> for AccountComponentCode
Source§fn from(component: AccountComponent) -> Self
fn from(component: AccountComponent) -> Self
Source§impl PartialEq for AccountComponent
impl PartialEq for AccountComponent
impl Eq for AccountComponent
impl StructuralPartialEq for AccountComponent
Auto Trait Implementations§
impl Freeze for AccountComponent
impl RefUnwindSafe for AccountComponent
impl Send for AccountComponent
impl Sync for AccountComponent
impl Unpin for AccountComponent
impl UnwindSafe for AccountComponent
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more