diff --git a/src/core.rs b/src/core.rs index a3873a0..30a2695 100644 --- a/src/core.rs +++ b/src/core.rs @@ -107,7 +107,9 @@ impl HarborCore { // todo go through all clients and select the first one that has enough balance let client = self.get_client(federation_id).await.fedimint_client; - let lightning_module = client.get_first_module::(); + let lightning_module = client + .get_first_module::() + .expect("must have ln module"); let gateway = select_gateway(&client) .await @@ -168,7 +170,9 @@ impl HarborCore { amount: Amount, ) -> anyhow::Result { let client = self.get_client(federation_id).await.fedimint_client; - let lightning_module = client.get_first_module::(); + let lightning_module = client + .get_first_module::() + .expect("must have ln module"); let gateway = select_gateway(&client) .await @@ -224,7 +228,9 @@ impl HarborCore { ) -> anyhow::Result<()> { // todo go through all clients and select the first one that has enough balance let client = self.get_client(federation_id).await.fedimint_client; - let onchain = client.get_first_module::(); + let onchain = client + .get_first_module::() + .expect("must have wallet module"); // todo add manual fee selection let (fees, amount) = match sats { @@ -290,7 +296,9 @@ impl HarborCore { federation_id: FederationId, ) -> anyhow::Result
{ let client = self.get_client(federation_id).await.fedimint_client; - let onchain = client.get_first_module::(); + let onchain = client + .get_first_module::() + .expect("must have wallet module"); let (op_id, address, _) = onchain.allocate_deposit_address_expert_only(()).await?; diff --git a/src/fedimint_client.rs b/src/fedimint_client.rs index 2510ee4..226a7d4 100644 --- a/src/fedimint_client.rs +++ b/src/fedimint_client.rs @@ -29,13 +29,11 @@ use iced::futures::channel::mpsc::Sender; use iced::futures::{SinkExt, StreamExt}; use log::{debug, error, info, trace}; use std::fmt::Debug; +use std::ops::Range; use std::path::Path; use std::sync::Arc; use std::time::Instant; -use std::{ - fmt, - sync::atomic::{AtomicBool, Ordering}, -}; +use std::{fmt, sync::atomic::AtomicBool}; use tokio::spawn; use uuid::Uuid; @@ -145,7 +143,9 @@ impl FedimintClient { trace!("Retrieving fedimint wallet client module"); // check federation is on expected network - let wallet_client = fedimint_client.get_first_module::(); + let wallet_client = fedimint_client + .get_first_module::() + .expect("must have wallet module"); // compare magic bytes because different versions of rust-bitcoin if network != wallet_client.get_network() { error!( @@ -158,10 +158,11 @@ impl FedimintClient { // Update gateway cache in background let client_clone = fedimint_client.clone(); - let stop_clone = stop.clone(); spawn(async move { let start = Instant::now(); - let lightning_module = client_clone.get_first_module::(); + let lightning_module = client_clone + .get_first_module::() + .expect("must have ln module"); match lightning_module.update_gateway_cache().await { Ok(_) => { @@ -178,14 +179,9 @@ impl FedimintClient { ); // continually update gateway cache - loop { - lightning_module - .update_gateway_cache_continuously(|g| async { g }) - .await; - if stop_clone.load(Ordering::Relaxed) { - break; - } - } + lightning_module + .update_gateway_cache_continuously(|g| async { g }) + .await; }); debug!("Built fedimint client"); @@ -198,7 +194,10 @@ impl FedimintClient { } pub(crate) async fn select_gateway(client: &ClientHandleArc) -> Option { - let ln = client.get_first_module::(); + let ln = client + .get_first_module::() + .expect("must have ln module"); + let gateways = ln.list_gateways().await; let mut selected_gateway: Option = None; for gateway in gateways.iter() { @@ -765,6 +764,10 @@ impl<'a> IDatabaseTransactionOpsCore for SQLPseudoTransaction<'a> { .raw_find_by_prefix_sorted_descending(key_prefix) .await } + + async fn raw_find_by_range(&mut self, range: Range<&[u8]>) -> anyhow::Result> { + self.mem.raw_find_by_range(range).await + } } #[async_trait]