1pub mod caching_proxy_node_client;
12pub mod rpc_node_client;
13
14use ab_core_primitives::pieces::{Piece, PieceIndex};
15use ab_core_primitives::segments::{SegmentHeader, SegmentIndex};
16use ab_farmer_rpc_primitives::{
17 BlockSealInfo, BlockSealResponse, FarmerAppInfo, SlotInfo, SolutionResponse,
18};
19use async_trait::async_trait;
20use futures::Stream;
21use std::fmt;
22use std::pin::Pin;
23
24#[async_trait]
26pub trait NodeClient: fmt::Debug + Send + Sync + 'static {
27 async fn farmer_app_info(&self) -> anyhow::Result<FarmerAppInfo>;
29
30 async fn subscribe_slot_info(
32 &self,
33 ) -> anyhow::Result<Pin<Box<dyn Stream<Item = SlotInfo> + Send + 'static>>>;
34
35 async fn submit_solution_response(
37 &self,
38 solution_response: SolutionResponse,
39 ) -> anyhow::Result<()>;
40
41 async fn subscribe_block_sealing(
43 &self,
44 ) -> anyhow::Result<Pin<Box<dyn Stream<Item = BlockSealInfo> + Send + 'static>>>;
45
46 async fn submit_block_seal(&self, block_seal: BlockSealResponse) -> anyhow::Result<()>;
48
49 async fn subscribe_archived_segment_headers(
51 &self,
52 ) -> anyhow::Result<Pin<Box<dyn Stream<Item = SegmentHeader> + Send + 'static>>>;
53
54 async fn segment_headers(
56 &self,
57 segment_indices: Vec<SegmentIndex>,
58 ) -> anyhow::Result<Vec<Option<SegmentHeader>>>;
59
60 async fn piece(&self, piece_index: PieceIndex) -> anyhow::Result<Option<Piece>>;
62
63 async fn acknowledge_archived_segment_header(
65 &self,
66 segment_index: SegmentIndex,
67 ) -> anyhow::Result<()>;
68}
69
70#[async_trait]
72pub trait NodeClientExt: NodeClient {
73 async fn cached_segment_headers(
78 &self,
79 segment_indices: Vec<SegmentIndex>,
80 ) -> anyhow::Result<Vec<Option<SegmentHeader>>>;
81
82 async fn last_segment_headers(&self, limit: u32) -> anyhow::Result<Vec<Option<SegmentHeader>>>;
88}