mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-11-17 00:07:53 +00:00
handler: add write handlers, impl Clone
This commit is contained in:
parent
e15b7d42c0
commit
4f738eef38
5 changed files with 19 additions and 23 deletions
|
@ -175,19 +175,15 @@ pub(super) async fn pop_blocks(
|
|||
state: &mut CupratedRpcHandlerState,
|
||||
nblocks: u64,
|
||||
) -> Result<u64, Error> {
|
||||
// TODO: we need access to `BlockchainWriteHandle`
|
||||
|
||||
// let BlockchainResponse::PopBlocks(height) = state
|
||||
// .blockchain_write
|
||||
// .ready()
|
||||
// .await?
|
||||
// .call(BlockchainWriteRequest::PopBlocks(nblocks))
|
||||
// .await?
|
||||
// else {
|
||||
// unreachable!();
|
||||
// };
|
||||
|
||||
let height = todo!();
|
||||
let BlockchainResponse::PopBlocks(height) = state
|
||||
.blockchain_write
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockchainWriteRequest::PopBlocks(nblocks))
|
||||
.await?
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
Ok(usize_to_u64(height))
|
||||
}
|
||||
|
|
|
@ -40,12 +40,14 @@ pub struct CupratedRpcHandlerState {
|
|||
/// Read handle to the blockchain database.
|
||||
pub blockchain_read: BlockchainReadHandle,
|
||||
|
||||
// /// Write handle to the blockchain database.
|
||||
// pub blockchain_write: BlockchainWriteHandle,
|
||||
/// Write handle to the blockchain database.
|
||||
pub blockchain_write: BlockchainWriteHandle,
|
||||
|
||||
/// Read handle to the transaction pool database.
|
||||
pub txpool_read: TxpoolReadHandle,
|
||||
// /// Write handle to the transaction pool database.
|
||||
// pub txpool_write: TxpoolWriteHandle,
|
||||
|
||||
/// Write handle to the transaction pool database.
|
||||
pub txpool_write: TxpoolWriteHandle,
|
||||
}
|
||||
|
||||
impl CupratedRpcHandler {
|
||||
|
|
|
@ -21,10 +21,6 @@
|
|||
//!
|
||||
//! The 2nd allows any caller to send [`WriteRequest`][req_w]s.
|
||||
//!
|
||||
//! The `DatabaseReadHandle` can be shared as it is cheaply [`Clone`]able, however,
|
||||
//! the `DatabaseWriteHandle` cannot be cloned. There is only 1 place in Cuprate that
|
||||
//! writes, so it is passed there and used.
|
||||
//!
|
||||
//! ## Initialization
|
||||
//! The database & thread-pool system can be initialized with [`init()`].
|
||||
//!
|
||||
|
|
|
@ -21,7 +21,7 @@ const WRITER_THREAD_NAME: &str = concat!(module_path!(), "::DatabaseWriter");
|
|||
/// Calling [`tower::Service::call`] with a [`DatabaseWriteHandle`]
|
||||
/// will return an `async`hronous channel that can be `.await`ed upon
|
||||
/// to receive the corresponding response.
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DatabaseWriteHandle<Req, Res> {
|
||||
/// Sender channel to the database write thread-pool.
|
||||
///
|
||||
|
|
|
@ -19,6 +19,7 @@ pub enum TxpoolReadRequest {
|
|||
//---------------------------------------------------------------------------------------------------- TxpoolReadResponse
|
||||
/// The transaction pool [`tower::Service`] read response type.
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
#[derive(Debug)]
|
||||
pub enum TxpoolReadResponse {
|
||||
/// A response containing the raw bytes of a transaction.
|
||||
// TODO: use bytes::Bytes.
|
||||
|
@ -29,6 +30,7 @@ pub enum TxpoolReadResponse {
|
|||
|
||||
//---------------------------------------------------------------------------------------------------- TxpoolWriteRequest
|
||||
/// The transaction pool [`tower::Service`] write request type.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TxpoolWriteRequest {
|
||||
/// Add a transaction to the pool.
|
||||
///
|
||||
|
@ -49,7 +51,7 @@ pub enum TxpoolWriteRequest {
|
|||
|
||||
//---------------------------------------------------------------------------------------------------- TxpoolWriteResponse
|
||||
/// The transaction pool [`tower::Service`] write response type.
|
||||
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq)]
|
||||
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub enum TxpoolWriteResponse {
|
||||
/// A [`TxpoolWriteRequest::AddTransaction`] response.
|
||||
///
|
||||
|
|
Loading…
Reference in a new issue