From d219b77bd08b3c37befeaff5c00b5b431bd97145 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sat, 15 Nov 2025 16:13:25 -0500 Subject: [PATCH] Add bindings to the events from the coins module to `serai-client-serai` --- substrate/client/serai/src/coins.rs | 76 +++++++++++++++++++++++++++++ substrate/client/serai/src/lib.rs | 9 ++++ 2 files changed, 85 insertions(+) create mode 100644 substrate/client/serai/src/coins.rs diff --git a/substrate/client/serai/src/coins.rs b/substrate/client/serai/src/coins.rs new file mode 100644 index 00000000..dcd72fd5 --- /dev/null +++ b/substrate/client/serai/src/coins.rs @@ -0,0 +1,76 @@ +pub use serai_abi::coins::Event; + +use crate::{RpcError, TemporalSerai}; + +/// A `TemporalSerai` scoped to the coins module. +#[derive(Clone)] +pub struct Coins<'a>(pub(super) &'a TemporalSerai<'a>); + +impl<'a> Coins<'a> { + /// The events from the coins module. + pub async fn events(&self) -> Result, RpcError> { + Ok( + self + .0 + .events_borrowed() + .await? + .as_ref() + .expect("`TemporalSerai::events` returned None") + .iter() + .flat_map(IntoIterator::into_iter) + .filter_map(|event| match event { + serai_abi::Event::Coins(event) => Some(event.clone()), + _ => None, + }) + .collect(), + ) + } + + /// The `Mint` events from the coins module. + pub async fn mint_events(&self) -> Result, RpcError> { + Ok( + self + .events() + .await? + .into_iter() + .filter(|event| matches!(event, Event::Mint { .. })) + .collect(), + ) + } + + /// The `Transfer` events from the coins module. + pub async fn transfer_events(&self) -> Result, RpcError> { + Ok( + self + .events() + .await? + .into_iter() + .filter(|event| matches!(event, Event::Transfer { .. })) + .collect(), + ) + } + + /// The `Burn` events from the coins module. + pub async fn burn_events(&self) -> Result, RpcError> { + Ok( + self + .events() + .await? + .into_iter() + .filter(|event| matches!(event, Event::Burn { .. })) + .collect(), + ) + } + + /// The `BurnWithInstruction` events from the coins module. + pub async fn burn_with_instruction_events(&self) -> Result, RpcError> { + Ok( + self + .events() + .await? + .into_iter() + .filter(|event| matches!(event, Event::BurnWithInstruction { .. })) + .collect(), + ) + } +} diff --git a/substrate/client/serai/src/lib.rs b/substrate/client/serai/src/lib.rs index d29c12d3..badf22a7 100644 --- a/substrate/client/serai/src/lib.rs +++ b/substrate/client/serai/src/lib.rs @@ -19,6 +19,10 @@ use abi::{ use async_lock::RwLock; +/// RPC client functionality for the coins module. +pub mod coins; +use coins::*; + /// RPC client functionality for the validator sets module. pub mod validator_sets; use validator_sets::*; @@ -245,6 +249,11 @@ impl<'a> TemporalSerai<'a> { Ok(self.events_borrowed().await?.clone().expect("`TemporalSerai::events` returned None")) } + /// Scope to the coins module. + pub fn coins(&self) -> Coins<'_> { + Coins(self) + } + /// Scope to the validator sets module. pub fn validator_sets(&self) -> ValidatorSets<'_> { ValidatorSets(self)