+ async fn poll_for_fee_estimates(
+ fees: Arc<HashMap<Target, AtomicU32>>, rpc_client: Arc<Mutex<RpcClient>>,
+ ) {
+ tokio::spawn(async move {
+ loop {
+ let background_estimate = {
+ let mut rpc = rpc_client.lock().await;
+ let background_conf_target = serde_json::json!(144);
+ let background_estimate_mode = serde_json::json!("ECONOMICAL");
+ let resp = rpc
+ .call_method::<FeeResponse>(
+ "estimatesmartfee",
+ &vec![background_conf_target, background_estimate_mode],
+ )
+ .await
+ .unwrap();
+ match resp.feerate {
+ Some(fee) => fee,
+ None => 253,
+ }
+ };
+ // if background_estimate.
+
+ let normal_estimate = {
+ let mut rpc = rpc_client.lock().await;
+ let normal_conf_target = serde_json::json!(18);
+ let normal_estimate_mode = serde_json::json!("ECONOMICAL");
+ let resp = rpc
+ .call_method::<FeeResponse>(
+ "estimatesmartfee",
+ &vec![normal_conf_target, normal_estimate_mode],
+ )
+ .await
+ .unwrap();
+ match resp.feerate {
+ Some(fee) => fee,
+ None => 2000,
+ }
+ };
+
+ let high_prio_estimate = {
+ let mut rpc = rpc_client.lock().await;
+ let high_prio_conf_target = serde_json::json!(6);
+ let high_prio_estimate_mode = serde_json::json!("CONSERVATIVE");
+ let resp = rpc
+ .call_method::<FeeResponse>(
+ "estimatesmartfee",
+ &vec![high_prio_conf_target, high_prio_estimate_mode],
+ )
+ .await
+ .unwrap();
+
+ match resp.feerate {
+ Some(fee) => fee,
+ None => 5000,
+ }
+ };
+
+ fees.get(&Target::Background)
+ .unwrap()
+ .store(background_estimate, Ordering::Release);
+ fees.get(&Target::Normal).unwrap().store(normal_estimate, Ordering::Release);
+ fees.get(&Target::HighPriority)
+ .unwrap()
+ .store(high_prio_estimate, Ordering::Release);
+ // match fees.get(Target::Background) {
+ // Some(fee) => fee.store(background_estimate, Ordering::Release),
+ // None =>
+ // }
+ // if let Some(fee) = background_estimate.feerate {
+ // fees.get("background").unwrap().store(fee, Ordering::Release);
+ // }
+ // if let Some(fee) = normal_estimate.feerate {
+ // fees.get("normal").unwrap().store(fee, Ordering::Release);
+ // }
+ // if let Some(fee) = high_prio_estimate.feerate {
+ // fees.get("high_prio").unwrap().store(fee, Ordering::Release);
+ // }
+ tokio::time::sleep(Duration::from_secs(60)).await;
+ }
+ });
+ }
+