Skip to content

Commit

Permalink
feat(relayer_discovery)!: added events to relayer discovery (#198)
Browse files Browse the repository at this point in the history
Co-authored-by: Milap Sheth <[email protected]>
  • Loading branch information
Foivos and milapsheth authored Nov 20, 2024
1 parent 763090f commit 952c2e7
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-goats-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@axelar-network/axelar-cgp-sui': minor
---

Add events to register and remove transaction on relayer discovery
3 changes: 2 additions & 1 deletion move/relayer_discovery/sources/discovery.move
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use version_control::version_control::{Self, VersionControl};
/// -------
/// This is the version of the package that should change every package upgrade.
const VERSION: u64 = 0;
/// This is the version of the data that should change when we need to migrate `Versioned` type (e.g. from `RelayerDiscovery_v0` to `RelayerDiscoveryV1`)
/// This is the version of the data that should change when we need to migrate
/// `Versioned` type (e.g. from `RelayerDiscovery_v0` to `RelayerDiscovery_v1`)
const DATA_VERSION: u64 = 0;

/// -------
Expand Down
37 changes: 37 additions & 0 deletions move/relayer_discovery/sources/events.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module relayer_discovery::events;

use relayer_discovery::transaction::Transaction;
use sui::event;

/// ------
/// Events
/// ------
// Emitted when a transaction is registered
public struct TransactionRegistered has copy, drop {
channel_id: ID,
transaction: Transaction,
}

// Emitted when a transaction is removed
public struct TransactionRemoved has copy, drop {
channel_id: ID,
}

/// -----------------
/// Package Functions
/// -----------------
public(package) fun transaction_registered(
channel_id: ID,
transaction: Transaction,
) {
event::emit(TransactionRegistered {
channel_id,
transaction,
})
}

public(package) fun transaction_removed(channel_id: ID) {
event::emit(TransactionRemoved {
channel_id,
})
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module relayer_discovery::relayer_discovery_v0;

use relayer_discovery::events;
use relayer_discovery::transaction::Transaction;
use sui::table::{Self, Table};
use version_control::version_control::VersionControl;
Expand Down Expand Up @@ -46,14 +47,17 @@ public(package) fun set_transaction(
self.configurations.remove(id);
};
self.configurations.add(id, transaction);
events::transaction_registered(id, transaction);
}

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

public(package) fun get_transaction(
Expand Down
35 changes: 35 additions & 0 deletions test/testdata/interface_relayer_discovery_events.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"structs": {
"TransactionRegistered": {
"name": "TransactionRegistered",
"abilities": [
"copy",
"drop"
],
"fields": [
{
"name": "channel_id",
"type": "ID"
},
{
"name": "transaction",
"type": "Transaction"
}
]
},
"TransactionRemoved": {
"name": "TransactionRemoved",
"abilities": [
"copy",
"drop"
],
"fields": [
{
"name": "channel_id",
"type": "ID"
}
]
}
},
"publicFunctions": {}
}

0 comments on commit 952c2e7

Please sign in to comment.