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: Library,
storage_slots: Vec<StorageSlot>,
) -> Result<AccountComponent, AccountError>
pub fn new( code: Library, storage_slots: Vec<StorageSlot>, ) -> Result<AccountComponent, 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 compile(
source_code: impl Parse,
assembler: Assembler,
storage_slots: Vec<StorageSlot>,
) -> Result<AccountComponent, AccountError>
pub fn compile( source_code: impl Parse, assembler: Assembler, storage_slots: Vec<StorageSlot>, ) -> Result<AccountComponent, AccountError>
Returns a new AccountComponent whose library is compiled from the provided source_code
using the specified assembler and with the given storage_slots.
All procedures exported from the provided code will become members of the account’s public
interface when added to an AccountCode.
§Errors
Returns an error if:
- the compilation of the provided source code fails.
- The number of storage slots exceeds 255.
Sourcepub fn from_template(
template: &AccountComponentTemplate,
init_storage_data: &InitStorageData,
) -> Result<AccountComponent, AccountError>
pub fn from_template( template: &AccountComponentTemplate, init_storage_data: &InitStorageData, ) -> Result<AccountComponent, AccountError>
Instantiates an AccountComponent from the AccountComponentTemplate.
The template’s component metadata might contain placeholders, which can be replaced by
mapping storage placeholders to values through the init_storage_data parameter.
§Errors
- If any of the component’s storage entries cannot be transformed into a valid storage slot. This could be because the metadata is invalid, or storage values were not provided (or they are not of a valid type)
Sourcepub fn from_package_with_init_data(
package: &Package,
init_storage_data: &InitStorageData,
) -> Result<AccountComponent, AccountError>
pub fn from_package_with_init_data( package: &Package, init_storage_data: &InitStorageData, ) -> Result<AccountComponent, 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 the library and account component metadatainit_storage_data- The initialization data for storage slots
§Errors
Returns an error if:
- The package does not contain account component metadata
- The package cannot be converted to an
AccountComponentTemplate - 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 library(&self) -> &Library
pub fn library(&self) -> &Library
Returns a reference to the underlying Library 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 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_name(
&self,
proc_name: impl TryInto<QualifiedProcedureName>,
) -> Option<Word>
pub fn get_procedure_root_by_name( &self, proc_name: impl TryInto<QualifiedProcedureName>, ) -> Option<Word>
Returns the digest of the procedure with the specified name, 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,
) -> AccountComponent
pub fn with_supported_type( self, supported_type: AccountType, ) -> AccountComponent
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>,
) -> AccountComponent
pub fn with_supported_types( self, supported_types: BTreeSet<AccountType>, ) -> AccountComponent
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_supports_all_types(self) -> AccountComponent
pub fn with_supports_all_types(self) -> AccountComponent
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 Library
impl From<AccountComponent> for Library
Source§fn from(component: AccountComponent) -> Library
fn from(component: AccountComponent) -> Library
Source§impl From<AuthEcdsaK256Keccak> for AccountComponent
impl From<AuthEcdsaK256Keccak> for AccountComponent
Source§fn from(ecdsa: AuthEcdsaK256Keccak) -> AccountComponent
fn from(ecdsa: AuthEcdsaK256Keccak) -> AccountComponent
Source§impl From<AuthEcdsaK256KeccakAcl> for AccountComponent
impl From<AuthEcdsaK256KeccakAcl> for AccountComponent
Source§fn from(ecdsa: AuthEcdsaK256KeccakAcl) -> AccountComponent
fn from(ecdsa: AuthEcdsaK256KeccakAcl) -> AccountComponent
Source§impl From<AuthEcdsaK256KeccakMultisig> for AccountComponent
impl From<AuthEcdsaK256KeccakMultisig> for AccountComponent
Source§fn from(multisig: AuthEcdsaK256KeccakMultisig) -> AccountComponent
fn from(multisig: AuthEcdsaK256KeccakMultisig) -> AccountComponent
Source§impl From<AuthRpoFalcon512> for AccountComponent
impl From<AuthRpoFalcon512> for AccountComponent
Source§fn from(falcon: AuthRpoFalcon512) -> AccountComponent
fn from(falcon: AuthRpoFalcon512) -> AccountComponent
Source§impl From<AuthRpoFalcon512Acl> for AccountComponent
impl From<AuthRpoFalcon512Acl> for AccountComponent
Source§fn from(falcon: AuthRpoFalcon512Acl) -> AccountComponent
fn from(falcon: AuthRpoFalcon512Acl) -> AccountComponent
Source§impl From<AuthRpoFalcon512Multisig> for AccountComponent
impl From<AuthRpoFalcon512Multisig> for AccountComponent
Source§fn from(multisig: AuthRpoFalcon512Multisig) -> AccountComponent
fn from(multisig: AuthRpoFalcon512Multisig) -> AccountComponent
Source§impl From<BasicFungibleFaucet> for AccountComponent
impl From<BasicFungibleFaucet> for AccountComponent
Source§fn from(faucet: BasicFungibleFaucet) -> AccountComponent
fn from(faucet: BasicFungibleFaucet) -> AccountComponent
Source§impl From<BasicWallet> for AccountComponent
impl From<BasicWallet> for AccountComponent
Source§fn from(_: BasicWallet) -> AccountComponent
fn from(_: BasicWallet) -> AccountComponent
Source§impl From<NetworkFungibleFaucet> for AccountComponent
impl From<NetworkFungibleFaucet> for AccountComponent
Source§fn from(network_faucet: NetworkFungibleFaucet) -> AccountComponent
fn from(network_faucet: NetworkFungibleFaucet) -> AccountComponent
Source§impl From<NoAuth> for AccountComponent
impl From<NoAuth> for AccountComponent
Source§fn from(_: NoAuth) -> AccountComponent
fn from(_: NoAuth) -> AccountComponent
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§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