use std::{ future::Future, pin::Pin, task::{Context, Poll}, }; use futures::FutureExt; use tower::Service; use monero_p2p::{ services::{ AddressBookRequest, AddressBookResponse, CoreSyncDataRequest, CoreSyncDataResponse, PeerSyncRequest, PeerSyncResponse, }, NetworkZone, PeerRequest, PeerResponse, }; #[derive(Clone)] pub struct DummyAddressBook; impl Service> for DummyAddressBook { type Response = AddressBookResponse; type Error = tower::BoxError; type Future = Pin> + Send + 'static>>; fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) } fn call(&mut self, req: AddressBookRequest) -> Self::Future { async move { Ok(match req { AddressBookRequest::GetWhitePeers(_) => AddressBookResponse::Peers(vec![]), _ => AddressBookResponse::Ok, }) } .boxed() } } #[derive(Clone)] pub struct DummyCoreSyncSvc; impl Service for DummyCoreSyncSvc { type Response = CoreSyncDataResponse; type Error = tower::BoxError; type Future = Pin> + Send + 'static>>; fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) } fn call(&mut self, _: CoreSyncDataRequest) -> Self::Future { async move { Ok(CoreSyncDataResponse(monero_wire::CoreSyncData { cumulative_difficulty: 1, cumulative_difficulty_top64: 0, current_height: 1, pruning_seed: 0, top_id: hex::decode( "418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e3", ) .unwrap() .try_into() .unwrap(), top_version: 1, })) } .boxed() } } #[derive(Clone)] pub struct DummyPeerSyncSvc; impl Service> for DummyPeerSyncSvc { type Error = tower::BoxError; type Future = Pin> + Send + 'static>>; type Response = PeerSyncResponse; fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) } fn call(&mut self, _: PeerSyncRequest) -> Self::Future { async { Ok(PeerSyncResponse::Ok) }.boxed() } } #[derive(Clone)] pub struct DummyPeerRequestHandlerSvc; impl Service for DummyPeerRequestHandlerSvc { type Response = PeerResponse; type Error = tower::BoxError; type Future = Pin> + Send + 'static>>; fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) } fn call(&mut self, _: PeerRequest) -> Self::Future { async move { Ok(PeerResponse::NA) }.boxed() } }