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

    const CALLABLE: fn(_: Self::Input) -> Self::Storage;
    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

use ink_lang as ink;

#[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 Types

Reflects the input types of the dispatchable ink! constructor.

The ink! storage struct type.

Required Associated Constants

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

Yields true if the dispatchable ink! constructor is payable.

The selectors of the dispatchable ink! constructor.

The label of the dispatchable ink! constructor.

Implementors