mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Add bindings to the events from the coins module to serai-client-serai
This commit is contained in:
76
substrate/client/serai/src/coins.rs
Normal file
76
substrate/client/serai/src/coins.rs
Normal file
@@ -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<Vec<Event>, 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<Vec<Event>, 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<Vec<Event>, 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<Vec<Event>, 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<Vec<Event>, RpcError> {
|
||||
Ok(
|
||||
self
|
||||
.events()
|
||||
.await?
|
||||
.into_iter()
|
||||
.filter(|event| matches!(event, Event::BurnWithInstruction { .. }))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user