refactor: add function to get coins to cache
This commit is contained in:
parent
733c3a6071
commit
e03d4e17be
@ -1,6 +1,11 @@
|
||||
use crate::daemon::model::Coin;
|
||||
use crate::daemon::{
|
||||
model::{Coin, ListCoinsResult},
|
||||
Daemon, DaemonError,
|
||||
};
|
||||
use liana::miniscript::bitcoin::Network;
|
||||
use lianad::commands::CoinStatus;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Cache {
|
||||
@ -31,3 +36,12 @@ impl std::default::Default for Cache {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the coins that should be cached.
|
||||
pub async fn coins_to_cache(
|
||||
daemon: Arc<dyn Daemon + Sync + Send>,
|
||||
) -> Result<ListCoinsResult, DaemonError> {
|
||||
daemon
|
||||
.list_coins(&[CoinStatus::Unconfirmed, CoinStatus::Confirmed], &[])
|
||||
.await
|
||||
}
|
||||
|
||||
@ -318,9 +318,7 @@ impl App {
|
||||
daemon.is_alive(&datadir_path, network).await?;
|
||||
|
||||
let info = daemon.get_info().await?;
|
||||
let coins = daemon
|
||||
.list_coins(&[CoinStatus::Unconfirmed, CoinStatus::Confirmed], &[])
|
||||
.await?;
|
||||
let coins = cache::coins_to_cache(daemon).await?;
|
||||
Ok(Cache {
|
||||
datadir_path,
|
||||
coins: coins.coins,
|
||||
|
||||
@ -18,7 +18,6 @@ use liana_ui::{
|
||||
widget::*,
|
||||
};
|
||||
use lianad::{
|
||||
commands::CoinStatus,
|
||||
config::{BitcoinBackend, Config, ConfigError},
|
||||
StartupError,
|
||||
};
|
||||
@ -28,7 +27,7 @@ use crate::backup::Backup;
|
||||
use crate::export::RestoreBackupError;
|
||||
use crate::{
|
||||
app::{
|
||||
cache::Cache,
|
||||
cache::{coins_to_cache, Cache},
|
||||
config::Config as GUIConfig,
|
||||
wallet::{Wallet, WalletError},
|
||||
},
|
||||
@ -429,10 +428,7 @@ pub async fn load_application(
|
||||
.load_from_settings(&datadir_path, network)?
|
||||
.load_hotsigners(&datadir_path, network)?;
|
||||
|
||||
let coins = daemon
|
||||
.list_coins(&[CoinStatus::Unconfirmed, CoinStatus::Confirmed], &[])
|
||||
.await
|
||||
.map(|res| res.coins)?;
|
||||
let coins = coins_to_cache(daemon.clone()).await.map(|res| res.coins)?;
|
||||
|
||||
let cache = Cache {
|
||||
datadir_path,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user