Skip to content

Commit

Permalink
add allow and disallow function to relayer_discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Nov 26, 2024
1 parent b68989a commit 217dede
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/proud-pumas-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@axelar-network/axelar-cgp-sui': minor
---

Add allow_function and disallow_function to relayer_discovery.
60 changes: 59 additions & 1 deletion move/relayer_discovery/sources/discovery.move
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
module relayer_discovery::discovery;

use axelar_gateway::channel::Channel;
use relayer_discovery::owner_cap::{Self, OwnerCap};
use relayer_discovery::relayer_discovery_v0::{Self, RelayerDiscovery_v0};
use relayer_discovery::transaction::Transaction;
use std::ascii;
use std::ascii::{Self, String};
use sui::versioned::{Self, Versioned};
use version_control::version_control::{Self, VersionControl};

Expand Down Expand Up @@ -43,6 +44,7 @@ fun init(ctx: &mut TxContext) {
id: object::new(ctx),
inner,
});
transfer::public_transfer(owner_cap::create(ctx), ctx.sender());
}

/// ------
Expand All @@ -68,6 +70,32 @@ macro fun value_mut(
value
}

// ---------------
// Entry Functions
// ---------------
entry fun allow_function(
self: &mut RelayerDiscovery,
_: &OwnerCap,
version: u64,
function_name: String,
) {
self.value_mut!(b"allow_function").allow_function(version, function_name);
}

entry fun disallow_function(
self: &mut RelayerDiscovery,
_: &OwnerCap,
version: u64,
function_name: String,
) {
self
.value_mut!(b"disallow_function")
.disallow_function(version, function_name);
}

// ----------------
// Public Functions
// ----------------
/// During the creation of the object, the UID should be passed here to
/// receive the Channel and emit an event which will be handled by the
/// Relayer.
Expand Down Expand Up @@ -118,6 +146,8 @@ fun version_control(): VersionControl {
b"register_transaction",
b"remove_transaction",
b"get_transaction",
b"allow_function",
b"disallow_function",
].map!(|function_name| function_name.to_ascii_string()),
])
}
Expand Down Expand Up @@ -165,3 +195,31 @@ fun test_register_and_get() {
sui::test_utils::destroy(self);
sui::test_utils::destroy(channel);
}

#[test]
fun test_allow_function() {
let ctx = &mut sui::tx_context::dummy();
let mut self = new(ctx);
let owner_cap = owner_cap::create(ctx);
let version = 0;
let function_name = b"function_name".to_ascii_string();

self.allow_function(&owner_cap, version, function_name);

sui::test_utils::destroy(self);
owner_cap.destroy_for_testing();
}

#[test]
fun test_disallow_function() {
let ctx = &mut sui::tx_context::dummy();
let mut self = new(ctx);
let owner_cap = owner_cap::create(ctx);
let version = 0;
let function_name = b"register_transaction".to_ascii_string();

self.disallow_function(&owner_cap, version, function_name);

sui::test_utils::destroy(self);
owner_cap.destroy_for_testing();
}
23 changes: 23 additions & 0 deletions move/relayer_discovery/sources/types/owner_cap.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module relayer_discovery::owner_cap;

// -----
// Types
// -----
public struct OwnerCap has key, store {
id: UID,
}

public(package) fun create(ctx: &mut TxContext): OwnerCap {
OwnerCap {
id: object::new(ctx),
}
}

/// ---------
/// Test Only
/// ---------
#[test_only]
public(package) fun destroy_for_testing(self: OwnerCap) {
let OwnerCap { id } = self;
id.delete();
}
17 changes: 17 additions & 0 deletions move/relayer_discovery/sources/versioned/relayer_discovery_v0.move
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module relayer_discovery::relayer_discovery_v0;

use relayer_discovery::events;
use relayer_discovery::transaction::Transaction;
use std::ascii::String;
use sui::table::{Self, Table};
use version_control::version_control::VersionControl;

Expand Down Expand Up @@ -74,6 +75,22 @@ public(package) fun version_control(
&self.version_control
}

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

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

// ---------
// Test Only
// ---------
Expand Down

0 comments on commit 217dede

Please sign in to comment.