Module 0xa9::gmp
use 0x1::ascii;
use 0x1::type_name;
use 0x2::address;
use 0x2::coin;
use 0x2::event;
use 0x2::hex;
use 0x2::object;
use 0x2::sui;
use 0x2::transfer;
use 0x2::tx_context;
use 0xa1::channel;
use 0xa1::gateway;
use 0xa1::message_ticket;
use 0xa2::gas_service;
use 0xa9::utils;
use 0xaa::discovery;
use 0xaa::transaction;
Resource Singleton
struct Singleton has key
Fields
-
id: object::UID
-
-
channel: channel::Channel
-
Struct Executed
struct Executed has copy, drop
Fields
-
data: vector<u8>
-
Function init
fun init(ctx: &mut tx_context::TxContext)
Implementation
fun init(ctx: &mut TxContext) {
let singletonId = object::new(ctx);
let channel = channel::new(ctx);
transfer::share_object(Singleton {
id: singletonId,
channel,
});
}
Function register_transaction
public fun register_transaction(discovery: &mut discovery::RelayerDiscovery, singleton: &gmp::Singleton)
Implementation
public fun register_transaction(
discovery: &mut RelayerDiscovery,
singleton: &Singleton,
) {
let arguments =
vector[
vector[2u8],
concat(vector[0u8], object::id_address(singleton).to_bytes()),
];
let transaction = transaction::new_transaction(
true,
vector[
transaction::new_move_call(
transaction::new_function(
address::from_bytes(
hex::decode(
*ascii::as_bytes(
&type_name::get_address(
&type_name::get<Singleton>(),
),
),
),
),
ascii::string(b"gmp"),
ascii::string(b"execute"),
),
arguments,
vector[],
),
],
);
discovery.register_transaction(&singleton.channel, transaction);
}
Function send_call
public fun send_call(singleton: &gmp::Singleton, gateway: &gateway::Gateway, gas_service: &mut gas_service::GasService, destination_chain: ascii::String, destination_address: ascii::String, payload: vector<u8>, refund_address: address, coin: coin::Coin<sui::SUI>, params: vector<u8>)
Implementation
public fun send_call(
singleton: &Singleton,
gateway: &Gateway,
gas_service: &mut GasService,
destination_chain: String,
destination_address: String,
payload: vector<u8>,
refund_address: address,
coin: Coin<SUI>,
params: vector<u8>,
) {
let message_ticket = gateway::prepare_message(
&singleton.channel,
destination_chain,
destination_address,
payload,
);
gas_service.pay_gas(
&message_ticket,
coin,
refund_address,
params,
);
gateway.send_message(message_ticket);
}
Function execute
public fun execute(call: channel::ApprovedMessage, singleton: &mut gmp::Singleton)
Implementation
public fun execute(call: ApprovedMessage, singleton: &mut Singleton) {
let (_, _, _, payload) = singleton.channel.consume_approved_message(call);
event::emit(Executed { data: payload });
}