Skip to content

Commit

Permalink
Fix compile
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Oct 7, 2024
1 parent fb4f747 commit efc2ddc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2024-09-25"
channel = "nightly-2024-05-13"
components = ["rustfmt", "clippy"]
profile = "default"
16 changes: 12 additions & 4 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<LightningClientModule>();
let lightning_module = client
.get_first_module::<LightningClientModule>()
.expect("must have ln module");

let gateway = select_gateway(&client)
.await
Expand Down Expand Up @@ -168,7 +170,9 @@ impl HarborCore {
amount: Amount,
) -> anyhow::Result<Bolt11Invoice> {
let client = self.get_client(federation_id).await.fedimint_client;
let lightning_module = client.get_first_module::<LightningClientModule>();
let lightning_module = client
.get_first_module::<LightningClientModule>()
.expect("must have ln module");

let gateway = select_gateway(&client)
.await
Expand Down Expand Up @@ -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::<WalletClientModule>();
let onchain = client
.get_first_module::<WalletClientModule>()
.expect("must have wallet module");

// todo add manual fee selection
let (fees, amount) = match sats {
Expand Down Expand Up @@ -290,7 +296,9 @@ impl HarborCore {
federation_id: FederationId,
) -> anyhow::Result<Address> {
let client = self.get_client(federation_id).await.fedimint_client;
let onchain = client.get_first_module::<WalletClientModule>();
let onchain = client
.get_first_module::<WalletClientModule>()
.expect("must have wallet module");

let (op_id, address, _) = onchain.allocate_deposit_address_expert_only(()).await?;

Expand Down
35 changes: 19 additions & 16 deletions src/fedimint_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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::<WalletClientModule>();
let wallet_client = fedimint_client
.get_first_module::<WalletClientModule>()
.expect("must have wallet module");
// compare magic bytes because different versions of rust-bitcoin
if network != wallet_client.get_network() {
error!(
Expand All @@ -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::<LightningClientModule>();
let lightning_module = client_clone
.get_first_module::<LightningClientModule>()
.expect("must have ln module");

match lightning_module.update_gateway_cache().await {
Ok(_) => {
Expand All @@ -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");
Expand All @@ -198,7 +194,10 @@ impl FedimintClient {
}

pub(crate) async fn select_gateway(client: &ClientHandleArc) -> Option<LightningGateway> {
let ln = client.get_first_module::<LightningClientModule>();
let ln = client
.get_first_module::<LightningClientModule>()
.expect("must have ln module");

let gateways = ln.list_gateways().await;
let mut selected_gateway: Option<LightningGateway> = None;
for gateway in gateways.iter() {
Expand Down Expand Up @@ -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<PrefixStream<'_>> {
self.mem.raw_find_by_range(range).await
}
}

#[async_trait]
Expand Down

0 comments on commit efc2ddc

Please sign in to comment.