Trait SolTypeEncode

Source
pub trait SolTypeEncode: SolTokenType + Sealed {
    type AlloyType: AlloySolType;

    const DEFAULT_VALUE: Self::DefaultType;

    // Required method
    fn tokenize(&self) -> Self::TokenType<'_>;

    // Provided method
    fn encode(&self) -> Vec<u8>  { ... }
}
Expand description

A Rust/ink! equivalent of a Solidity ABI type that implements logic for Solidity ABI encoding.

§Rust/ink! to Solidity ABI type mapping

Rust/ink! typeSolidity ABI typeNotes
boolbool
iN for N ∈ {8,16,32,64,128}intNe.g i8int8
uN for N ∈ {8,16,32,64,128}uintNe.g u8uint8
U256uint256
Stringstring
Box<str>string
Address / H160addressAddress is a type alias for the H160 type used for addresses in pallet-revive
[T; N] for const N: usizeT[N]e.g. [i8; 64]int8[64]
Vec<T>T[]e.g. Vec<i8>int8[]
Box<[T]>T[]e.g. Box<[i8]>int8[]
SolBytes<u8>bytes1
SolBytes<[u8; N]> for 1 <= N <= 32bytesNe.g. SolBytes<[u8; 32]>bytes32
SolBytes<Vec<u8>>bytes
SolBytes<Box<[u8]>>bytes
(T1, T2, T3, ... T12)(U1, U2, U3, ... U12)where T1U1, … T12U12 e.g. (bool, u8, Address)(bool, uint8, address)
&str, &mut strstring
&T, &mut T, Box<T>Te.g. &i8 ↔ int8
&[T], &mut [T]T[]e.g. &[i8]int8[]

Ref: https://docs.soliditylang.org/en/latest/abi-spec.html#types

§Note

This trait is sealed and cannot be implemented for types outside ink_primitives.

Required Associated Constants§

Source

const DEFAULT_VALUE: Self::DefaultType

An encodable representation of the default value for this type.

Required Associated Types§

Source

type AlloyType: AlloySolType

Equivalent Solidity ABI type from [alloy_sol_types].

Required Methods§

Source

fn tokenize(&self) -> Self::TokenType<'_>

Tokenizes the given value into a Self::AlloyType token.

Provided Methods§

Source

fn encode(&self) -> Vec<u8>

Solidity ABI encode the value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl SolTypeEncode for &str

Source§

const DEFAULT_VALUE: Self::DefaultType = DynSizeDefault

Source§

type AlloyType = String

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for &mut str

Source§

const DEFAULT_VALUE: Self::DefaultType = DynSizeDefault

Source§

type AlloyType = String

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for Cow<'_, str>

Source§

const DEFAULT_VALUE: Self::DefaultType = DynSizeDefault

Source§

type AlloyType = String

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for bool

Source§

const DEFAULT_VALUE: Self::DefaultType = {transmute(0x0000000000000001): <bool as sol::types::SolTokenType>::DefaultType}

Source§

type AlloyType = Bool

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for i8

Source§

const DEFAULT_VALUE: Self::DefaultType = {transmute(0x0000000000000001): <i8 as sol::types::SolTokenType>::DefaultType}

Source§

type AlloyType = Int<8>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for i16

Source§

const DEFAULT_VALUE: Self::DefaultType = {transmute(0x0000000000000001): <i16 as sol::types::SolTokenType>::DefaultType}

Source§

type AlloyType = Int<16>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for i32

Source§

const DEFAULT_VALUE: Self::DefaultType = {transmute(0x0000000000000001): <i32 as sol::types::SolTokenType>::DefaultType}

Source§

type AlloyType = Int<32>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for i64

Source§

const DEFAULT_VALUE: Self::DefaultType = {transmute(0x0000000000000001): <i64 as sol::types::SolTokenType>::DefaultType}

Source§

type AlloyType = Int<64>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for i128

Source§

const DEFAULT_VALUE: Self::DefaultType = {transmute(0x0000000000000001): <i128 as sol::types::SolTokenType>::DefaultType}

Source§

type AlloyType = Int<128>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for u8

Source§

const DEFAULT_VALUE: Self::DefaultType = {transmute(0x0000000000000001): <u8 as sol::types::SolTokenType>::DefaultType}

Source§

type AlloyType = Uint<8>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for u16

Source§

const DEFAULT_VALUE: Self::DefaultType = {transmute(0x0000000000000001): <u16 as sol::types::SolTokenType>::DefaultType}

Source§

type AlloyType = Uint<16>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for u32

Source§

const DEFAULT_VALUE: Self::DefaultType = {transmute(0x0000000000000001): <u32 as sol::types::SolTokenType>::DefaultType}

Source§

type AlloyType = Uint<32>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for u64

Source§

