mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-01-28 21:36:00 +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,
|
state: &mut CupratedRpcHandlerState,
|
||||||
nblocks: u64,
|
nblocks: u64,
|
||||||
) -> Result<u64, Error> {
|
) -> Result<u64, Error> {
|
||||||
// TODO: we need access to `BlockchainWriteHandle`
|
let BlockchainResponse::PopBlocks(height) = state
|
||||||
|
.blockchain_write
|
||||||
// let BlockchainResponse::PopBlocks(height) = state
|
.ready()
|
||||||
// .blockchain_write
|
.await?
|
||||||
// .ready()
|
.call(BlockchainWriteRequest::PopBlocks(nblocks))
|
||||||
// .await?
|
.await?
|
||||||
// .call(BlockchainWriteRequest::PopBlocks(nblocks))
|
else {
|
||||||
// .await?
|
unreachable!();
|
||||||
// else {
|
};
|
||||||
// unreachable!();
|
|
||||||
// };
|
|
||||||
|
|
||||||
let height = todo!();
|
|
||||||
|
|
||||||
Ok(usize_to_u64(height))
|
Ok(usize_to_u64(height))
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,12 +40,14 @@ pub struct CupratedRpcHandlerState {
|
||||||
/// Read handle to the blockchain database.
|
/// Read handle to the blockchain database.
|
||||||
pub blockchain_read: BlockchainReadHandle,
|
pub blockchain_read: BlockchainReadHandle,
|
||||||
|
|
||||||
// /// Write handle to the blockchain database.
|
/// Write handle to the blockchain database.
|
||||||
// pub blockchain_write: BlockchainWriteHandle,
|
pub blockchain_write: BlockchainWriteHandle,
|
||||||
|
|
||||||
/// Read handle to the transaction pool database.
|
/// Read handle to the transaction pool database.
|
||||||
pub txpool_read: TxpoolReadHandle,
|
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 {
|
impl CupratedRpcHandler {
|
||||||
|
|
|
@ -21,10 +21,6 @@
|
||||||
//!
|
//!
|
||||||
//! The 2nd allows any caller to send [`WriteRequest`][req_w]s.
|
//! 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
|
//! ## Initialization
|
||||||
//! The database & thread-pool system can be initialized with [`init()`].
|
//! 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`]
|
/// Calling [`tower::Service::call`] with a [`DatabaseWriteHandle`]
|
||||||
/// will return an `async`hronous channel that can be `.await`ed upon
|
/// will return an `async`hronous channel that can be `.await`ed upon
|
||||||
/// to receive the corresponding response.
|
/// to receive the corresponding response.
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct DatabaseWriteHandle<Req, Res> {
|
pub struct DatabaseWriteHandle<Req, Res> {
|
||||||
/// Sender channel to the database write thread-pool.
|
/// Sender channel to the database write thread-pool.
|
||||||
///
|
///
|
||||||
|
|
|
@ -19,6 +19,7 @@ pub enum TxpoolReadRequest {
|
||||||
//---------------------------------------------------------------------------------------------------- TxpoolReadResponse
|
//---------------------------------------------------------------------------------------------------- TxpoolReadResponse
|
||||||
/// The transaction pool [`tower::Service`] read response type.
|
/// The transaction pool [`tower::Service`] read response type.
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum TxpoolReadResponse {
|
pub enum TxpoolReadResponse {
|
||||||
/// A response containing the raw bytes of a transaction.
|
/// A response containing the raw bytes of a transaction.
|
||||||
// TODO: use bytes::Bytes.
|
// TODO: use bytes::Bytes.
|
||||||
|
@ -29,6 +30,7 @@ pub enum TxpoolReadResponse {
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- TxpoolWriteRequest
|
//---------------------------------------------------------------------------------------------------- TxpoolWriteRequest
|
||||||
/// The transaction pool [`tower::Service`] write request type.
|
/// The transaction pool [`tower::Service`] write request type.
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub enum TxpoolWriteRequest {
|
pub enum TxpoolWriteRequest {
|
||||||
/// Add a transaction to the pool.
|
/// Add a transaction to the pool.
|
||||||
///
|
///
|
||||||
|
@ -49,7 +51,7 @@ pub enum TxpoolWriteRequest {
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- TxpoolWriteResponse
|
//---------------------------------------------------------------------------------------------------- TxpoolWriteResponse
|
||||||
/// The transaction pool [`tower::Service`] write response type.
|
/// The transaction pool [`tower::Service`] write response type.
|
||||||
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq)]
|
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
|
||||||
pub enum TxpoolWriteResponse {
|
pub enum TxpoolWriteResponse {
|
||||||
/// A [`TxpoolWriteRequest::AddTransaction`] response.
|
/// A [`TxpoolWriteRequest::AddTransaction`] response.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in a new issue