From a1918f5eb6009c5e4526edcc57f82f5a1ccec37f Mon Sep 17 00:00:00 2001 From: pythcoiner Date: Mon, 14 Apr 2025 20:26:55 +0200 Subject: [PATCH] export: do not panic if import an insane PSBT --- liana-gui/src/app/state/psbt.rs | 4 +--- liana-gui/src/export.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/liana-gui/src/app/state/psbt.rs b/liana-gui/src/app/state/psbt.rs index fffe8062..6f1de0c2 100644 --- a/liana-gui/src/app/state/psbt.rs +++ b/liana-gui/src/app/state/psbt.rs @@ -250,9 +250,7 @@ impl PsbtState { .wallet .main_descriptor .partial_spend_info(&self.tx.psbt) - // FIXME: we should not unwrap here, it seems importing a PSBT w/ an - // non-owned input will trigger a panic - .unwrap(); + .expect("already check in psbt import logic"); } _ => { if let Some(modal) = self.modal.as_mut() { diff --git a/liana-gui/src/export.rs b/liana-gui/src/export.rs index 91669782..d5364f63 100644 --- a/liana-gui/src/export.rs +++ b/liana-gui/src/export.rs @@ -124,6 +124,7 @@ pub enum Error { ParseXpub, XpubNetwork, TxidNotMatch, + InsanePsbt, } impl Display for Error { @@ -145,7 +146,8 @@ impl Display for Error { Error::Backup(e) => write!(f, "Backup: {e}"), Error::ParseXpub => write!(f, "Failed to parse Xpub from file"), Error::XpubNetwork => write!(f, "Xpub is for another network"), - Error::TxidNotMatch => write!(f, "The imported PSBT txid do not match this PSBT"), + Error::TxidNotMatch => write!(f, "The imported PSBT txid doesn't match this PSBT"), + Error::InsanePsbt => write!(f, "The Psbt is not sane"), } } } @@ -591,12 +593,17 @@ pub async fn import_psbt( let mut file = File::open(&path)?; let daemon = daemon.ok_or(Error::DaemonMissing)?; + let descr = daemon.get_info().await?.descriptors.main; + let mut psbt_str = String::new(); file.read_to_string(&mut psbt_str)?; psbt_str = psbt_str.trim().to_string(); let psbt = Psbt::from_str(&psbt_str).map_err(|_| Error::ParsePsbt)?; send_progress!(sender, Progress(50.0)); + descr + .partial_spend_info(&psbt) + .map_err(|_| Error::InsanePsbt)?; if let Some(txid) = txid { if psbt.unsigned_tx.compute_txid() != txid {