mod service;
pub use service::BaseNodeSyncRpcService;
use crate::{
chain_storage::{async_db::AsyncBlockchainDb, BlockchainBackend},
proto,
proto::base_node::{
FindChainSplitRequest,
FindChainSplitResponse,
SyncBlocksRequest,
SyncHeadersRequest,
SyncKernelsRequest,
SyncUtxosRequest,
SyncUtxosResponse,
},
};
use tari_comms::protocol::rpc::{Request, Response, RpcStatus, Streaming};
use tari_comms_rpc_macros::tari_rpc;
#[tari_rpc(protocol_name = b"t/blksync/1", server_struct = BaseNodeSyncRpcServer, client_struct = BaseNodeSyncRpcClient)]
pub trait BaseNodeSyncService: Send + Sync + 'static {
#[rpc(method = 1)]
async fn sync_blocks(
&self,
request: Request<SyncBlocksRequest>,
) -> Result<Streaming<proto::base_node::BlockBodyResponse>, RpcStatus>;
#[rpc(method = 2)]
async fn sync_headers(
&self,
request: Request<SyncHeadersRequest>,
) -> Result<Streaming<proto::core::BlockHeader>, RpcStatus>;
#[rpc(method = 3)]
async fn get_header_by_height(
&self,
request: Request<u64>,
) -> Result<Response<proto::core::BlockHeader>, RpcStatus>;
#[rpc(method = 4)]
async fn find_chain_split(
&self,
request: Request<FindChainSplitRequest>,
) -> Result<Response<FindChainSplitResponse>, RpcStatus>;
#[rpc(method = 5)]
async fn get_chain_metadata(
&self,
request: Request<()>,
) -> Result<Response<proto::base_node::ChainMetadata>, RpcStatus>;
#[rpc(method = 6)]
async fn sync_kernels(
&self,
request: Request<SyncKernelsRequest>,
) -> Result<Streaming<proto::types::TransactionKernel>, RpcStatus>;
#[rpc(method = 7)]
async fn sync_utxos(&self, request: Request<SyncUtxosRequest>) -> Result<Streaming<SyncUtxosResponse>, RpcStatus>;
}
pub fn create_base_node_sync_rpc_service<B: BlockchainBackend + 'static>(
db: AsyncBlockchainDb<B>,
) -> BaseNodeSyncRpcServer<BaseNodeSyncRpcService<B>> {
BaseNodeSyncRpcServer::new(BaseNodeSyncRpcService::new(db))
}