use std::time::Duration;
use futures::Stream;
use hopr_types::chain::chain_events::ChainEvent;
use super::{
ComponentStatus, ComponentStatusReporter, EventWaitResult, NodeOnchainIdentity, TicketEvent,
transport::TransportOperations,
};
use crate::{
OffchainPublicKey,
chain::HoprChainApi,
graph::{NetworkGraphConnectivity, NetworkGraphTraverse, NetworkGraphView},
network::NetworkView,
tickets::TicketManagement,
};
#[auto_impl::auto_impl(&, Arc)]
pub trait HasChainApi {
type ChainApi: HoprChainApi + ComponentStatusReporter + Clone + Send + Sync + 'static;
type ChainError: std::error::Error + Send + Sync + 'static;
fn identity(&self) -> &NodeOnchainIdentity;
fn chain_api(&self) -> &Self::ChainApi;
fn status(&self) -> ComponentStatus;
fn wait_for_on_chain_event<F>(
&self,
predicate: F,
context: String,
timeout: Duration,
) -> EventWaitResult<<Self::ChainApi as HoprChainApi>::ChainError, Self::ChainError>
where
F: Fn(&ChainEvent) -> bool + Send + Sync + 'static;
}
#[auto_impl::auto_impl(&, Arc)]
pub trait HasNetworkView {
type NetworkView: NetworkView + Send + Sync;
fn network_view(&self) -> &Self::NetworkView;
fn status(&self) -> ComponentStatus;
}
#[auto_impl::auto_impl(&, Arc)]
pub trait HasGraphView {
type Graph: NetworkGraphView<NodeId = OffchainPublicKey>
+ NetworkGraphConnectivity<NodeId = OffchainPublicKey>
+ NetworkGraphTraverse<NodeId = OffchainPublicKey>
+ Send
+ Sync;
fn graph(&self) -> &Self::Graph;
fn status(&self) -> ComponentStatus;
}
#[auto_impl::auto_impl(&, Arc)]
pub trait HasTransportApi {
type Transport: TransportOperations;
fn transport(&self) -> &Self::Transport;
fn status(&self) -> ComponentStatus;
}
#[auto_impl::auto_impl(&, Arc)]
pub trait HasTicketManagement {
type TicketManager: TicketManagement + Clone + Send + Sync + 'static;
fn ticket_management(&self) -> &Self::TicketManager;
fn subscribe_ticket_events(&self) -> impl Stream<Item = TicketEvent> + Send + 'static;
fn status(&self) -> ComponentStatus;
}