Skip to main content

AccountPatch

Struct AccountPatch 

Source
pub struct AccountPatch { /* private fields */ }
Expand description

An AccountPatch describes the new absolute state of an account after one or more transactions, in contrast to an AccountDelta, which describes the relative change.

For example, where a delta might say “remove 50 USDC from the vault”, a patch says “the new USDC balance is 100”. This means a patch can be applied to compute the new account state without loading the previous state and without invoking any custom asset compose logic (e.g. merge/split procedures defined by the issuing faucet).

The patch represents updates to the account as follows:

  • storage: an AccountStoragePatch containing the new values of changed storage slots and map entries. Storage updates are already absolute per changed entry, so no dedicated patch type is required for storage.
  • vault: an AccountVaultPatch containing the new values of changed vault entries.
  • nonce: the new (absolute) nonce of the account, in contrast to AccountDelta::nonce_delta which stores the increment.
  • code: an AccountCodePatch containing the code of a new or upgraded account.

Implementations§

Source§

impl AccountPatch

Source

pub fn new( account_id: AccountId, storage: AccountStoragePatch, vault: AccountVaultPatch, code: AccountCodePatch, final_nonce: Option<Felt>, ) -> Result<Self, AccountPatchError>

Returns a new AccountPatch instantiated from the provided components.

final_nonce must be Some(non_zero_nonce) if storage, vault or code contain any updates, and can be None only for empty patches.

§Errors

Returns an error if:

  • final_nonce is Some(Felt::ZERO). The tx kernel guarantees that an updated nonce is at least one, so a zero nonce is never a valid post-tx-state. Empty patches must be constructed with None instead.
  • storage or vault contain updates or code is present but final_nonce is None. The tx kernel mandates that the nonce is incremented whenever account state changes.
  • final_nonce is 1 but code is not Some. Such a patch describes a new account and should be convertible into a full Account, so account code is required.
Source

pub fn empty(account_id: AccountId) -> Self

Returns an empty patch for the provided account ID.

Source

pub fn merge(&mut self, other: Self) -> Result<(), AccountPatchError>

Merges the other AccountPatch into this one with patch semantics: entries present in other overwrite their counterparts in self, and other.final_nonce, if present, becomes the new final nonce.

The merge is not commutative: self must describe the earlier and other the later state, so a.merge(b) and b.merge(a) generally give different results.

Both patches must apply to the same account, and other.final_nonce must be greater than self.final_nonce whenever both are set. other can be an aggregate of multiple transactions (e.g. of a batch), so the nonce can grow by more than one. Continuity of the merged patches is not and cannot be checked here.

If other carries code, it replaces the code of self, since other describes the later state.

Empty patches are neutral: merging into an empty self adopts other, and merging an empty other is a no-op.

§Errors

Returns an error if:

  • the two patches apply to different accounts.
  • both patches carry a final nonce and the nonce in other is not greater than the nonce in self.
  • a storage slot is used as different slot types in the two patches.
Source

pub fn id(&self) -> AccountId

Returns the account ID to which this patch applies.

Source

pub fn storage(&self) -> &AccountStoragePatch

Returns the storage updates of this patch.

Source

pub fn vault(&self) -> &AccountVaultPatch

Returns the vault updates of this patch.

Source

pub fn code(&self) -> &AccountCodePatch

Returns the code updates of this patch.

Source

pub fn final_nonce(&self) -> Option<Felt>

Returns the new (absolute) nonce of the account after this patch is applied, or None if the nonce wasn’t updated.

Source

pub fn is_empty(&self) -> bool

Returns true if this account patch does not contain any vault, storage or code updates and the nonce wasn’t updated.

Source

pub fn to_commitment(&self) -> Word

Computes the commitment to the account patch.

This is very similar to AccountDelta::to_commitment. See its docs for the rationale, security aspects, and other details. The only differences between these are:

  • the patch includes the new nonce rather than the nonce delta.
  • The patch includes the new absolute asset values (AccountVaultPatch) while the delta includes the relative asset changes (AccountVaultDelta).
§Computation

