gas_service::gas_service
GasService
init
value_mut
value
allow_function
disallow_function
pay_gas
add_gas
collect_gas
refund
balance
version_control
use axelar_gateway::message_ticket;
use gas_service::events;
use gas_service::gas_service_v0;
use gas_service::operator_cap;
use gas_service::owner_cap;
use std::address;
use std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::type_name;
use std::vector;
use sui::accumulator;
use sui::address;
use sui::bag;
use sui::balance;
use sui::coin;
use sui::config;
use sui::deny_list;
use sui::dynamic_field;
use sui::dynamic_object_field;
use sui::event;
use sui::hash;
use sui::hex;
use sui::object;
use sui::party;
use sui::table;
use sui::transfer;
use sui::tx_context;
use sui::types;
use sui::url;
use sui::vec_map;
use sui::vec_set;
use sui::versioned;
use version_control::version_control;
GasService
public struct GasService has key, store
id: sui::object::UID
inner: sui::versioned::Versioned
const VERSION: u64 = 0;
init
fun init(ctx: &mut sui::tx_context::TxContext)
fun init(ctx: &mut TxContext) {
transfer::share_object(GasService {
id: object::new(ctx),
inner: versioned::create(
VERSION,
gas_service_v0::new(
version_control(),
ctx,
),
ctx,
),
});
transfer::public_transfer(
operator_cap::create(ctx),
ctx.sender(),
);
transfer::public_transfer(
owner_cap::create(ctx),
ctx.sender(),
);
}
value_mut
macro fun value_mut($self: &gas_service::gas_service::GasService, $function_name: vector<u8>): &mut gas_service::gas_service_v0::GasService_v0
macro fun value_mut($self: &GasService, $function_name: vector<u8>): &mut GasService_v0 {
let gas_service = $self;
let value = gas_service.inner.load_value_mut<GasService_v0>();
value.version_control().check(VERSION, ascii::string($function_name));
value
}
value
macro fun value($self: &gas_service::gas_service::GasService): &gas_service::gas_service_v0::GasService_v0
macro fun value($self: &GasService): &GasService_v0 {
let gas_service = $self;
gas_service.inner.load_value<GasService_v0>()
}
allow_function
entry fun allow_function(self: &mut gas_service::gas_service::GasService, _: &gas_service::owner_cap::OwnerCap, version: u64, function_name: std::ascii::String)
entry fun allow_function(self: &mut GasService, _: &OwnerCap, version: u64, function_name: String) {
self.value_mut!(b"allow_function").allow_function(version, function_name);
}
disallow_function
entry fun disallow_function(self: &mut gas_service::gas_service::GasService, _: &gas_service::owner_cap::OwnerCap, version: u64, function_name: std::ascii::String)
entry fun disallow_function(self: &mut GasService, _: &OwnerCap, version: u64, function_name: String) {
self.value_mut!(b"disallow_function").disallow_function(version, function_name);
}
pay_gas
Pay gas for a contract call. This function is called by the channel that wants to pay gas for a contract call. It can also be called by the user to pay gas for a contract call, while setting the sender as the channel ID.
public fun pay_gas<T>(self: &mut gas_service::gas_service::GasService, message_ticket: &axelar_gateway::message_ticket::MessageTicket, coin: sui::coin::Coin<T>, refund_address: address, params: vector<u8>)
public fun pay_gas<T>(
self: &mut GasService,
message_ticket: &MessageTicket,
coin: Coin<T>,
refund_address: address,
params: vector<u8>,
) {
self
.value_mut!(b"pay_gas")
.pay_gas<T>(
message_ticket,
coin,
refund_address,
params,
);
}
add_gas
Add gas for an existing cross-chain contract call. This function can be called by a user who wants to add gas for a contract call with insufficient gas.
public fun add_gas<T>(self: &mut gas_service::gas_service::GasService, coin: sui::coin::Coin<T>, message_id: std::ascii::String, refund_address: address, params: vector<u8>)
public fun add_gas<T>(self: &mut GasService, coin: Coin<T>, message_id: String, refund_address: address, params: vector<u8>) {
self
.value_mut!(b"add_gas")
.add_gas<T>(
coin,
message_id,
refund_address,
params,
);
}
collect_gas
public fun collect_gas<T>(self: &mut gas_service::gas_service::GasService, _: &gas_service::operator_cap::OperatorCap, receiver: address, amount: u64, ctx: &mut sui::tx_context::TxContext)
public fun collect_gas<T>(self: &mut GasService, _: &OperatorCap, receiver: address, amount: u64, ctx: &mut TxContext) {
self
.value_mut!(b"collect_gas")
.collect_gas<T>(
receiver,
amount,
ctx,
)
}
refund
public fun refund<T>(self: &mut gas_service::gas_service::GasService, _: &gas_service::operator_cap::OperatorCap, message_id: std::ascii::String, receiver: address, amount: u64, ctx: &mut sui::tx_context::TxContext)
public fun refund<T>(self: &mut GasService, _: &OperatorCap, message_id: String, receiver: address, amount: u64, ctx: &mut TxContext) {
self
.value_mut!(b"refund")
.refund<T>(
message_id,
receiver,
amount,
ctx,
);
}
balance
public fun balance<T>(self: &gas_service::gas_service::GasService): &sui::balance::Balance<T>
public fun balance<T>(self: &GasService): &Balance<T> {
self.value!().balance<T>()
}
version_control
fun version_control(): version_control::version_control::VersionControl
fun version_control(): VersionControl {
version_control::new(vector[
vector[b"pay_gas", b"add_gas", b"collect_gas", b"refund", b"allow_function", b"disallow_function"].map!(
|function_name| function_name.to_ascii_string(),
),
])
}