Skip to content

Commit a28d085

Browse files
committed
Fix transaction's feerate
1 parent 32b063a commit a28d085

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/main.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const PUBSIGNALS_SECRET_HASH_INDEX: usize = 8;
5151

5252
/// Number of the BDK wallet's sync tries to find the taproot atomic-swap transaction on-chain that
5353
/// has been published by a counterparty.
54-
const MAX_NUMBER_OF_ATTEMPTS_TO_SYNC: usize = 150;
54+
const MAX_NUMBER_OF_ATTEMPTS_TO_SYNC: usize = 300;
5555

5656
/// Delay between attempts to sync the BDK wallet to find the taproot atomic-swap transaction.
5757
const DELAY_BETWEEN_SYNC_ATTEMPT_SEC: u64 = 5;
@@ -499,7 +499,13 @@ impl SwapParticipant {
499499
self.bitcoin_wallet.network(),
500500
)?;
501501

502+
let feerate = self
503+
.bitcoin_client
504+
.estimate_fee(2)
505+
.wrap_err("failed to estimate fee")?;
506+
502507
builder
508+
.fee_rate(feerate)
503509
.drain_wallet()
504510
.drain_to(recepient_address.script_pubkey())
505511
.policy_path(path, KeychainKind::External);
@@ -589,7 +595,15 @@ impl SwapParticipant {
589595

590596
let (mut psbt, _details) = {
591597
let mut tx_builder = self.bitcoin_wallet.build_tx();
592-
tx_builder.add_recipient(address.script_pubkey(), sats_amount);
598+
599+
let feerate = self
600+
.bitcoin_client
601+
.estimate_fee(2)
602+
.wrap_err("failed to estimate fee")?;
603+
604+
tx_builder
605+
.fee_rate(feerate)
606+
.add_recipient(address.script_pubkey(), sats_amount);
593607
tx_builder.finish()?
594608
};
595609

0 commit comments

Comments
 (0)