#[repr(u8)]pub enum ContractMetadataKind {
Show 17 variants
Contract = 0,
Trait = 1,
Init = 2,
UpdateStateless = 3,
UpdateStatefulRo = 4,
UpdateStatefulRw = 5,
ViewStateless = 6,
ViewStateful = 7,
EnvRo = 8,
EnvRw = 9,
TmpRo = 10,
TmpRw = 11,
SlotRo = 12,
SlotRw = 13,
Input = 14,
Output = 15,
Return = 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 as follows:
- Encoding of the state type as described in
IoTypeMetadataKind - Encoding of the
#[slot]type as described inIoTypeMetadataKind - Encoding of the
#[tmp]type as described inIoTypeMetadataKind - Number of methods (u8)
- Recursive metadata of methods as defined in one of:
Trait = 1
Trait metadata.
Traits are encoded as follows:
- Length of trait name in bytes (u8)
- Trait name as UTF-8 bytes
- Number of methods (u8)
- Recursive metadata of methods as defined in one of:
Init = 2
#[init] method.
Initializers are encoded as follows:
- Length of method name in bytes (u8)
- Method name as UTF-8 bytes
- Number of named arguments (u8, excluding state argument
&selfor&mut self, but including return type that is not()orResult<(), ContactError>)
Each argument is encoded as follows:
- Argument type as u8, one of:
Self::EnvRoSelf::EnvRwSelf::TmpRoSelf::TmpRwSelf::SlotRoSelf::SlotRwSelf::InputSelf::OutputSelf::Return(yes, this is considered to be an argument)
- Length of the argument name in bytes (u8, except for
Self::EnvRoandSelf::EnvRw) - Argument name as UTF-8 bytes (except for
Self::EnvRoandSelf::EnvRw) - Only for
Self::InputandSelf::Outputrecursive metadata of argument’s type as described inIoTypeMetadataKindwith the following exception:- For last
Self::OutputorSelf::Returnthis is skipped if the method isSelf::Initsince it is statically known to beSelfand present otherwise
- For last
NOTE: Self::Return is encoded as a separate argument and counts towards the 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.
ViewStateful = 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
Explicit #[output] argument.
NOTE: Skipped if return type’s T is ().
Example: #[output] out: &mut VariableBytes<1024>,
Return = 16
T of Result<T, ContractError> return type or simply return type if it is not fallible.
NOTE: Skipped if return type’s T is ().
Example: -> Balance
Implementations§
Source§impl ContractMetadataKind
impl ContractMetadataKind
Sourcepub const fn try_from_u8(byte: u8) -> Option<Self>
pub const fn try_from_u8(byte: u8) -> Option<Self>
Try to create an instance from its u8 representation
Sourcepub const fn compact(metadata: &[u8]) -> Option<([u8; 8192], usize)>
pub const fn compact(metadata: &[u8]) -> Option<([u8; 8192], usize)>
Produce compact metadata.
Compact metadata retains the shape but throws some details. Specifically, the 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
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 (though Self::compact_external_args() is used by it internally).
Returns None if the input is invalid or too long.
Sourcepub const fn compact_external_args(
metadata: &[u8],
) -> Option<([u8; 8192], usize)>
pub const fn compact_external_args( metadata: &[u8], ) -> Option<([u8; 8192], usize)>
Produce compact metadata for ExternalArgs.
Similar to Self::compact(), but arguments that are not reflected in ExternalArgs will
be skipped since they don’t impact ExternalArgs API. This is used for
MethodFingerprint derivation.
Returns None if the input is invalid or too long.
Trait Implementations§
Source§impl Clone for ContractMetadataKind
impl Clone for ContractMetadataKind
Source§fn clone(&self) -> ContractMetadataKind
fn clone(&self) -> ContractMetadataKind
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ContractMetadataKind
impl Debug for ContractMetadataKind
Source§impl PartialEq for ContractMetadataKind
impl PartialEq for ContractMetadataKind
impl Copy for ContractMetadataKind
impl Eq for ContractMetadataKind
impl StructuralPartialEq for ContractMetadataKind
Auto Trait Implementations§
impl Freeze for ContractMetadataKind
impl RefUnwindSafe for ContractMetadataKind
impl Send for ContractMetadataKind
impl Sync for ContractMetadataKind
impl Unpin for ContractMetadataKind
impl UnwindSafe for ContractMetadataKind
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<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 more