cuprated/rpc/request/
txpool.rs1use std::convert::Infallible;
4
5use anyhow::{anyhow, Error};
6use tower::{Service, ServiceExt};
7
8use cuprate_helper::cast::usize_to_u64;
9use cuprate_txpool::{
10 service::{
11 interface::{TxpoolReadRequest, TxpoolReadResponse},
12 TxpoolReadHandle,
13 },
14 TxEntry,
15};
16
17pub(crate) async fn backlog(txpool_read: &mut TxpoolReadHandle) -> Result<Vec<TxEntry>, Error> {
21 let TxpoolReadResponse::Backlog(tx_entries) = txpool_read
22 .ready()
23 .await
24 .map_err(|e| anyhow!(e))?
25 .call(TxpoolReadRequest::Backlog)
26 .await
27 .map_err(|e| anyhow!(e))?
28 else {
29 unreachable!();
30 };
31
32 Ok(tx_entries)
33}
34
35pub(crate) async fn size(
37 txpool_read: &mut TxpoolReadHandle,
38 include_sensitive_txs: bool,
39) -> Result<u64, Error> {
40 let TxpoolReadResponse::Size(size) = txpool_read
41 .ready()
42 .await
43 .map_err(|e| anyhow!(e))?
44 .call(TxpoolReadRequest::Size {
45 include_sensitive_txs,
46 })
47 .await
48 .map_err(|e| anyhow!(e))?
49 else {
50 unreachable!();
51 };
52
53 Ok(usize_to_u64(size))
54}
55
56pub(crate) async fn flush(
58 txpool_manager: &mut Infallible,
59 tx_hashes: Vec<[u8; 32]>,
60) -> Result<(), Error> {
61 todo!();
62 Ok(())
63}
64
65pub(crate) async fn relay(
67 txpool_manager: &mut Infallible,
68 tx_hashes: Vec<[u8; 32]>,
69) -> Result<(), Error> {
70 todo!();
71 Ok(())
72}