Trait DispatchableMessageInfo
pub trait DispatchableMessageInfo<const ID: u32> {
type Input;
type Output;
type Storage;
const CALLABLE: fn(_: &mut Self::Storage, _: Self::Input) -> Self::Output;
const MUTATES: bool;
const PAYABLE: bool;
const SELECTOR: [u8; 4];
const LABEL: &'static str;
}
Expand description
Stores various information of the respective dispatchable ink! message.
§Note
This trait is implemented by ink! for every dispatchable ink! message
of the root ink! smart contract. The ID
used in the trait reflects the
chosen or derived selector of the dispatchable ink! message.
§Usage
#[ink::contract]
pub mod contract {
#[ink(storage)]
pub struct Contract {}
impl Contract {
#[ink(constructor)]
pub fn constructor() -> Self {
Contract {}
}
#[ink(message)]
pub fn message1(&self) {}
#[ink(message, payable, selector = 0xC0DECAFE)]
pub fn message2(&mut self, input1: i32, input2: i64) -> (bool, i32) {
unimplemented!()
}
}
}
use contract::Contract;
/// Asserts that the message with the selector `ID` has the following properties.
///
/// # Note
///
/// The `In` and `Out` generic parameters describe the input and output types.
fn assert_message_info<In, Out, const ID: u32>(
mutates: bool,
payable: bool,
selector: [u8; 4],
label: &str,
) where
Contract: DispatchableMessageInfo<{ ID }, Input = In, Output = Out>,
{
assert_eq!(
<Contract as DispatchableMessageInfo<{ ID }>>::MUTATES,
mutates
);
assert_eq!(
<Contract as DispatchableMessageInfo<{ ID }>>::PAYABLE,
payable
);
assert_eq!(
<Contract as DispatchableMessageInfo<{ ID }>>::SELECTOR,
selector,
);
assert_eq!(<Contract as DispatchableMessageInfo<{ ID }>>::LABEL, label,);
}
fn main() {
assert_message_info::<(), (), { selector_id!("message1") }>(
false,
false,
selector_bytes!("message1"),
"message1",
);
assert_message_info::<(i32, i64), (bool, i32), 0xC0DECAFE_u32>(
true,
true,
[0xC0, 0xDE, 0xCA, 0xFE],
"message2",
);
}
Required Associated Constants§
const CALLABLE: fn(_: &mut Self::Storage, _: Self::Input) -> Self::Output
const CALLABLE: fn(_: &mut Self::Storage, _: Self::Input) -> Self::Output
The closure that can be used to dispatch into the dispatchable ink! message.
§Note
We unify &self
and &mut self
ink! messages here and always take a &mut self
.
This is mainly done for simplification but also because we can easily convert from
&mut self
to &self
with our current dispatch codegen architecture.
Required Associated Types§
type Input
type Input
Reflects the input types of the dispatchable ink! message.
type Output
type Output
Reflects the output type of the dispatchable ink! message.
type Storage
type Storage
The ink! storage struct type.
Object Safety§
This trait is not object safe.