export: do not panic if import an insane PSBT

This commit is contained in:
pythcoiner 2025-04-14 20:26:55 +02:00
parent 3d9440d3ac
commit a1918f5eb6
No known key found for this signature in database
GPG Key ID: C1048AEEDF303B88
2 changed files with 9 additions and 4 deletions

View File

@ -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() {

View File

@ -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 {