pub struct Selector { /* private fields */ }
Expand description

The selector of an ink! dispatchable.

Note

This is equal to the first four bytes of the SHA-3 hash of a function’s name.

Implementations

Computes the BLAKE-2 256-bit based selector from the given input bytes.

Note
  • trait_prefix is None when computing the selector of ink! constructors and messages in inherent implementation blocks.
  • trait_prefix is Some when computing the selector of ink! constructors and messages in trait implementation blocks. In this case the namespace is either the full path of the trait definition gained by Rust’s module_path! macro by default or it is customized by manual application of the #[ink(namespace = "my_namespace")] ink! attribute. In the example my_namespace concatenated with :: and the identifier of the trait definition would then be part of the provided trait_prefix parameter.
  • fn_ident refers to the ink! constructor or message identifier.
Inherent Implementation Blocks

For inherent implementation blocks, when trait_prefix is None the composed selector is computed as follows:

  1. Apply BLAKE2 256-bit hash H on the bytes of the ASCII representation of the fn_ident identifier.
  2. The first 4 bytes of H make up the selector.
Trait Implementation Blocks

For trait implementation blocks, when trait_prefix is Some((namespace, trait_ident)) the composed selector is computed as follows:

  1. Compute the ASCII byte representation of fn_ident and call it F.
  2. Compute the ASCII byte representation of namespace and call it N.
  3. Compute the ASCII byte representation of trait_ident and call it T.
  4. Concatenate N, T and F using :: as separator and call it C.
  5. Apply the BLAKE2 256-bit hash H of C.
  6. The first 4 bytes of H make up the selector.

Returns the underlying four bytes.

Returns the big-endian u32 representation of the selector bytes.

Returns the 4 bytes that make up the selector as hex encoded bytes.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.