pub struct AccountBuilder { /* private fields */ }Expand description
A convenient builder for an Account allowing for safe construction of an account by
combining multiple AccountComponents.
This will build a valid new account with these properties:
- An empty
AssetVault. - The nonce set to
Felt::ZERO. - A seed which results in an
AccountIdvalid for the configured account type.
By default, the builder is initialized with:
- The
account_typeset toAccountType::Private. - The
versionset toAccountIdVersion::Version1.
AccountBuilder::with_component (or AccountBuilder::with_components) must be called at
least once, and exactly one of the added components must be an authentication component (i.e. a
component exporting a procedure marked with the @auth_script attribute). The auth component is
identified and extracted automatically when AccountBuilder::build is called.
§Security
The builder only enforces the structural requirement of exactly one auth component; it does not check that the auth component is a sensible choice for the other components on the account. In particular, an auth component that performs no authentication makes the account permissionless: every state-changing procedure it exposes can be called by anyone. This is especially dangerous when combined with components that rely on the auth component as their sole access gate (such as authority-controlled setters), which then become permissionless as well. Higher-level factory functions vet these combinations; when building an account directly, the caller is responsible for pairing a suitable auth component with the account’s other components.
Under the testing feature, it is possible to:
- Build an existing account using
AccountBuilder::build_existing, which will set the account’s nonce to1by default, or to the configured value. - Add assets to the account’s vault; this only succeeds when using
AccountBuilder::build_existing.
Account Procedure Order
Note that the procedure in each components code are merged together in the same order as
with_component is called, except for the auth component. The auth procedure is always moved to
the first position, since the tx kernel assume procedure index 0 is the auth procedure within an
AccountCode.
Implementations§
Source§impl AccountBuilder
impl AccountBuilder
Sourcepub fn new(init_seed: [u8; 32]) -> Self
pub fn new(init_seed: [u8; 32]) -> Self
Creates a new builder for an account and sets the initial seed from which the grinding
process for that account’s AccountId will start.
This initial seed should come from a cryptographic random number generator.
Sourcepub fn version(self, version: AccountIdVersion) -> Self
pub fn version(self, version: AccountIdVersion) -> Self
Sets the AccountIdVersion of the account ID.
Sourcepub fn account_type(self, account_type: AccountType) -> Self
pub fn account_type(self, account_type: AccountType) -> Self
Sets the account type of the account.
Sourcepub fn with_asset_callbacks(self, asset_callbacks: AssetCallbackFlag) -> Self
pub fn with_asset_callbacks(self, asset_callbacks: AssetCallbackFlag) -> Self
Sets the immutable AssetCallbackFlag of the account.
This determines whether assets issued by the account (if any) trigger callbacks. It must be
set to AssetCallbackFlag::Enabled for faucets that configure a transfer policy, and
is encoded into the resulting AccountId at creation. Defaults to
AssetCallbackFlag::Disabled.
Sourcepub fn with_component(
self,
account_component: impl Into<AccountComponent>,
) -> Self
pub fn with_component( self, account_component: impl Into<AccountComponent>, ) -> Self
Adds an AccountComponent to the builder. This method can be called multiple times and
must be called at least once since an account must export at least one procedure.
All components will be merged to form the final code and storage of the built account.
Exactly one of the added components must be an authentication component (see
AccountComponent::is_auth_component); it is identified and moved to the front of the
procedure list automatically when Self::build is called.
For composite configurations that expand into multiple components (such as
AccessControl or TokenPolicyManager), use Self::with_components.
Sourcepub fn with_components(
self,
components: impl IntoIterator<Item = impl Into<AccountComponent>>,
) -> Self
pub fn with_components( self, components: impl IntoIterator<Item = impl Into<AccountComponent>>, ) -> Self
Adds the components yielded by components to the builder.
This is a convenience wrapper around repeated Self::with_component calls. It is
most useful for installing the variable number of components produced by composite
configurations whose component count is not known at the call site (for example, a
configuration value that expands into one or several components depending on its
variant).
Sourcepub fn storage_schemas(&self) -> impl Iterator<Item = &StorageSchema> + '_
pub fn storage_schemas(&self) -> impl Iterator<Item = &StorageSchema> + '_
Returns an iterator of storage schemas attached to the builder’s components.
Sourcepub fn build(self) -> Result<Account, AccountError>
pub fn build(self) -> Result<Account, AccountError>
Builds an Account out of the configured builder.
§Errors
Returns an error if:
- The init seed is not set.
- The number of procedures in all merged components is 0 or exceeds
AccountCode::MAX_NUM_PROCEDURES. - Two or more packages export a procedure with the same MAST root.
- Authentication component is missing.
- Multiple authentication procedures are found.
- The number of
StorageSlots of all components exceeds 255. MastForest::mergefails on the given components.- If duplicate assets were added to the builder (only under the
testingfeature). - If the vault is not empty on new accounts (only under the
testingfeature).
Trait Implementations§
Source§impl Clone for AccountBuilder
impl Clone for AccountBuilder
Source§fn clone(&self) -> AccountBuilder
fn clone(&self) -> AccountBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for AccountBuilder
impl RefUnwindSafe for AccountBuilder
impl Send for AccountBuilder
impl Sync for AccountBuilder
impl Unpin for AccountBuilder
impl UnsafeUnpin for AccountBuilder
impl UnwindSafe for AccountBuilder
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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