The patch commitment is a sequential hash over a vector of field elements which starts out empty and is appended to in the following way. If no asset, storage or code elements were appended, the commitment is defined as the empty word. Whenever sorting is expected, it is that of a Word. The hash is domain-separated by the patch’s DOMAIN, which is placed in the capacity word of the hasher. This is what distinguishes a patch commitment from a delta commitment, whose headers are otherwise identically shaped.

  • Append [[version = 1, final_nonce, account_id_suffix, account_id_prefix], EMPTY_WORD], where account_id_{prefix,suffix} are the prefix and suffix felts of the native account id, final_nonce is the new nonce of the account, and version is the version of this layout.
  • Asset Patch
    • For each asset whose value has changed compared to the initial state of the transaction, including if it was removed, sorted by its asset ID:
      • Append [ASSET_ID, ASSET_VALUE_OR_EMPTY_WORD] which are the key and either the value of the asset (for updates) or the empty word (for removals).
      • Append [[domain = 1, num_changed_assets, 0, 0], 0, 0, 0, 0], where num_changed_assets is the number of assets that were appended. This is the same domain as the delta asset section uses, since the capacity domain already prevents an asset delta and an asset patch from producing the same commitment.
  • Storage Slots are sorted by slot ID and are iterated in this order. patch_op is the StoragePatchOperation of the slot patch and slot_id_{suffix, prefix} is the identifier of the slot. For each slot, depending on its slot type:
    • Value Slot
      • Append [[domain = 2, patch_op, slot_id_suffix, slot_id_prefix], NEW_VALUE] where NEW_VALUE is the new value of the slot.
    • Map Slot
      • For each key-value pair, sorted by key, whose new value is different from the previous value in the map:
        • Append [KEY, NEW_VALUE].
      • The map trailer is constructed as [[domain = 3, patch_op, slot_id_suffix, slot_id_prefix], [num_changed_entries, 0, 0, 0]], where num_changed_entries is the number of key-value pairs appended above. Whether the trailer is included depends on patch_op:
        • For StoragePatchOperation::Create, the trailer is always included, since the slot’s creation must be committed to even when the map is created empty (num_changed_entries == 0).
        • For StoragePatchOperation::Update, the trailer is included only if num_changed_entries != 0. An update that changes no entries is a no-op and is omitted entirely.
        • For StoragePatchOperation::Remove, the trailer is always included with num_changed_entries set to zero, since the number of removed entries is unknown.
  • If the account is new or its code was upgraded, append [[domain = 4, 0, 0, 0], CODE_COMMITMENT], where CODE_COMMITMENT is the commitment of the account code.

Headers for storage map slots and asset patches are appended rather than prepended since the tx kernel cannot efficiently get the number of changed entries before the iteration.

Source

pub fn try_to_new_account(&self) -> Result<Account, AccountError>

Returns the new Account created by this patch.

Conceptually, this applies the patch onto an empty account.

§Warning

This method only results in a semantically correct account if the caller knows that the patch is from an account-creating transaction itself or resulted from merging patches onto the account-creating patch. The method can also succeed on patches coming from code-upgrading transactions, but the result will not correspond to a meaningful account state. Prefer applying the patch onto the new account against which the account-creating transaction was executed.

§Errors

Returns an error if:

  • the patch does not carry account code or a final nonce.
  • the storage patch contains an Update or Remove operation, which cannot be applied to the empty storage of a new account.
  • applying the vault patch to an empty vault fails.
  • applying the storage patch to empty storage fails.
  • Account::new fails on the resulting components.

Trait Implementations§

Source§

impl Clone for AccountPatch

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AccountPatch

Source§

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

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

impl Deserializable for AccountPatch

Source§

fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>

Reads a sequence of bytes from the provided source, attempts to deserialize these bytes into Self, and returns the result. Read more
Source§

fn min_serialized_size() -> usize

Returns the minimum serialized size for one instance of this type. Read more
Source§

fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>

Attempts to deserialize the provided bytes into Self and returns the result. Read more
Source§

fn read_from_bytes_with_budget( bytes: &[u8], budget: usize, ) -> Result<Self, DeserializationError>

Deserializes Self from bytes with a byte budget limit. Read more
Source§

impl Eq for AccountPatch

Source§

impl PartialEq for AccountPatch

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl SequentialCommit for AccountPatch

Source§

fn to_commitment(&self) -> Word

Computes the commitment to the patch, domain-separated by its DOMAIN.

See AccountPatch::to_commitment() for more details.

Source§

fn to_elements(&self) -> Vec<Felt>

Reduces the patch to a sequence of field elements.

See AccountPatch::to_commitment() for more details.

Source§

type Commitment = Word

A type of the commitment which must be derivable from Word.
Source§

impl Serializable for AccountPatch

Source§

fn write_into<W: ByteWriter>(&self, target: &mut W)

Serializes self into bytes and writes these bytes into the target.
Source§

fn get_size_hint(&self) -> usize

Returns an estimate of how many bytes are needed to represent self. Read more
Source§

fn to_bytes(&self) -> Vec<u8> ⓘ

Serializes self into a vector of bytes.
Source§

impl StructuralPartialEq for AccountPatch

Source§

impl TryFrom<Account> for AccountPatch

Source§

fn try_from(account: Account) -> Result<Self, Self::Error>

Converts an Account into an AccountPatch.

§Errors

Returns an error if:

  • the account has a seed. Accounts with seeds have a nonce of 0. Representing such accounts as patches is not possible because patches with a non-empty state change need a final_nonce greater than 0.
Source§

type Error = AccountError

The type returned in the event of a conversion error.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more