Skip to content

Commit 254c673

Browse files
committed
Tweak transaction bumping sign_tx types for bindings
In bindings we can't practically pass a mutable transaction, and instead need to pass an owned transaction and have the sign method return a signed copy. We do this here only for the `#[cfg(c_bindings)]` build mode.
1 parent 1e119a2 commit 254c673

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

lightning/src/events/bump_transaction.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,14 @@ pub trait CoinSelectionSource {
467467
&self, claim_id: ClaimId, must_spend: &[Input], must_pay_to: &[TxOut],
468468
target_feerate_sat_per_1000_weight: u32,
469469
) -> Result<CoinSelection, ()>;
470+
#[cfg(not(c_bindings))]
470471
/// Signs and provides the full witness for all inputs within the transaction known to the
471472
/// trait (i.e., any provided via [`CoinSelectionSource::select_confirmed_utxos`]).
472473
fn sign_tx(&self, tx: &mut Transaction) -> Result<(), ()>;
474+
#[cfg(c_bindings)]
475+
/// Signs and provides the full witness for all inputs within the transaction known to the
476+
/// trait (i.e., any provided via [`CoinSelectionSource::select_confirmed_utxos`]).
477+
fn sign_tx(&self, tx: Transaction) -> Result<Transaction, ()>;
473478
}
474479

475480
/// An alternative to [`CoinSelectionSource`] that can be implemented and used along [`Wallet`] to
@@ -480,10 +485,16 @@ pub trait WalletSource {
480485
/// Returns a script to use for change above dust resulting from a successful coin selection
481486
/// attempt.
482487
fn get_change_script(&self) -> Result<Script, ()>;
488+
#[cfg(not(c_bindings))]
483489
/// Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
484490
/// the transaction known to the wallet (i.e., any provided via
485491
/// [`WalletSource::list_confirmed_utxos`]).
486492
fn sign_tx(&self, tx: &mut Transaction) -> Result<(), ()>;
493+
#[cfg(c_bindings)]
494+
/// Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
495+
/// the transaction known to the wallet (i.e., any provided via
496+
/// [`WalletSource::list_confirmed_utxos`]).
497+
fn sign_tx(&self, tx: Transaction) -> Result<Transaction, ()>;
487498
}
488499

489500
/// A wrapper over [`WalletSource`] that implements [`CoinSelection`] by preferring UTXOs that would
@@ -629,9 +640,15 @@ where
629640
.or_else(|_| do_coin_selection(true, true))
630641
}
631642

643+
#[cfg(not(c_bindings))]
632644
fn sign_tx(&self, tx: &mut Transaction) -> Result<(), ()> {
633645
self.source.sign_tx(tx)
634646
}
647+
648+
#[cfg(c_bindings)]
649+
fn sign_tx(&self, tx: Transaction) -> Result<Transaction, ()> {
650+
self.source.sign_tx(tx)
651+
}
635652
}
636653

637654
/// A handler for [`Event::BumpTransaction`] events that sources confirmed UTXOs from a
@@ -748,7 +765,13 @@ where
748765
let unsigned_tx_weight = anchor_tx.weight() as u64 - (anchor_tx.input.len() as u64 * EMPTY_SCRIPT_SIG_WEIGHT);
749766

750767
log_debug!(self.logger, "Signing anchor transaction {}", anchor_txid);
751-
self.utxo_source.sign_tx(&mut anchor_tx)?;
768+
#[cfg(not(c_bindings))] {
769+
self.utxo_source.sign_tx(&mut anchor_tx)?;
770+
}
771+
#[cfg(c_bindings)] {
772+
anchor_tx = self.utxo_source.sign_tx(anchor_tx)?;
773+
}
774+
752775
let signer = anchor_descriptor.derive_channel_signer(&self.signer_provider);
753776
let anchor_sig = signer.sign_holder_anchor_input(&anchor_tx, 0, &self.secp)?;
754777
anchor_tx.input[0].witness = anchor_descriptor.tx_input_witness(&anchor_sig);
@@ -812,7 +835,13 @@ where
812835
let unsigned_tx_weight = htlc_tx.weight() as u64 - (htlc_tx.input.len() as u64 * EMPTY_SCRIPT_SIG_WEIGHT);
813836

814837
log_debug!(self.logger, "Signing HTLC transaction {}", htlc_tx.txid());
815-
self.utxo_source.sign_tx(&mut htlc_tx)?;
838+
#[cfg(not(c_bindings))] {
839+
self.utxo_source.sign_tx(&mut htlc_tx)?;
840+
}
841+
#[cfg(c_bindings)] {
842+
htlc_tx = self.utxo_source.sign_tx(htlc_tx)?;
843+
}
844+
816845
let mut signers = BTreeMap::new();
817846
for (idx, htlc_descriptor) in htlc_descriptors.iter().enumerate() {
818847
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.keys_id)

0 commit comments

Comments
 (0)