const DEFAULT_VALUE: Self::DefaultType = {transmute(0x0000000000000001): <u64 as sol::types::SolTokenType>::DefaultType}

Source§

type AlloyType = Uint<64>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for u128

Source§

const DEFAULT_VALUE: Self::DefaultType = {transmute(0x0000000000000001): <u128 as sol::types::SolTokenType>::DefaultType}

Source§

type AlloyType = Uint<128>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for ()

Source§

const DEFAULT_VALUE: Self::DefaultType = ()

Source§

type AlloyType = ()

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for Box<str>

Source§

const DEFAULT_VALUE: Self::DefaultType = DynSizeDefault

Source§

type AlloyType = String

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl SolTypeEncode for String

Source§

const DEFAULT_VALUE: Self::DefaultType = DynSizeDefault

Source§

type AlloyType = String

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<T> SolTypeEncode for Cow<'_, [T]>

Source§

const DEFAULT_VALUE: Self::DefaultType = DynSizeDefault

Source§

type AlloyType = Array<<T as SolTypeEncode>::AlloyType>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<T> SolTypeEncode for Option<T>
where T: SolTypeEncode,

Source§

const DEFAULT_VALUE: Self::DefaultType

Source§

type AlloyType = (Bool, <T as SolTypeEncode>::AlloyType)

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<T: SolTypeEncode + Clone> SolTypeEncode for Cow<'_, T>

Source§

const DEFAULT_VALUE: Self::DefaultType = T::DEFAULT_VALUE

Source§

type AlloyType = <T as SolTypeEncode>::AlloyType

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<T: SolTypeEncode> SolTypeEncode for &[T]

Source§

const DEFAULT_VALUE: Self::DefaultType = DynSizeDefault

Source§

type AlloyType = Array<<T as SolTypeEncode>::AlloyType>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<T: SolTypeEncode> SolTypeEncode for &mut [T]

Source§

const DEFAULT_VALUE: Self::DefaultType = DynSizeDefault

Source§

type AlloyType = Array<<T as SolTypeEncode>::AlloyType>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<T: SolTypeEncode> SolTypeEncode for &T

Source§

const DEFAULT_VALUE: Self::DefaultType = T::DEFAULT_VALUE

Source§

type AlloyType = <T as SolTypeEncode>::AlloyType

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<T: SolTypeEncode> SolTypeEncode for &mut T

Source§

const DEFAULT_VALUE: Self::DefaultType = T::DEFAULT_VALUE

Source§

type AlloyType = <T as SolTypeEncode>::AlloyType

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<T: SolTypeEncode> SolTypeEncode for Box<[T]>

Source§

const DEFAULT_VALUE: Self::DefaultType = DynSizeDefault

Source§

type AlloyType = Array<<T as SolTypeEncode>::AlloyType>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<T: SolTypeEncode> SolTypeEncode for Box<T>

Source§

const DEFAULT_VALUE: Self::DefaultType = T::DEFAULT_VALUE

Source§

type AlloyType = <T as SolTypeEncode>::AlloyType

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<T: SolTypeEncode> SolTypeEncode for Vec<T>

Source§

const DEFAULT_VALUE: Self::DefaultType = DynSizeDefault

Source§

type AlloyType = Array<<T as SolTypeEncode>::AlloyType>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<T: SolTypeEncode, const N: usize> SolTypeEncode for [T; N]

Source§

const DEFAULT_VALUE: Self::DefaultType

Source§

type AlloyType = FixedArray<<T as SolTypeEncode>::AlloyType, N>

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<TupleElement0: SolTypeEncode> SolTypeEncode for (TupleElement0,)

Source§

const DEFAULT_VALUE: Self::DefaultType

Source§

type AlloyType = (<TupleElement0 as SolTypeEncode>::AlloyType,)

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<TupleElement0: SolTypeEncode, TupleElement1: SolTypeEncode> SolTypeEncode for (TupleElement0, TupleElement1)

Source§

const DEFAULT_VALUE: Self::DefaultType

Source§

type AlloyType = (<TupleElement0 as SolTypeEncode>::AlloyType, <TupleElement1 as SolTypeEncode>::AlloyType)

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<TupleElement0: SolTypeEncode, TupleElement1: SolTypeEncode, TupleElement2: SolTypeEncode> SolTypeEncode for (TupleElement0, TupleElement1, TupleElement2)

Source§

const DEFAULT_VALUE: Self::DefaultType

Source§

type AlloyType = (<TupleElement0 as SolTypeEncode>::AlloyType, <TupleElement1 as SolTypeEncode>::AlloyType, <TupleElement2 as SolTypeEncode>::AlloyType)

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<TupleElement0: SolTypeEncode, TupleElement1: SolTypeEncode, TupleElement2: SolTypeEncode, TupleElement3: SolTypeEncode> SolTypeEncode for (TupleElement0, TupleElement1, TupleElement2, TupleElement3)

