@@ -797,6 +797,14 @@ where
797797 }
798798 } ;
799799
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+
800808 let mut tx = Transaction {
801809 version,
802810 lock_time,
@@ -831,19 +839,6 @@ where
831839 outgoing += value;
832840 }
833841
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-
847842 if params. change_policy != tx_builder:: ChangeSpendPolicy :: ChangeAllowed
848843 && self . change_descriptor . is_none ( )
849844 {
@@ -894,7 +889,7 @@ where
894889 } else {
895890 Some ( outgoing)
896891 } ,
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)
898893 min_absolute_fee : fee_amount,
899894 ..bdk_core:: CoinSelectorOpt :: fund_outputs (
900895 & tx. output ,
@@ -1048,7 +1043,7 @@ where
10481043 confirmation_time : None ,
10491044 received,
10501045 sent,
1051- fee : Some ( fee_amount ) ,
1046+ fee : Some ( excess_strategy . fee ) ,
10521047 } ;
10531048
10541049 Ok ( ( psbt, transaction_details) )
0 commit comments