]> git.bitcoin.ninja Git - ldk-sample/commitdiff
Post-async refactor cleanup
authorValentine Wallace <vwallace@protonmail.com>
Tue, 30 Mar 2021 17:44:17 +0000 (13:44 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Mon, 3 May 2021 22:30:48 +0000 (18:30 -0400)
src/bitcoind_client.rs
src/cli.rs
src/convert.rs
src/main.rs

index 48d54f822e783bbb9dabfc0888d581c593f960df..58510ae736bd894cbfece045db24ef4ddd9ded31 100644 (file)
@@ -153,19 +153,6 @@ impl BitcoindClient {
                                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;
                        }
                });
@@ -235,43 +222,6 @@ impl FeeEstimator for BitcoindClient {
                                self.fees.get(&Target::HighPriority).unwrap().load(Ordering::Acquire)
                        }
                }
-               // self.fees.g
-               // 253
-               // match confirmation_target {
-               //     ConfirmationTarget::Background =>
-               // }
-               // let mut rpc = self.bitcoind_rpc_client.lock().unwrap();
-
-               // let (conf_target, estimate_mode, default) = match confirmation_target {
-               //      ConfirmationTarget::Background => (144, "ECONOMICAL", 253),
-               //      ConfirmationTarget::Normal => (18, "ECONOMICAL", 20000),
-               //      ConfirmationTarget::HighPriority => (6, "CONSERVATIVE", 50000),
-               // };
-
-               // // This function may be called from a tokio runtime, or not. So we need to check before
-               // // making the call to avoid the error "cannot run a tokio runtime from within a tokio runtime".
-               // let conf_target_json = serde_json::json!(conf_target);
-               // let estimate_mode_json = serde_json::json!(estimate_mode);
-               // let resp = match Handle::try_current() {
-               //      Ok(_) => tokio::task::block_in_place(|| {
-               //              runtime
-               //                      .block_on(rpc.call_method::<FeeResponse>(
-               //                              "estimatesmartfee",
-               //                              &vec![conf_target_json, estimate_mode_json],
-               //                      ))
-               //                      .unwrap()
-               //      }),
-               //      _ => runtime
-               //              .block_on(rpc.call_method::<FeeResponse>(
-               //                      "estimatesmartfee",
-               //                      &vec![conf_target_json, estimate_mode_json],
-               //              ))
-               //              .unwrap(),
-               // };
-               // if resp.errored {
-               //      return default;
-               // }
-               // resp.feerate.unwrap()
        }
 }
 
@@ -283,32 +233,5 @@ impl BroadcasterInterface for BitcoindClient {
                        let mut rpc = bitcoind_rpc_client.lock().await;
                        rpc.call_method::<RawTx>("sendrawtransaction", &vec![tx_serialized]).await.unwrap();
                });
-               // let bitcoind_rpc_client = self.bitcoind_rpc_client.clone();
-               // tokio::spawn(async move {
-               //     let rpc = bitcoind_rpc_client.lock().await;
-               //     rpc.call_method::<R>
-               // });
-               // let mut rpc = self.bitcoind_rpc_client.lock().unwrap();
-               // let runtime = self.runtime.lock().unwrap();
-
-               // let tx_serialized = serde_json::json!(encode::serialize_hex(tx));
-               // // This function may be called from a tokio runtime, or not. So we need to check before
-               // // making the call to avoid the error "cannot run a tokio runtime from within a tokio runtime".
-               // match Handle::try_current() {
-               //      Ok(_) => {
-               //              tokio::task::block_in_place(|| {
-               //                      runtime
-               //                              .block_on(
-               //                                      rpc.call_method::<RawTx>("sendrawtransaction", &vec![tx_serialized]),
-               //                              )
-               //                              .unwrap();
-               //              });
-               //      }
-               //      _ => {
-               //              runtime
-               //                      .block_on(rpc.call_method::<RawTx>("sendrawtransaction", &vec![tx_serialized]))
-               //                      .unwrap();
-               //      }
-               // }
        }
 }
index 56c788fa3b72e2042c8b68d09b58d62acac70cdd..9589211261592d936c6232477506fa39356f09a6 100644 (file)
@@ -156,7 +156,6 @@ pub(crate) async fn poll_for_user_input(
                                                continue;
                                        };
 
