From dc3d29e3f06b7cb2aa0d502edd6f7fcf0aadf458 Mon Sep 17 00:00:00 2001 From: edouardparis Date: Mon, 26 Feb 2024 15:33:20 +0100 Subject: [PATCH] Remove spend_txs from cache --- gui/src/app/cache.rs | 4 +--- gui/src/app/mod.rs | 29 +++++++++++++---------------- gui/src/app/state/psbts.rs | 4 ++-- gui/src/loader.rs | 2 -- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/gui/src/app/cache.rs b/gui/src/app/cache.rs index cc714a6f..05944514 100644 --- a/gui/src/app/cache.rs +++ b/gui/src/app/cache.rs @@ -1,4 +1,4 @@ -use crate::daemon::model::{Coin, SpendTx}; +use crate::daemon::model::Coin; use liana::miniscript::bitcoin::Network; use std::path::PathBuf; @@ -8,7 +8,6 @@ pub struct Cache { pub network: Network, pub blockheight: i32, pub coins: Vec, - pub spend_txs: Vec, pub rescan_progress: Option, } @@ -20,7 +19,6 @@ impl std::default::Default for Cache { network: Network::Bitcoin, blockheight: 0, coins: Vec::new(), - spend_txs: Vec::new(), rescan_progress: None, } } diff --git a/gui/src/app/mod.rs b/gui/src/app/mod.rs index 8ebaa766..657cf053 100644 --- a/gui/src/app/mod.rs +++ b/gui/src/app/mod.rs @@ -32,7 +32,7 @@ use state::{ use crate::{ app::{cache::Cache, error::Error, menu::Menu, wallet::Wallet}, bitcoind::Bitcoind, - daemon::{embedded::EmbeddedDaemon, Daemon}, + daemon::{embedded::EmbeddedDaemon, model::Coin, Daemon}, }; use self::state::SettingsState; @@ -52,21 +52,22 @@ struct Panels { impl Panels { fn new( cache: &Cache, + coins: &[Coin], wallet: Arc, data_dir: PathBuf, internal_bitcoind: Option<&Bitcoind>, ) -> Panels { Self { current: Menu::Home, - home: Home::new(wallet.clone(), &cache.coins), - coins: CoinsPanel::new(&cache.coins, wallet.main_descriptor.first_timelock_value()), + home: Home::new(wallet.clone(), coins), + coins: CoinsPanel::new(coins, wallet.main_descriptor.first_timelock_value()), transactions: TransactionsPanel::new(), - psbts: PsbtsPanel::new(wallet.clone(), &cache.spend_txs), - recovery: RecoveryPanel::new(wallet.clone(), &cache.coins, cache.blockheight), + psbts: PsbtsPanel::new(wallet.clone()), + recovery: RecoveryPanel::new(wallet.clone(), &coins, cache.blockheight), receive: ReceivePanel::new(data_dir.clone(), wallet.clone()), create_spend: CreateSpendPanel::new( wallet.clone(), - &cache.coins, + &coins, cache.blockheight as u32, cache.network, ), @@ -131,6 +132,7 @@ impl App { ) -> (App, Command) { let mut panels = Panels::new( &cache, + &cache.coins, wallet.clone(), data_dir.clone(), internal_bitcoind.as_ref(), @@ -155,17 +157,15 @@ impl App { menu::Menu::PsbtPreSelected(txid) => { // Get preselected spend from DB in case it's not yet in the cache. // We only need this single spend as we will go straight to its view and not show the PSBTs list. - // In case of any error loading the spend or if it doesn't exist, fall back to using the cache - // and load PSBTs list in usual way. - self.panels.psbts = match self + // In case of any error loading the spend or if it doesn't exist, load PSBTs list in usual way. + if let Ok(Some(spend_tx)) = self .daemon .list_spend_transactions(Some(&[*txid])) .map(|txs| txs.first().cloned()) { - Ok(Some(spend_tx)) => { - PsbtsPanel::new_preselected(self.wallet.clone(), spend_tx) - } - _ => PsbtsPanel::new(self.wallet.clone(), &self.cache.spend_txs), + self.panels.psbts = PsbtsPanel::new_preselected(self.wallet.clone(), spend_tx); + self.panels.current = menu; + return Command::none(); }; } menu::Menu::RefreshCoins(preselected) => { @@ -219,9 +219,6 @@ impl App { Message::Coins(Ok(coins)) => { self.cache.coins = coins.clone(); } - Message::SpendTxs(Ok(txs)) => { - self.cache.spend_txs = txs.clone(); - } Message::Info(Ok(info)) => { self.cache.blockheight = info.block_height; self.cache.rescan_progress = info.rescan_progress; diff --git a/gui/src/app/state/psbts.rs b/gui/src/app/state/psbts.rs index 7a385580..6ba8a8ca 100644 --- a/gui/src/app/state/psbts.rs +++ b/gui/src/app/state/psbts.rs @@ -24,10 +24,10 @@ pub struct PsbtsPanel { } impl PsbtsPanel { - pub fn new(wallet: Arc, spend_txs: &[SpendTx]) -> Self { + pub fn new(wallet: Arc) -> Self { Self { wallet, - spend_txs: spend_txs.to_vec(), + spend_txs: Vec::new(), warning: None, selected_tx: None, import_tx: None, diff --git a/gui/src/loader.rs b/gui/src/loader.rs index 19f43033..da9f8da8 100644 --- a/gui/src/loader.rs +++ b/gui/src/loader.rs @@ -368,14 +368,12 @@ pub async fn load_application( Wallet::new(info.descriptors.main).load_settings(&gui_config, &datadir_path, network)?; let coins = daemon.list_coins().map(|res| res.coins)?; - let spend_txs = daemon.list_spend_transactions(None)?; let cache = Cache { datadir_path, network: info.network, blockheight: info.block_height, coins, - spend_txs, ..Default::default() };