Skip to main content

Keypath

Struct Keypath 

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

Path identifying a storage slot.

A keypath is a sequence of length-framed components absorbed into one of the VM’s incremental hash streams. Each call to child appends CXS(byte_len) ‖ CXS(value): the component value CXS-encoded, prefixed by the CXS-encoded byte length of that encoding. The storage key is the SHA-256 of the concatenated frames; leaf storage cells derive it once at construction and hold it as a LeafKey.

The keypath IS its midstate: it holds the VM stream that has absorbed exactly its frames. child forks the parent’s stream — a constant-time SHA256Copy, which is what that syscall exists for — and absorbs only its own frame, so a shared parent prefix is absorbed once ever; generate_key forks once more and finalizes. No preimage bytes are kept guest-side.

The self-delimiting CXS(len) prefix makes the preimage child(v1) ‖ child(v2) ‖ … uniquely decodable: read the length, then read exactly that many value bytes. This holds for any value encoding — including fixed opaque [u8; N] keys that do not self-delimit — so distinct component sequences can never share a preimage.

Like a Hasher, a keypath is meaningful only in the current contract invocation, so it can’t be stored. Live keypaths, user hashers, and one transient per key derivation share the VM’s live-stream budget (the chain’s max_sha256_buffers network config parameter); the VM refuses streams past it and the refusing syscall’s error is thrown. A stream absorbs at most kSHA256BufferMaxSize (4096) preimage bytes, also VM-enforced. A single component’s encoding is capped at the SDK’s fixed encode-buffer size.

Implementations§

Source§

impl Keypath

Source

pub fn child<I: WriteXDR + ?Sized>(&self, value: &I) -> Keypath

Child keyed by an encodable value.

Appends CXS(byte_len) ‖ CXS(value), where CXS(value) is the value’s CXS encoding and byte_len is its byte length, also CXS-encoded (the same compact codec, so small lengths cost a single byte). The self-delimiting length prefix keeps the preimage uniquely decodable for any value bytes.

A single value’s encoding is capped at the SDK’s fixed encode-buffer size; oversized values throw LibraryExn::StorageSerialization.

Slot identity is the sequence of child values from the root: there is no per-component “structural vs. user-key” tag, so two children of the same node built from the same value address the same slot regardless of intent. SDK-generated code never mixes schemes under one node (a struct keys children by field position, a Map by user key, a Vector by region index then element index one level down), so distinct slots stay distinct. A hand-written From<Keypath> must uphold the same rule: give each child of a node a distinct value.

Source

pub fn generate_key(&self) -> StorageKey

Source

pub fn into_key(self) -> StorageKey

Consume the keypath and return its storage key, finalizing its own stream directly — no transient fork.

Source

pub fn addresses_same_slot(&self, other: &Keypath) -> bool

Whether self and other address the same storage slot.

Slot identity is the keypath preimage; SHA-256 is collision resistant, so equality of the derived keys decides it. The exclusive access-mode flag is not part of slot identity.

Source

pub fn is_exclusive(&self) -> bool

Source

pub fn set_exclusive(&mut self)

Trait Implementations§

Source§

impl Clone for Keypath

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 Keypath

Source§

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

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

impl Default for Keypath

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Keypath> for LeafKey

Source§

fn from(keypath: Keypath) -> Self

Converts to this type from the input type.
Source§

impl<T: From<Keypath>> From<Keypath> for Node<T>

Source§

fn from(keypath: Keypath) -> Self

Converts to this type from the input type.
Source§

impl From<Keypath> for Bytestring

Source§

fn from(keypath: Keypath) -> Self

Converts to this type from the input type.
Source§

impl From<Keypath> for NNInt

Source§

fn from(keypath: Keypath) -> Self

Converts to this type from the input type.
Source§

impl From<Keypath> for Balance

Source§

fn from(keypath: Keypath) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Keypath> for RCQ<T>

Source§

fn from(keypath: Keypath) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Keypath> for Value<T>

Source§

fn from(keypath: Keypath) -> Self

Converts to this type from the input type.
Source§

impl From<Keypath> for CapacityConstraint

Source§

fn from(keypath: Keypath) -> Self

Converts to this type from the input type.
Source§

impl<K, V> From<Keypath> for Map<K, V>

Source§

fn from(keypath: Keypath) -> Self

Converts to this type from the input type.
Source§

impl<S> From<Keypath> for Vector<S>

Source§

fn from(keypath: Keypath) -> Self

Converts to this type from the input type.
Source§

impl<S, const N: usize> From<Keypath> for Array<S, N>

Source§

fn from(keypath: Keypath) -> Self

Converts to this type from the input type.

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<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<T> ContractState for T
where T: From<Keypath>,

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> StaticIfNoAlloc for T

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.