Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(relayer_discovery)!: added events to relayer discovery #198

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 `RelayerDiscoveryV1`)
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,13 +47,15 @@ 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);
events::transaction_removed(id);
self.configurations.remove(id)
}

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": {}
}