This is the message defination lib for the protocol stack in ink!.
- Put
Payload = { git = "https://github.com/dantenetwork/message_ink", branch = "main" }in yourCargo.tomlof your contract project. Or clone it from "https://github.com/dantenetwork/message_ink" and substitute with your related local path.
The interaction message between ink! smart contract and others(deployed on other chains) are expressed as MessagePayload, which is composited with a vector of MessageItem. The core part of MessageItem is MsgDetail, which defines almost every useful types.
A convenient way to Build a MsgDetail is as follows:
- The trait InMsgType is defined to create an instance of
MsgDetailfrom a normal type and decode out a normal type fromMsgDetail.
pub trait InMsgType {
type MyType;
fn get_value(type_value: & MsgDetail) -> Option<Self::MyType>;
fn create_message(msg_detail: Self::MyType) -> MsgDetail;
}- As enum variants are not
types, we provide an implementation of every type defined inMsgDetailseparately.
In addition, with the help of InMsgType for MsgDetail, MessageItem can be directly decoded into a normal type with x.in_to(), in which x is an instance of MessageItem.
That's the main interface of the message protocol for ink! smart contracts, that is very easy to use.
