ab_contracts_common::metadata

Enum ContractMetadataKind

Source
#[repr(u8)]
pub enum ContractMetadataKind {
Show 17 variants Contract = 0, Trait = 1, Init = 2, UpdateStateless = 3, UpdateStatefulRo = 4, UpdateStatefulRw = 5, ViewStateless = 6, ViewStatefulRo = 7, EnvRo = 8, EnvRw = 9, TmpRo = 10, TmpRw = 11, SlotRo = 12, SlotRw = 13, Input = 14, Output = 15, Result = 16,
}
Expand description

Metadata for smart contact methods.

Metadata encoding consists of this enum variant treated as u8 followed by optional metadata encoding rules specific to metadata type variant (see variant’s description).

This metadata is enough to fully reconstruct the hierarchy of the type to generate language bindings, auto-generate UI forms, etc.

Variants§

§

Contract = 0

Main contract metadata.

Contracts are encoded af follows:

§

Trait = 1

Trait metadata.

Traits are encoded af follows:

§

Init = 2

#[init] method.

Initializers are encoded af follows:

  • Length of method name in bytes (u8)
  • Method name as UTF-8 bytes
  • Number of named arguments (u8, excluding state argument &self or &mut self)

Each argument is encoded as follows:

NOTE: Result, regardless of whether it is a return type or explicit #[result] argument is encoded as a separate argument and counts towards number of arguments. At the same time, self doesn’t count towards the number of arguments as it is implicitly defined by the variant of this struct.

§

UpdateStateless = 3

Stateless #[update] method (doesn’t have self in its arguments).

Encoding is the same as Self::Init.

§

UpdateStatefulRo = 4

Stateful read-only #[update] method (has &self in its arguments).

Encoding is the same as Self::Init.

§

UpdateStatefulRw = 5

Stateful read-write #[update] method (has &mut self in its arguments).

Encoding is the same as Self::Init.

§

ViewStateless = 6

Stateless #[view] method (doesn’t have self in its arguments).

Encoding is the same as Self::Init.

§

ViewStatefulRo = 7

Stateful read-only #[view] method (has &self in its arguments).

Encoding is the same as Self::Init.

§

EnvRo = 8

Read-only #[env] argument.

Example: #[env] env: &Env,

§

EnvRw = 9

Read-write #[env] argument.

Example: #[env] env: &mut Env,

§

TmpRo = 10

Read-only #[tmp] argument.

Example: #[tmp] tmp: &MaybeData<Tmp>,

§

TmpRw = 11

Read-write #[tmp] argument.

Example: #[tmp] tmp: &mut MaybeData<Tmp>,

§

SlotRo = 12

Read-only #[slot] argument with an address.

Example: #[slot] (from_address, from): (&Address, &MaybeData<Slot>),

§

SlotRw = 13

Read-write #[slot] argument with an address.

Example: #[slot] (from_address, from): (&Address, &mut MaybeData<Slot>),

§

Input = 14

#[input] argument.

Example: #[input] balance: &Balance,

§

Output = 15

#[output] argument.

Example: #[output] out: &mut VariableBytes<1024>,

§

Result = 16

Explicit #[result] argument or T of Result<T, ContractError> return type or simply return type if it is not fallible.

Example: #[result] result: &mut MaybeData<Balance>,

NOTE: There is always exactly one result in a method.

Implementations§

Source§

impl ContractMetadataKind

Source

pub const fn try_from_u8(byte: u8) -> Option<Self>

Try to create an instance from its u8 representation

Source

pub const fn compact(metadata: &[u8]) -> Option<([u8; 8192], usize)>

Produce compact metadata.

Compact metadata retains the shape, but throws some details. Specifically following transformations are applied to metadata (crucially, method names are retained!):

  • Struct, trait, enum and enum variant names removed (replaced with 0 bytes names)
  • Structs and enum variants turned into tuple variants (removing field names)
  • Method argument names removed (removing argument names)

This means that two methods with different argument names or struct field names, but the same shape otherwise are considered identical, allowing for limited future refactoring opportunities without changing compact metadata shape, which is important for MethodFingerprint.

Returns None if input is invalid or too long.

Trait Implementations§

Source§

impl Clone for ContractMetadataKind

Source§

fn clone(&self) -> ContractMetadataKind

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ContractMetadataKind

Source§

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

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

impl PartialEq for ContractMetadataKind

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ContractMetadataKind

Source§

impl Eq for ContractMetadataKind

Source§

impl StructuralPartialEq for ContractMetadataKind

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.