From b22d4aba6b1e339ce929ccc37276a7a33e520520 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Mon, 18 Sep 2023 15:30:32 -0500 Subject: [PATCH 1/1] Remove unneeded Target enum --- src/bitcoind_client.rs | 47 +++++++++++++----------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/src/bitcoind_client.rs b/src/bitcoind_client.rs index a093e6d..3a41bc6 100644 --- a/src/bitcoind_client.rs +++ b/src/bitcoind_client.rs @@ -33,19 +33,11 @@ pub struct BitcoindClient { port: u16, rpc_user: String, rpc_password: String, - fees: Arc>, + fees: Arc>, handle: tokio::runtime::Handle, logger: Arc, } -#[derive(Clone, Eq, Hash, PartialEq)] -pub enum Target { - MempoolMinimum, - Background, - Normal, - HighPriority, -} - impl BlockSource for BitcoindClient { fn get_header<'a>( &'a self, header_hash: &'a BlockHash, height_hint: Option, @@ -83,11 +75,11 @@ impl BitcoindClient { std::io::Error::new(std::io::ErrorKind::PermissionDenied, "Failed to make initial call to bitcoind - please check your RPC user/password and access settings") })?; - let mut fees: HashMap = HashMap::new(); - fees.insert(Target::MempoolMinimum, AtomicU32::new(MIN_FEERATE)); - fees.insert(Target::Background, AtomicU32::new(MIN_FEERATE)); - fees.insert(Target::Normal, AtomicU32::new(2000)); - fees.insert(Target::HighPriority, AtomicU32::new(5000)); + let mut fees: HashMap = HashMap::new(); + fees.insert(ConfirmationTarget::MempoolMinimum, AtomicU32::new(MIN_FEERATE)); + fees.insert(ConfirmationTarget::Background, AtomicU32::new(MIN_FEERATE)); + fees.insert(ConfirmationTarget::Normal, AtomicU32::new(2000)); + fees.insert(ConfirmationTarget::HighPriority, AtomicU32::new(5000)); let client = Self { bitcoind_rpc_client: Arc::new(bitcoind_rpc_client), host, @@ -107,7 +99,7 @@ impl BitcoindClient { } fn poll_for_fee_estimates( - fees: Arc>, rpc_client: Arc, + fees: Arc>, rpc_client: Arc, handle: tokio::runtime::Handle, ) { handle.spawn(async move { @@ -171,14 +163,16 @@ impl BitcoindClient { } }; - fees.get(&Target::MempoolMinimum) + fees.get(&ConfirmationTarget::MempoolMinimum) .unwrap() .store(mempoolmin_estimate, Ordering::Release); - fees.get(&Target::Background) + fees.get(&ConfirmationTarget::Background) .unwrap() .store(background_estimate, Ordering::Release); - fees.get(&Target::Normal).unwrap().store(normal_estimate, Ordering::Release); - fees.get(&Target::HighPriority) + fees.get(&ConfirmationTarget::Normal) + .unwrap() + .store(normal_estimate, Ordering::Release); + fees.get(&ConfirmationTarget::HighPriority) .unwrap() .store(high_prio_estimate, Ordering::Release); tokio::time::sleep(Duration::from_secs(60)).await; @@ -267,20 +261,7 @@ impl BitcoindClient { impl FeeEstimator for BitcoindClient { fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32 { - match confirmation_target { - ConfirmationTarget::MempoolMinimum => { - self.fees.get(&Target::MempoolMinimum).unwrap().load(Ordering::Acquire) - } - ConfirmationTarget::Background => { - self.fees.get(&Target::Background).unwrap().load(Ordering::Acquire) - } - ConfirmationTarget::Normal => { - self.fees.get(&Target::Normal).unwrap().load(Ordering::Acquire) - } - ConfirmationTarget::HighPriority => { - self.fees.get(&Target::HighPriority).unwrap().load(Ordering::Acquire) - } - } + self.fees.get(&confirmation_target).unwrap().load(Ordering::Acquire) } } -- 2.30.2