Module 0xa2::gas_service_v0
use 0x1::ascii;
use 0x2::address;
use 0x2::balance;
use 0x2::coin;
use 0x2::hash;
use 0x2::sui;
use 0x2::transfer;
use 0x2::tx_context;
use 0xa1::message_ticket;
use 0xa2::events;
use 0xb0::version_control;
Struct GasService_v0
struct GasService_v0 has store
Fields
-
balance: balance::Balance<sui::SUI>
-
-
version_control: version_control::VersionControl
-
Function new
public(friend) fun new(version_control: version_control::VersionControl): gas_service_v0::GasService_v0
Implementation
public(package) fun new(version_control: VersionControl): GasService_v0 {
GasService_v0 {
balance: balance::zero<SUI>(),
version_control,
}
}
Function version_control
public(friend) fun version_control(self: &gas_service_v0::GasService_v0): &version_control::VersionControl
Implementation
public(package) fun version_control(self: &GasService_v0): &VersionControl {
&self.version_control
}
Function pay_gas
public(friend) fun pay_gas(self: &mut gas_service_v0::GasService_v0, message_ticket: &message_ticket::MessageTicket, coin: coin::Coin<sui::SUI>, refund_address: address, params: vector<u8>)
Implementation
public(package) fun pay_gas(
self: &mut GasService_v0,
message_ticket: &MessageTicket,
coin: Coin<SUI>,
refund_address: address,
params: vector<u8>,
) {
let coin_value = coin.value();
self.put(coin);
let payload_hash = address::from_bytes(
keccak256(&message_ticket.payload()),
);
events::gas_paid<SUI>(
message_ticket.source_id(),
message_ticket.destination_chain(),
message_ticket.destination_address(),
payload_hash,
coin_value,
refund_address,
params,
);
}
Function add_gas
public(friend) fun add_gas(self: &mut gas_service_v0::GasService_v0, coin: coin::Coin<sui::SUI>, message_id: ascii::String, refund_address: address, params: vector<u8>)
Implementation
public(package) fun add_gas(
self: &mut GasService_v0,
coin: Coin<SUI>,
message_id: String,
refund_address: address,
params: vector<u8>,
) {
let coin_value = coin.value();
self.put(coin);
events::gas_added<SUI>(
message_id,
coin_value,
refund_address,
params,
);
}
Function collect_gas
public(friend) fun collect_gas(self: &mut gas_service_v0::GasService_v0, receiver: address, amount: u64, ctx: &mut tx_context::TxContext)
Implementation
public(package) fun collect_gas(
self: &mut GasService_v0,
receiver: address,
amount: u64,
ctx: &mut TxContext,
) {
transfer::public_transfer(
self.take(amount, ctx),
receiver,
);
events::gas_collected<SUI>(
receiver,
amount,
);
}
Function refund
public(friend) fun refund(self: &mut gas_service_v0::GasService_v0, message_id: ascii::String, receiver: address, amount: u64, ctx: &mut tx_context::TxContext)
Implementation
public(package) fun refund(
self: &mut GasService_v0,
message_id: String,
receiver: address,
amount: u64,
ctx: &mut TxContext,
) {
transfer::public_transfer(
self.take(amount, ctx),
receiver,
);
events::refunded<SUI>(
message_id,
amount,
receiver,
);
}
Function allow_function
public(friend) fun allow_function(self: &mut gas_service_v0::GasService_v0, version: u64, function_name: ascii::String)
Implementation
public(package) fun allow_function(
self: &mut GasService_v0,
version: u64,
function_name: String,
) {
self.version_control.allow_function(version, function_name);
}
Function disallow_function
public(friend) fun disallow_function(self: &mut gas_service_v0::GasService_v0, version: u64, function_name: ascii::String)
Implementation
public(package) fun disallow_function(
self: &mut GasService_v0,
version: u64,
function_name: String,
) {
self.version_control.disallow_function(version, function_name);
}
Function put
fun put(self: &mut gas_service_v0::GasService_v0, coin: coin::Coin<sui::SUI>)
Implementation
fun put(self: &mut GasService_v0, coin: Coin<SUI>) {
coin::put(&mut self.balance, coin);
}
Function take
fun take(self: &mut gas_service_v0::GasService_v0, amount: u64, ctx: &mut tx_context::TxContext): coin::Coin<sui::SUI>
Implementation
fun take(
self: &mut GasService_v0,
amount: u64,
ctx: &mut TxContext,
): Coin<SUI> {
coin::take(&mut self.balance, amount, ctx)
}