use {
crate::sui,
std::{convert::Infallible, error::Error},
};
pub trait EventQuery: Send + Sync + 'static {
type Output: Send + 'static;
type Error: Error + Send + Sync + 'static;
fn filter(&self) -> sui::grpc::EventFilter;
fn read_mask(&self) -> sui::grpc::FieldMask;
fn decode(
&self,
event: sui::grpc::Event,
) -> impl std::future::Future<Output = Result<Option<Self::Output>, Self::Error>> + Send;
}
#[derive(Clone)]
pub struct RawEventQuery {
filter: sui::grpc::EventFilter,
read_mask: sui::grpc::FieldMask,
}
impl RawEventQuery {
pub fn new(filter: sui::grpc::EventFilter, read_mask: sui::grpc::FieldMask) -> Self {
Self { filter, read_mask }
}
}
impl EventQuery for RawEventQuery {
type Error = Infallible;
type Output = sui::grpc::Event;
fn filter(&self) -> sui::grpc::EventFilter {
self.filter.clone()
}
fn read_mask(&self) -> sui::grpc::FieldMask {
self.read_mask.clone()
}
async fn decode(&self, event: sui::grpc::Event) -> Result<Option<Self::Output>, Self::Error> {
Ok(Some(event))
}
}