#[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:
- 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 af 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 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:
- Argument type as u8, one of:
- Length of the argument name in bytes (u8, except for
Self::EnvRo
andSelf::EnvRw
) - Argument name as UTF-8 bytes (except for
Self::EnvRo
andSelf::EnvRw
) - Only for
Self::Input
,Self::Output
andSelf::Result
recursive metadata of argument’s type as described inIoTypeMetadataKind
with following exceptions:- For
Self::Result
this is skipped if method isSelf::Init
and present otherwise
- For
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
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 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
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 more