Source§

const DEFAULT_VALUE: Self::DefaultType

Source§

type AlloyType = (<TupleElement0 as SolTypeEncode>::AlloyType, <TupleElement1 as SolTypeEncode>::AlloyType, <TupleElement2 as SolTypeEncode>::AlloyType, <TupleElement3 as SolTypeEncode>::AlloyType)

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<TupleElement0: SolTypeEncode, TupleElement1: SolTypeEncode, TupleElement2: SolTypeEncode, TupleElement3: SolTypeEncode, TupleElement4: SolTypeEncode> SolTypeEncode for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4)

Source§

const DEFAULT_VALUE: Self::DefaultType

Source§

type AlloyType = (<TupleElement0 as SolTypeEncode>::AlloyType, <TupleElement1 as SolTypeEncode>::AlloyType, <TupleElement2 as SolTypeEncode>::AlloyType, <TupleElement3 as SolTypeEncode>::AlloyType, <TupleElement4 as SolTypeEncode>::AlloyType)

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<TupleElement0: SolTypeEncode, TupleElement1: SolTypeEncode, TupleElement2: SolTypeEncode, TupleElement3: SolTypeEncode, TupleElement4: SolTypeEncode, TupleElement5: SolTypeEncode> SolTypeEncode for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5)

Source§

const DEFAULT_VALUE: Self::DefaultType

Source§

type AlloyType = (<TupleElement0 as SolTypeEncode>::AlloyType, <TupleElement1 as SolTypeEncode>::AlloyType, <TupleElement2 as SolTypeEncode>::AlloyType, <TupleElement3 as SolTypeEncode>::AlloyType, <TupleElement4 as SolTypeEncode>::AlloyType, <TupleElement5 as SolTypeEncode>::AlloyType)

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<TupleElement0: SolTypeEncode, TupleElement1: SolTypeEncode, TupleElement2: SolTypeEncode, TupleElement3: SolTypeEncode, TupleElement4: SolTypeEncode, TupleElement5: SolTypeEncode, TupleElement6: SolTypeEncode> SolTypeEncode for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6)

Source§

const DEFAULT_VALUE: Self::DefaultType

Source§

type AlloyType = (<TupleElement0 as SolTypeEncode>::AlloyType, <TupleElement1 as SolTypeEncode>::AlloyType, <TupleElement2 as SolTypeEncode>::AlloyType, <TupleElement3 as SolTypeEncode>::AlloyType, <TupleElement4 as SolTypeEncode>::AlloyType, <TupleElement5 as SolTypeEncode>::AlloyType, <TupleElement6 as SolTypeEncode>::AlloyType)

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<TupleElement0: SolTypeEncode, TupleElement1: SolTypeEncode, TupleElement2: SolTypeEncode, TupleElement3: SolTypeEncode, TupleElement4: SolTypeEncode, TupleElement5: SolTypeEncode, TupleElement6: SolTypeEncode, TupleElement7: SolTypeEncode> SolTypeEncode for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7)

Source§

const DEFAULT_VALUE: Self::DefaultType

Source§

type AlloyType = (<TupleElement0 as SolTypeEncode>::AlloyType, <TupleElement1 as SolTypeEncode>::AlloyType, <TupleElement2 as SolTypeEncode>::AlloyType, <TupleElement3 as SolTypeEncode>::AlloyType, <TupleElement4 as SolTypeEncode>::AlloyType, <TupleElement5 as SolTypeEncode>::AlloyType, <TupleElement6 as SolTypeEncode>::AlloyType, <TupleElement7 as SolTypeEncode>::AlloyType)

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<TupleElement0: SolTypeEncode, TupleElement1: SolTypeEncode, TupleElement2: SolTypeEncode, TupleElement3: SolTypeEncode, TupleElement4: SolTypeEncode, TupleElement5: SolTypeEncode, TupleElement6: SolTypeEncode, TupleElement7: SolTypeEncode, TupleElement8: SolTypeEncode> SolTypeEncode for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7, TupleElement8)

Source§

const DEFAULT_VALUE: Self::DefaultType

Source§

type AlloyType = (<TupleElement0 as SolTypeEncode>::AlloyType, <TupleElement1 as SolTypeEncode>::AlloyType, <TupleElement2 as SolTypeEncode>::AlloyType, <TupleElement3 as SolTypeEncode>::AlloyType, <TupleElement4 as SolTypeEncode>::AlloyType, <TupleElement5 as SolTypeEncode>::AlloyType, <TupleElement6 as SolTypeEncode>::AlloyType, <TupleElement7 as SolTypeEncode>::AlloyType, <TupleElement8 as SolTypeEncode>::AlloyType)

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<TupleElement0: SolTypeEncode, TupleElement1: SolTypeEncode, TupleElement2: SolTypeEncode, TupleElement3: SolTypeEncode, TupleElement4: SolTypeEncode, TupleElement5: SolTypeEncode, TupleElement6: SolTypeEncode, TupleElement7: SolTypeEncode, TupleElement8: SolTypeEncode, TupleElement9: SolTypeEncode> SolTypeEncode for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7, TupleElement8, TupleElement9)

