Skip to content

Commit

Permalink
bugfix: Return early if no non-static outputs
Browse files Browse the repository at this point in the history
If there is a cooperative closure, there will only be one output to
spend, and it will be a `StaticOutput`. Since `WalletKeysManager`'s
`spend_spendable_outputs` filters out static outputs, `KeysManager`'s
`spend_spendable_outputs` gets passed an empty list of descriptors to
spend, which results in an error (with no further information provided).
  • Loading branch information
MaxFangX committed Jul 5, 2023
1 parent 3c7dac9 commit 1750be4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,10 @@ where
&Secp256k1::new(),
);
match res {
Ok(spending_tx) => self.wallet.broadcast_transaction(&spending_tx),
Ok(Some(spending_tx)) => self.wallet.broadcast_transaction(&spending_tx),
Ok(None) => {
log_info!(self.logger, "All outputs already handled");
}
Err(err) => {
log_error!(self.logger, "Error spending outputs: {:?}", err);
}
Expand Down
21 changes: 13 additions & 8 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,19 +362,24 @@ where
&self, descriptors: &[&SpendableOutputDescriptor], outputs: Vec<TxOut>,
change_destination_script: Script, feerate_sat_per_1000_weight: u32,
secp_ctx: &Secp256k1<C>,
) -> Result<Transaction, ()> {
) -> Result<Option<Transaction>, ()> {
let only_non_static = &descriptors
.iter()
.filter(|desc| !matches!(desc, SpendableOutputDescriptor::StaticOutput { .. }))
.copied()
.collect::<Vec<_>>();
self.inner.spend_spendable_outputs(
only_non_static,
outputs,
change_destination_script,
feerate_sat_per_1000_weight,
secp_ctx,
)
if only_non_static.is_empty() {
return Ok(None);
}
self.inner
.spend_spendable_outputs(
only_non_static,
outputs,
change_destination_script,
feerate_sat_per_1000_weight,
secp_ctx,
)
.map(Some)
}

pub fn sign_message(&self, msg: &[u8]) -> Result<String, Error> {
Expand Down

0 comments on commit 1750be4

Please sign in to comment.