0xa1::message
Message
new
peel
message_to_command_id
command_id
hash
use 0x1::ascii;
use 0x1::vector;
use 0x2::bcs;
use 0x2::hash;
use 0xa1::bytes32;
Message
Types —– Cross chain message type
struct Message has copy, drop, store
source_chain: ascii::String
message_id: ascii::String
source_address: ascii::String
destination_id: address
payload_hash: bytes32::Bytes32
new
Package Functions —————–
public(friend) fun new(source_chain: ascii::String, message_id: ascii::String, source_address: ascii::String, destination_id: address, payload_hash: bytes32::Bytes32): message::Message
public(package) fun new(
source_chain: String,
message_id: String,
source_address: String,
destination_id: address,
payload_hash: Bytes32,
): Message {
Message {
source_chain,
message_id,
source_address,
destination_id,
payload_hash,
}
}
peel
public(friend) fun peel(bcs: &mut bcs::BCS): message::Message
public(package) fun peel(bcs: &mut BCS): Message {
// TODO: allow UTF-8 strings? Or keep it as more generic bytes?
let source_chain = bcs.peel_vec_u8().to_ascii_string();
let message_id = bcs.peel_vec_u8().to_ascii_string();
let source_address = bcs.peel_vec_u8().to_ascii_string();
let destination_id = bcs.peel_address();
let payload_hash = bytes32::peel(bcs);
Message {
source_chain,
message_id,
source_address,
destination_id,
payload_hash,
}
}
message_to_command_id
public(friend) fun message_to_command_id(source_chain: ascii::String, message_id: ascii::String): bytes32::Bytes32
public(package) fun message_to_command_id(
source_chain: String,
message_id: String,
): Bytes32 {
let mut id = source_chain.into_bytes();
id.append(b"_");
id.append(message_id.into_bytes());
bytes32::from_bytes(hash::keccak256(&id))
}
command_id
public(friend) fun command_id(self: &message::Message): bytes32::Bytes32
public(package) fun command_id(self: &Message): Bytes32 {
message_to_command_id(self.source_chain, self.message_id)
}
hash
public(friend) fun hash(self: &message::Message): bytes32::Bytes32
public(package) fun hash(self: &Message): Bytes32 {
bytes32::from_bytes(hash::keccak256(&bcs::to_bytes(self)))
}