0xa2::gas_service
GasService
GasCollectorCap
init
allow_function
disallow_function
pay_gas
add_gas
collect_gas
refund
version_control
use 0x1::ascii;
use 0x1::vector;
use 0x2::coin;
use 0x2::object;
use 0x2::sui;
use 0x2::transfer;
use 0x2::tx_context;
use 0x2::versioned;
use 0xa1::message_ticket;
use 0xa2::gas_service_v0;
use 0xb0::version_control;
GasService
struct GasService has store, key
id: object::UID
inner: versioned::Versioned
GasCollectorCap
struct GasCollectorCap has store, key
id: object::UID
const VERSION: u64 = 0;
init
fun init(ctx: &mut 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,
),
});
transfer::public_transfer(
GasCollectorCap {
id: object::new(ctx),
},
ctx.sender(),
);
}
allow_function
entry fun allow_function(self: &mut gas_service::GasService, _: &gas_service::GasCollectorCap, version: u64, function_name: ascii::String)
entry fun allow_function(
self: &mut GasService,
_: &GasCollectorCap,
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::GasService, _: &gas_service::GasCollectorCap, version: u64, function_name: ascii::String)
entry fun disallow_function(
self: &mut GasService,
_: &GasCollectorCap,
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(self: &mut gas_service::GasService, message_ticket: &message_ticket::MessageTicket, coin: coin::Coin<sui::SUI>, refund_address: address, params: vector<u8>)
public fun pay_gas(
self: &mut GasService,
message_ticket: &MessageTicket,
coin: Coin<SUI>,
refund_address: address,
params: vector<u8>,
) {
self
.value_mut!(b"pay_gas")
.pay_gas(
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(self: &mut gas_service::GasService, coin: coin::Coin<sui::SUI>, message_id: ascii::String, refund_address: address, params: vector<u8>)
public fun add_gas(
self: &mut GasService,
coin: Coin<SUI>,
message_id: String,
refund_address: address,
params: vector<u8>,
) {
self
.value_mut!(b"add_gas")
.add_gas(
coin,
message_id,
refund_address,
params,
);
}
collect_gas
public fun collect_gas(self: &mut gas_service::GasService, _: &gas_service::GasCollectorCap, receiver: address, amount: u64, ctx: &mut tx_context::TxContext)
public fun collect_gas(
self: &mut GasService,
_: &GasCollectorCap,
receiver: address,
amount: u64,
ctx: &mut TxContext,
) {
self
.value_mut!(b"collect_gas")
.collect_gas(
receiver,
amount,
ctx,
)
}
refund
public fun refund(self: &mut gas_service::GasService, _: &gas_service::GasCollectorCap, message_id: ascii::String, receiver: address, amount: u64, ctx: &mut tx_context::TxContext)
public fun refund(
self: &mut GasService,
_: &GasCollectorCap,
message_id: String,
receiver: address,
amount: u64,
ctx: &mut TxContext,
) {
self
.value_mut!(b"refund")
.refund(
message_id,
receiver,
amount,
ctx,
);
}
version_control
fun 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()),
])
}