Skip to content

Commit ff14305

Browse files
committed
f BDK: Account for TxBuilder using Amounts
1 parent 9d8c1e6 commit ff14305

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/event.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use lightning_liquidity::lsps2::utils::compute_opening_fee;
4141

4242
use bitcoin::blockdata::locktime::absolute::LockTime;
4343
use bitcoin::secp256k1::PublicKey;
44-
use bitcoin::OutPoint;
44+
use bitcoin::{Amount, OutPoint};
4545

4646
use rand::{thread_rng, Rng};
4747

@@ -418,9 +418,10 @@ where
418418
let locktime = LockTime::from_height(cur_height).unwrap_or(LockTime::ZERO);
419419

420420
// Sign the final funding transaction and broadcast it.
421+
let channel_amount = Amount::from_sat(channel_value_satoshis);
421422
match self.wallet.create_funding_transaction(
422423
output_script,
423-
channel_value_satoshis,
424+
channel_amount,
424425
confirmation_target,
425426
locktime,
426427
) {

src/payment/onchain.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::error::Error;
1212
use crate::logger::{log_error, log_info, FilesystemLogger, Logger};
1313
use crate::types::{ChannelManager, Wallet};
1414

15-
use bitcoin::{Address, Txid};
15+
use bitcoin::{Address, Amount, Txid};
1616

1717
use std::sync::{Arc, RwLock};
1818

@@ -70,7 +70,9 @@ impl OnchainPayment {
7070
);
7171
return Err(Error::InsufficientFunds);
7272
}
73-
self.wallet.send_to_address(address, Some(amount_sats))
73+
74+
let amount = Amount::from_sat(amount_sats);
75+
self.wallet.send_to_address(address, Some(amount))
7476
}
7577

7678
/// Send an on-chain payment to the given address, draining all the available funds.

src/wallet/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ use bitcoin::psbt::Psbt;
3838
use bitcoin::secp256k1::ecdh::SharedSecret;
3939
use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature};
4040
use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey, Signing};
41-
use bitcoin::{ScriptBuf, Transaction, TxOut, Txid, WPubkeyHash, WitnessProgram, WitnessVersion};
41+
use bitcoin::{
42+
Amount, ScriptBuf, Transaction, TxOut, Txid, WPubkeyHash, WitnessProgram, WitnessVersion,
43+
};
4244

4345
use std::ops::{Deref, DerefMut};
4446
use std::sync::{Arc, Mutex};
@@ -137,7 +139,7 @@ where
137139
}
138140

139141
pub(crate) fn create_funding_transaction(
140-
&self, output_script: ScriptBuf, value_sats: u64, confirmation_target: ConfirmationTarget,
142+
&self, output_script: ScriptBuf, amount: Amount, confirmation_target: ConfirmationTarget,
141143
locktime: LockTime,
142144
) -> Result<Transaction, Error> {
143145
let fee_rate = self.fee_estimator.estimate_fee_rate(confirmation_target);
@@ -146,7 +148,7 @@ where
146148
let mut tx_builder = locked_wallet.build_tx();
147149

148150
tx_builder
149-
.add_recipient(output_script, value_sats)
151+
.add_recipient(output_script, amount)
150152
.fee_rate(fee_rate)
151153
.nlocktime(locktime)
152154
.enable_rbf();
@@ -217,7 +219,7 @@ where
217219
/// If `amount_msat_or_drain` is `None` the wallet will be drained, i.e., all available funds will be
218220
/// spent.
219221
pub(crate) fn send_to_address(
220-
&self, address: &bitcoin::Address, amount_msat_or_drain: Option<u64>,
222+
&self, address: &bitcoin::Address, amount_or_drain: Option<Amount>,
221223
) -> Result<Txid, Error> {
222224
let confirmation_target = ConfirmationTarget::OnchainPayment;
223225
let fee_rate = self.fee_estimator.estimate_fee_rate(confirmation_target);
@@ -226,9 +228,9 @@ where
226228
let mut locked_wallet = self.inner.lock().unwrap();
227229
let mut tx_builder = locked_wallet.build_tx();
228230

229-
if let Some(amount_sats) = amount_msat_or_drain {
231+
if let Some(amount) = amount_or_drain {
230232
tx_builder
231-
.add_recipient(address.script_pubkey(), amount_sats)
233+
.add_recipient(address.script_pubkey(), amount)
232234
.fee_rate(fee_rate)
233235
.enable_rbf();
234236
} else {
@@ -272,12 +274,12 @@ where
272274

273275
let txid = tx.compute_txid();
274276

275-
if let Some(amount_sats) = amount_msat_or_drain {
277+
if let Some(amount) = amount_or_drain {
276278
log_info!(
277279
self.logger,
278280
"Created new transaction {} sending {}sats on-chain to address {}",
279281
txid,
280-
amount_sats,
282+
amount.to_sat(),
281283
address
282284
);
283285
} else {

0 commit comments

Comments
 (0)