@@ -797,6 +797,14 @@ where
797
797
}
798
798
} ;
799
799
800
+ if params. recipients . is_empty ( ) {
801
+ let is_drain_all = params. drain_wallet && params. drain_to . is_some ( ) ;
802
+ let is_rbf = !params. utxos . is_empty ( ) && params. drain_to . is_some ( ) ;
803
+ if !( is_drain_all || is_rbf) {
804
+ return Err ( Error :: NoRecipients ) ;
805
+ }
806
+ }
807
+
800
808
let mut tx = Transaction {
801
809
version,
802
810
lock_time,
@@ -831,19 +839,6 @@ where
831
839
outgoing += value;
832
840
}
833
841
834
- fee_amount += fee_rate. fee_wu ( tx. weight ( ) ) ;
835
-
836
- // Segwit transactions' header is 2WU larger than legacy txs' header,
837
- // as they contain a witness marker (1WU) and a witness flag (1WU) (see BIP144).
838
- // At this point we really don't know if the resulting transaction will be segwit
839
- // or legacy, so we just add this 2WU to the fee_amount - overshooting the fee amount
840
- // is better than undershooting it.
841
- // If we pass a fee_amount that is slightly higher than the final fee_amount, we
842
- // end up with a transaction with a slightly higher fee rate than the requested one.
843
- // If, instead, we undershoot, we may end up with a feerate lower than the requested one
844
- // - we might come up with non broadcastable txs!
845
- fee_amount += fee_rate. fee_wu ( 2 ) ;
846
-
847
842
if params. change_policy != tx_builder:: ChangeSpendPolicy :: ChangeAllowed
848
843
&& self . change_descriptor . is_none ( )
849
844
{
@@ -894,7 +889,7 @@ where
894
889
} else {
895
890
Some ( outgoing)
896
891
} ,
897
- target_feerate : fee_rate. as_sat_per_vb ( ) * 4.0 , // sats/vb -> sats/wu
892
+ target_feerate : fee_rate. as_sat_per_vb ( ) / 4.0 , // sats/vb -> sats/wu (prefer overshoot)
898
893
min_absolute_fee : fee_amount,
899
894
..bdk_core:: CoinSelectorOpt :: fund_outputs (
900
895
& tx. output ,
@@ -1048,7 +1043,7 @@ where
1048
1043
confirmation_time : None ,
1049
1044
received,
1050
1045
sent,
1051
- fee : Some ( fee_amount ) ,
1046
+ fee : Some ( excess_strategy . fee ) ,
1052
1047
} ;
1053
1048
1054
1049
Ok ( ( psbt, transaction_details) )
0 commit comments