axelar-cgp-sui

Module 0xaa::relayer_discovery_v0

use 0x1::ascii;
use 0x2::object;
use 0x2::table;
use 0x2::tx_context;
use 0xaa::events;
use 0xaa::transaction;
use 0xb0::version_control;

Struct RelayerDiscovery_v0

A central shared object that stores discovery configuration for the Relayer. The Relayer will use this object to discover and execute the transactions when a message is targeted at specific channel.

struct RelayerDiscovery_v0 has store
Fields
configurations: table::Table<object::ID, transaction::Transaction>
A map of channel IDs to the target that needs to be executed by the relayer. There can be only one configuration per channel.
version_control: version_control::VersionControl
An object to manage version control.

Constants

#[error]
const EChannelNotFound: vector<u8> = b"channel not found";

Function new

public(friend) fun new(version_control: version_control::VersionControl, ctx: &mut tx_context::TxContext): relayer_discovery_v0::RelayerDiscovery_v0
Implementation
public(package) fun new(
    version_control: VersionControl,
    ctx: &mut TxContext,
): RelayerDiscovery_v0 {
    RelayerDiscovery_v0 {
        configurations: table::new<ID, Transaction>(ctx),
        version_control,
    }
}

Function set_transaction

public(friend) fun set_transaction(self: &mut relayer_discovery_v0::RelayerDiscovery_v0, id: object::ID, transaction: transaction::Transaction)
Implementation
public(package) fun set_transaction(
    self: &mut RelayerDiscovery_v0,
    id: ID,
    transaction: Transaction,
) {
    if (self.configurations.contains(id)) {
        self.configurations.remove(id);
    };
    self.configurations.add(id, transaction);
    events::transaction_registered(id, transaction);
}

Function remove_transaction

public(friend) fun remove_transaction(self: &mut relayer_discovery_v0::RelayerDiscovery_v0, id: object::ID): transaction::Transaction
Implementation
public(package) fun remove_transaction(
    self: &mut RelayerDiscovery_v0,
    id: ID,
): Transaction {
    assert!(self.configurations.contains(id), EChannelNotFound);
    let tx = self.configurations.remove(id);
    events::transaction_removed(id);
    tx
}

Function get_transaction

public(friend) fun get_transaction(self: &relayer_discovery_v0::RelayerDiscovery_v0, id: object::ID): transaction::Transaction
Implementation
public(package) fun get_transaction(
    self: &RelayerDiscovery_v0,
    id: ID,
): Transaction {
    assert!(self.configurations.contains(id), EChannelNotFound);
    self.configurations[id]
}

Function version_control

public(friend) fun version_control(self: &relayer_discovery_v0::RelayerDiscovery_v0): &version_control::VersionControl
Implementation
public(package) fun version_control(
    self: &RelayerDiscovery_v0,
): &VersionControl {
    &self.version_control
}

Function allow_function

public(friend) fun allow_function(self: &mut relayer_discovery_v0::RelayerDiscovery_v0, version: u64, function_name: ascii::String)
Implementation
public(package) fun allow_function(
    self: &mut RelayerDiscovery_v0,
    version: u64,
    function_name: String,
) {
    self.version_control.allow_function(version, function_name);
}

Function disallow_function

public(friend) fun disallow_function(self: &mut relayer_discovery_v0::RelayerDiscovery_v0, version: u64, function_name: ascii::String)
Implementation
public(package) fun disallow_function(
    self: &mut RelayerDiscovery_v0,
    version: u64,
    function_name: String,
) {
    self.version_control.disallow_function(version, function_name);
}