Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions payjoin-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- Fix panic when spending taproot UTXOs. They are now contributed as key-path
spends with an assumed default input weight.
- Any unsupported coin is simply skipped instead of crashing the cli.

## 1.0.0

The first stable payjoin-cli release, tracking payjoin 1.2.0. The CLI adopts
Expand Down
45 changes: 32 additions & 13 deletions payjoin-cli/src/app/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,21 @@ impl BitcoindWallet {
.block_on(async { self.rpc.list_unspent(None, None, None, None, None).await })
})
.context("Failed to list unspent")?;
Ok(unspent.0.into_iter().map(input_pair_from_corepc).collect())
// Skip UTXOs whose input weight cannot be predicted before signing
// (e.g. P2WSH, legacy P2SH, bare scripts) rather than failing the
// whole candidate list.
let candidate_inputs = unspent
.0
.into_iter()
.filter_map(|utxo| match input_pair_from_corepc(utxo) {
Ok(pair) => Some(pair),
Err(e) => {
tracing::warn!("Skipping UTXO unusable for payjoin: {e:#}");
None
}
})
.collect();
Ok(candidate_inputs)
}

/// Check if wallet has any spendable UTXOs
Expand All @@ -215,21 +229,26 @@ impl BitcoindWallet {
}
}

pub fn input_pair_from_corepc(utxo: ListUnspentItem) -> InputPair {
pub fn input_pair_from_corepc(utxo: ListUnspentItem) -> Result<InputPair> {
let txout = TxOut {
value: Amount::from_btc(utxo.amount.to_btc()).expect("Valid amount"),
script_pubkey: utxo.script_pubkey,
};
let outpoint = OutPoint { txid: utxo.txid, vout: utxo.vout };

if txout.script_pubkey.is_p2tr() {
// bitcoin core wallets spend the taproot key path by default
return InputPair::new_p2tr_keyspend(txout, outpoint)
.context("Failed to create taproot key-spend input pair");
}

let psbtin = Input {
// NOTE: non_witness_utxo is not necessary because bitcoin-cli always supplies
// witness_utxo, even for non-witness inputs
witness_utxo: Some(TxOut {
value: Amount::from_btc(utxo.amount.to_btc()).expect("Valid amount"),
script_pubkey: utxo.script_pubkey,
}),
redeem_script: None,
witness_script: None, // Not available in this version
..Default::default()
};
let txin = TxIn {
previous_output: OutPoint { txid: utxo.txid, vout: utxo.vout },
witness_utxo: Some(txout),
redeem_script: utxo.redeem_script,
..Default::default()
};
InputPair::new(txin, psbtin, None).expect("Input pair should be valid")
let txin = TxIn { previous_output: outpoint, ..Default::default() };
InputPair::new(txin, psbtin, None).context("Failed to create input pair")
}
Loading