From 6af977f0a50981509214727dd99a8846f9d501ec Mon Sep 17 00:00:00 2001
From: "hinto.janai" <hinto.janai@protonmail.com>
Date: Mon, 14 Oct 2024 18:01:16 -0400
Subject: [PATCH] flush_transaction_pool

---
 binaries/cuprated/src/rpc/json.rs           | 11 ++++++++++-
 binaries/cuprated/src/rpc/request/txpool.rs |  6 +-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/binaries/cuprated/src/rpc/json.rs b/binaries/cuprated/src/rpc/json.rs
index 359486b..a370156 100644
--- a/binaries/cuprated/src/rpc/json.rs
+++ b/binaries/cuprated/src/rpc/json.rs
@@ -48,6 +48,8 @@ use crate::rpc::{
     CupratedRpcHandler,
 };
 
+use super::request::txpool;
+
 /// Map a [`JsonRpcRequest`] to the function that will lead to a [`JsonRpcResponse`].
 pub(super) async fn map_request(
     state: CupratedRpcHandler,
@@ -497,7 +499,14 @@ async fn flush_transaction_pool(
     state: CupratedRpcHandler,
     request: FlushTransactionPoolRequest,
 ) -> Result<FlushTransactionPoolResponse, Error> {
-    todo!();
+    let tx_hashes = request
+        .txids
+        .into_iter()
+        .map(helper::hex_to_hash)
+        .collect::<Result<Vec<[u8; 32]>, _>>()?;
+
+    txpool::flush(tx_hashes).await?;
+
     Ok(FlushTransactionPoolResponse { status: Status::Ok })
 }
 
diff --git a/binaries/cuprated/src/rpc/request/txpool.rs b/binaries/cuprated/src/rpc/request/txpool.rs
index eef2a47..952cbbc 100644
--- a/binaries/cuprated/src/rpc/request/txpool.rs
+++ b/binaries/cuprated/src/rpc/request/txpool.rs
@@ -49,11 +49,7 @@ pub(crate) async fn size(txpool_read: &mut TxpoolReadHandle) -> Result<u64, Erro
 }
 
 /// TODO
-#[expect(clippy::needless_pass_by_ref_mut, reason = "TODO: remove after impl")]
-pub(crate) async fn flush(
-    txpool_read: &mut TxpoolReadHandle,
-    tx_hashes: Vec<[u8; 32]>,
-) -> Result<(), Error> {
+pub(crate) async fn flush(tx_hashes: Vec<[u8; 32]>) -> Result<(), Error> {
     todo!();
     Ok(())
 }