ink_env::reflect

Trait DispatchableConstructorInfo

pub trait DispatchableConstructorInfo<const ID: u32> {
    type Input;
    type Storage;
    type Output;
    type Error;

    const IS_RESULT: bool;
    const CALLABLE: fn(_: Self::Input) -> Self::Output;
    const PAYABLE: bool;
    const SELECTOR: [u8; 4];
    const LABEL: &'static str;
}
Expand description

Stores various information of the respective dispatchable ink! constructor.

§Note

This trait is implemented by ink! for every dispatchable ink! constructor of the root ink! smart contract. The ID used in the trait reflects the chosen or derived selector of the dispatchable ink! constructor.

§Usage


#[ink::contract]
pub mod contract {
    #[ink(storage)]
    pub struct Contract {}

    impl Contract {
        #[ink(constructor)]
        pub fn constructor1() -> Self {
            Contract {}
        }

        #[ink(constructor, selector = 0xC0DECAFE)]
        pub fn constructor2(input1: i32, input2: i64) -> Self {
            Contract {}
        }

        #[ink(message)]
        pub fn message(&self) {}
    }
}

use contract::Contract;

/// Asserts that the constructor with the selector `ID` has the following properties.
///
/// # Note
///
/// The `In` and `Out` generic parameters describe the input and output types.
fn assert_constructor_info<In, const ID: u32>(selector: [u8; 4], label: &str)
where
    Contract: DispatchableConstructorInfo<{ ID }, Input = In>,
{
    assert_eq!(
        <Contract as DispatchableConstructorInfo<{ ID }>>::SELECTOR,
        selector,
    );
    assert_eq!(
        <Contract as DispatchableConstructorInfo<{ ID }>>::LABEL,
        label,
    );
}

fn main() {
    assert_constructor_info::<(), { selector_id!("constructor1") }>(
        selector_bytes!("constructor1"),
        "constructor1",
    );
    assert_constructor_info::<(i32, i64), 0xC0DECAFE_u32>(
        [0xC0, 0xDE, 0xCA, 0xFE],
        "constructor2",
    );
}

Required Associated Constants§

const IS_RESULT: bool

True if the constructor returns a Result.

const CALLABLE: fn(_: Self::Input) -> Self::Output

The closure that can be used to dispatch into the dispatchable ink! constructor.

const PAYABLE: bool

Yields true if the dispatchable ink! constructor is payable.

const SELECTOR: [u8; 4]

The selectors of the dispatchable ink! constructor.

const LABEL: &'static str

The label of the dispatchable ink! constructor.

Required Associated Types§

type Input

Reflects the input types of the dispatchable ink! constructor.

type Storage

The ink! storage struct type.

type Output

Reflects the output type of the dispatchable ink! constructor.

type Error

The type of the error returned from the constructor. Infallible constructors will have () as the error type.

Object Safety§

This trait is not object safe.

Implementors§