-                                       // let private_channel = match words.next().as_ref().map(String::as_str) {
                                        let announce_channel = match words.next() {
                                                Some("--public") | Some("--public=true") => true,
                                                Some("--public=false") => false,
@@ -577,7 +576,6 @@ fn get_invoice(
                        Some(info) => info,
                        None => continue,
                };
-               println!("VMW: adding routehop, info.fee base: {}", forwarding_info.fee_base_msat);
                invoice = invoice.route(vec![lightning_invoice::RouteHop {
                        pubkey: channel.remote_network_id,
                        short_channel_id,
index 06677bc5780962d1bf4e16ecd5091f8cb96bb656..7dbd8cceb13caca3938a35077f205b1ff96aa386 100644 (file)
@@ -52,7 +52,6 @@ impl TryInto<NewAddress> for JsonResponse {
 
 pub struct FeeResponse {
        pub feerate: Option<u32>,
-       // pub errors: Array<String>,
        pub errored: bool,
 }
 
@@ -62,13 +61,10 @@ impl TryInto<FeeResponse> for JsonResponse {
                let errored = !self.0["errors"].is_null();
                Ok(FeeResponse {
                        errored,
-                         feerate: match self.0["feerate"].as_f64() {
-            Some(fee) => Some((fee * 100_000_000.0).round() as u32),
-            None => None
-        }
-                               // true => None,
-                               // // The feerate from bitcoind is in BTC/kb, and we want satoshis/kb.
-                               // false => Some((self.0["feerate"].as_f64().unwrap() * 100_000_000.0).round() as u32),
+                       feerate: match self.0["feerate"].as_f64() {
+                               Some(fee) => Some((fee * 100_000_000.0).round() as u32),
+                               None => None,
+                       },
                })
        }
 }
index 8c5793ac34945cf09b548b35f9055b777496bc27..ab9508672d6483ac82384eef39fa49d3492a62d7 100644 (file)
@@ -237,7 +237,6 @@ async fn handle_ldk_events(
                                        tokio::spawn(async move {
                                                let min = time_forwardable.as_secs();
                                                let seconds_to_sleep = thread_rng().gen_range(min, min * 5);
-                                               // thread::sleep(Duration::new(seconds_to_sleep, 0));
                                                tokio::time::sleep(Duration::from_secs(seconds_to_sleep)).await;
                                                forwarding_channel_manager.process_pending_htlc_forwards();
                                        });
@@ -277,7 +276,7 @@ pub async fn main() {
        fs::create_dir_all(ldk_data_dir.clone()).unwrap();
 
        // Initialize our bitcoind client.
-       let mut bitcoind_client = match BitcoindClient::new(
+       let bitcoind_client = match BitcoindClient::new(
                args.bitcoind_rpc_host.clone(),
                args.bitcoind_rpc_port,
                args.bitcoind_rpc_username.clone(),
@@ -291,7 +290,6 @@ pub async fn main() {
                        return;
                }
        };
-       // let mut bitcoind_rpc_client = bitcoind_client.get_new_rpc_client().unwrap();
 
        // ## Setup
        // Step 1: Initialize the FeeEstimator
@@ -421,7 +419,6 @@ pub async fn main() {
                }
                chain_tip = Some(
                        init::synchronize_listeners(
-                               // &mut bitcoind_rpc_client,
                                &mut bitcoind_client.deref(),
                                args.network,
                                &mut cache,
@@ -482,21 +479,16 @@ pub async fn main() {
 
        // Step 17: Connect and Disconnect Blocks
        if chain_tip.is_none() {
-               // chain_tip = Some(init::validate_best_block_header(&mut bitcoind_client).await.unwrap());
                chain_tip =
                        Some(init::validate_best_block_header(&mut bitcoind_client.deref()).await.unwrap());
-               // chain_tip = Some(init::validate_best_block_header(&mut bitcoind_rpc_client).await.unwrap());
        }
        let channel_manager_listener = channel_manager.clone();
        let chain_monitor_listener = chain_monitor.clone();
        let bitcoind_block_source = bitcoind_client.clone();
        let network = args.network;
        tokio::spawn(async move {
-               // let chain_poller = poll::ChainPoller::new(&mut bitcoind_client, network);
                let mut derefed = bitcoind_block_source.deref();
-               // let chain_poller = poll::ChainPoller::new(&mut bitcoind_block_source.deref(), network);
                let chain_poller = poll::ChainPoller::new(&mut derefed, network);
-               // let chain_poller = poll::ChainPoller::new(&mut bitcoind_rpc_client, network);
                let chain_listener = (chain_monitor_listener, channel_manager_listener);
                let mut spv_client =
                        SpvClient::new(chain_tip.unwrap(), chain_poller, &mut cache, &chain_listener);
@@ -533,21 +525,13 @@ pub async fn main() {
        let payment_info: PaymentInfoStorage = Arc::new(Mutex::new(HashMap::new()));
        let payment_info_for_events = payment_info.clone();
        let network = args.network;
-       // let bitcoind = BitcoindClient::new(
-       //     args.bitcoind_rpc_host.clone(),
-       //     args.bitcoind_rpc_port,
-       //     args.bitcoind_rpc_username.clone(),
-       //     args.bitcoind_rpc_password.clone(),
-       // ).await.unwrap();
        let bitcoind_rpc = bitcoind_client.clone();
        tokio::spawn(async move {
                handle_ldk_events(
                        peer_manager_event_listener,
                        channel_manager_event_listener,
                        chain_monitor_event_listener,
-                       // bitcoind_client.clone(),
                        bitcoind_rpc,
-                       // bitcoind,
                        keys_manager_listener,
                        payment_info_for_events,
                        network,