Source§

const DEFAULT_VALUE: Self::DefaultType

Source§

type AlloyType = (<TupleElement0 as SolTypeEncode>::AlloyType, <TupleElement1 as SolTypeEncode>::AlloyType, <TupleElement2 as SolTypeEncode>::AlloyType, <TupleElement3 as SolTypeEncode>::AlloyType, <TupleElement4 as SolTypeEncode>::AlloyType, <TupleElement5 as SolTypeEncode>::AlloyType, <TupleElement6 as SolTypeEncode>::AlloyType, <TupleElement7 as SolTypeEncode>::AlloyType, <TupleElement8 as SolTypeEncode>::AlloyType, <TupleElement9 as SolTypeEncode>::AlloyType)

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<TupleElement0: SolTypeEncode, TupleElement1: SolTypeEncode, TupleElement2: SolTypeEncode, TupleElement3: SolTypeEncode, TupleElement4: SolTypeEncode, TupleElement5: SolTypeEncode, TupleElement6: SolTypeEncode, TupleElement7: SolTypeEncode, TupleElement8: SolTypeEncode, TupleElement9: SolTypeEncode, TupleElement10: SolTypeEncode> SolTypeEncode for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7, TupleElement8, TupleElement9, TupleElement10)

Source§

const DEFAULT_VALUE: Self::DefaultType

Source§

type AlloyType = (<TupleElement0 as SolTypeEncode>::AlloyType, <TupleElement1 as SolTypeEncode>::AlloyType, <TupleElement2 as SolTypeEncode>::AlloyType, <TupleElement3 as SolTypeEncode>::AlloyType, <TupleElement4 as SolTypeEncode>::AlloyType, <TupleElement5 as SolTypeEncode>::AlloyType, <TupleElement6 as SolTypeEncode>::AlloyType, <TupleElement7 as SolTypeEncode>::AlloyType, <TupleElement8 as SolTypeEncode>::AlloyType, <TupleElement9 as SolTypeEncode>::AlloyType, <TupleElement10 as SolTypeEncode>::AlloyType)

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Source§

impl<TupleElement0: SolTypeEncode, TupleElement1: SolTypeEncode, TupleElement2: SolTypeEncode, TupleElement3: SolTypeEncode, TupleElement4: SolTypeEncode, TupleElement5: SolTypeEncode, TupleElement6: SolTypeEncode, TupleElement7: SolTypeEncode, TupleElement8: SolTypeEncode, TupleElement9: SolTypeEncode, TupleElement10: SolTypeEncode, TupleElement11: SolTypeEncode> SolTypeEncode for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7, TupleElement8, TupleElement9, TupleElement10, TupleElement11)

Source§

const DEFAULT_VALUE: Self::DefaultType

Source§

type AlloyType = (<TupleElement0 as SolTypeEncode>::AlloyType, <TupleElement1 as SolTypeEncode>::AlloyType, <TupleElement2 as SolTypeEncode>::AlloyType, <TupleElement3 as SolTypeEncode>::AlloyType, <TupleElement4 as SolTypeEncode>::AlloyType, <TupleElement5 as SolTypeEncode>::AlloyType, <TupleElement6 as SolTypeEncode>::AlloyType, <TupleElement7 as SolTypeEncode>::AlloyType, <TupleElement8 as SolTypeEncode>::AlloyType, <TupleElement9 as SolTypeEncode>::AlloyType, <TupleElement10 as SolTypeEncode>::AlloyType, <TupleElement11 as SolTypeEncode>::AlloyType)

Source§

fn tokenize(&self) -> Self::TokenType<'_>

Implementors§

Source§

impl SolTypeEncode for U256

Source§

const DEFAULT_VALUE: Self::DefaultType = {transmute(0x0000000000000001): <primitive_types::U256 as sol::types::SolTokenType>::DefaultType}

Source§

type AlloyType = Uint<256>

Source§

impl SolTypeEncode for Address

Source§

const DEFAULT_VALUE: Self::DefaultType = {transmute(0x0000000000000001): <primitive_types::H160 as sol::types::SolTokenType>::DefaultType}

Source§

type AlloyType = Address

Source§

impl<T: SolBytesType> SolTypeEncode for SolBytes<T>

Source§

const DEFAULT_VALUE: Self::DefaultType = T::DEFAULT_VALUE

Source§

type AlloyType = <T as SolBytesType>::AlloyType