Skip to content

Commit

Permalink
refactor(interchain-token-service): use IntoEvent derive macro (#143)
Browse files Browse the repository at this point in the history
Co-authored-by: Milap Sheth <[email protected]>
  • Loading branch information
nbayindirli and milapsheth authored Jan 17, 2025
1 parent 9052c78 commit 5800cf7
Showing 1 changed file with 13 additions and 173 deletions.
186 changes: 13 additions & 173 deletions contracts/interchain-token-service/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
use core::fmt::Debug;

use soroban_sdk::{Address, Bytes, BytesN, Env, IntoVal, String, Symbol, Topics, Val};
use stellar_axelar_std::events::Event;
use soroban_sdk::{Address, Bytes, BytesN, String};
use stellar_axelar_std::IntoEvent;

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, IntoEvent)]
pub struct TrustedChainSetEvent {
pub chain: String,
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, IntoEvent)]
pub struct TrustedChainRemovedEvent {
pub chain: String,
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, IntoEvent)]
pub struct FlowLimitSetEvent {
pub token_id: BytesN<32>,
/// A `None` value implies that flow limit checks have been disabled for this `token_id`
pub flow_limit: Option<i128>,
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, IntoEvent)]
pub struct InterchainTokenDeployedEvent {
pub token_id: BytesN<32>,
pub token_address: Address,
Expand All @@ -30,7 +30,8 @@ pub struct InterchainTokenDeployedEvent {
pub minter: Option<Address>,
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, IntoEvent)]
#[event_name("token_deployment_started")]
pub struct InterchainTokenDeploymentStartedEvent {
pub token_id: BytesN<32>,
pub token_address: Address,
Expand All @@ -41,192 +42,31 @@ pub struct InterchainTokenDeploymentStartedEvent {
pub minter: Option<Address>,
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, IntoEvent)]
pub struct InterchainTokenIdClaimedEvent {
pub token_id: BytesN<32>,
pub deployer: Address,
pub salt: BytesN<32>,
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, IntoEvent)]
pub struct InterchainTransferSentEvent {
pub token_id: BytesN<32>,
pub source_address: Address,
pub destination_chain: String,
pub destination_address: Bytes,
pub amount: i128,
#[data]
pub data: Option<Bytes>,
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, IntoEvent)]
pub struct InterchainTransferReceivedEvent {
pub source_chain: String,
pub token_id: BytesN<32>,
pub source_address: Bytes,
pub destination_address: Address,
pub amount: i128,
#[data]
pub data: Option<Bytes>,
}

impl Event for TrustedChainSetEvent {
fn topics(&self, env: &Env) -> impl Topics + Debug {
(Symbol::new(env, "trusted_chain_set"), self.chain.to_val())
}
}

impl Event for TrustedChainRemovedEvent {
fn topics(&self, env: &Env) -> impl Topics + Debug {
(
Symbol::new(env, "trusted_chain_removed"),
self.chain.to_val(),
)
}
}

impl Event for FlowLimitSetEvent {
fn topics(&self, env: &Env) -> impl Topics + Debug {
(
Symbol::new(env, "flow_limit_set"),
self.token_id.to_val(),
self.flow_limit,
)
}
}

impl Event for InterchainTokenDeployedEvent {
fn topics(&self, env: &Env) -> impl Topics + Debug {
(
Symbol::new(env, "interchain_token_deployed"),
self.token_id.to_val(),
self.token_address.to_val(),
self.name.to_val(),
self.symbol.to_val(),
self.decimals,
self.minter.clone(),
)
}
}

impl Event for InterchainTokenDeploymentStartedEvent {
fn topics(&self, env: &Env) -> impl Topics + Debug {
(
Symbol::new(env, "token_deployment_started"),
self.token_id.to_val(),
self.token_address.to_val(),
self.destination_chain.to_val(),
self.name.to_val(),
self.symbol.to_val(),
self.decimals,
self.minter.clone(),
)
}
}

impl Event for InterchainTokenIdClaimedEvent {
fn topics(&self, env: &Env) -> impl Topics + Debug {
(
Symbol::new(env, "interchain_token_id_claimed"),
self.token_id.to_val(),
self.deployer.to_val(),
self.salt.to_val(),
)
}
}

impl Event for InterchainTransferSentEvent {
fn topics(&self, env: &Env) -> impl Topics + Debug {
(
Symbol::new(env, "interchain_transfer_sent"),
self.token_id.to_val(),
self.source_address.to_val(),
self.destination_chain.to_val(),
self.destination_address.to_val(),
self.amount,
)
}

fn data(&self, _env: &Env) -> impl IntoVal<Env, Val> + Debug {
(self.data.clone(),)
}
}

impl Event for InterchainTransferReceivedEvent {
fn topics(&self, env: &Env) -> impl Topics + Debug {
(
Symbol::new(env, "interchain_transfer_received"),
self.source_chain.to_val(),
self.token_id.to_val(),
self.source_address.to_val(),
self.destination_address.to_val(),
self.amount,
)
}

fn data(&self, _env: &Env) -> impl IntoVal<Env, Val> + Debug {
(self.data.clone(),)
}
}

#[cfg(any(test, feature = "testutils"))]
use stellar_axelar_std::impl_event_testutils;

#[cfg(any(test, feature = "testutils"))]
impl_event_testutils!(TrustedChainSetEvent, (Symbol, String), ());

#[cfg(any(test, feature = "testutils"))]
impl_event_testutils!(TrustedChainRemovedEvent, (Symbol, String), ());

#[cfg(any(test, feature = "testutils"))]
impl_event_testutils!(FlowLimitSetEvent, (Symbol, BytesN<32>, Option<i128>), ());

#[cfg(any(test, feature = "testutils"))]
impl_event_testutils!(
InterchainTokenDeployedEvent,
(
Symbol,
BytesN<32>,
Address,
String,
String,
u32,
Option<Address>
),
()
);

#[cfg(any(test, feature = "testutils"))]
impl_event_testutils!(
InterchainTokenDeploymentStartedEvent,
(
Symbol,
BytesN<32>,
Address,
String,
String,
String,
u32,
Option<Address>
),
()
);

#[cfg(any(test, feature = "testutils"))]
impl_event_testutils!(
InterchainTokenIdClaimedEvent,
(Symbol, BytesN<32>, Address, BytesN<32>),
()
);

#[cfg(any(test, feature = "testutils"))]
impl_event_testutils!(
InterchainTransferSentEvent,
(Symbol, BytesN<32>, Address, String, Bytes, i128),
(Option<Bytes>)
);

#[cfg(any(test, feature = "testutils"))]
impl_event_testutils!(
InterchainTransferReceivedEvent,
(Symbol, String, BytesN<32>, Bytes, Address, i128),
(Option<Bytes>)
);

0 comments on commit 5800cf7

Please sign in to comment.