@@ -17,6 +17,24 @@ use bitcoin::{Address, Txid};
1717
1818use std:: sync:: { Arc , RwLock } ;
1919
20+ #[ cfg( not( feature = "uniffi" ) ) ]
21+ type FeeRate = bitcoin:: FeeRate ;
22+ #[ cfg( feature = "uniffi" ) ]
23+ type FeeRate = Arc < bitcoin:: FeeRate > ;
24+
25+ macro_rules! maybe_map_fee_rate_opt {
26+ ( $fee_rate_opt: expr) => { {
27+ #[ cfg( not( feature = "uniffi" ) ) ]
28+ {
29+ $fee_rate_opt
30+ }
31+ #[ cfg( feature = "uniffi" ) ]
32+ {
33+ $fee_rate_opt. map( |f| * f)
34+ }
35+ } } ;
36+ }
37+
2038/// A payment handler allowing to send and receive on-chain payments.
2139///
2240/// Should be retrieved by calling [`Node::onchain_payment`].
@@ -50,9 +68,12 @@ impl OnchainPayment {
5068 /// This will respect any on-chain reserve we need to keep, i.e., won't allow to cut into
5169 /// [`BalanceDetails::total_anchor_channels_reserve_sats`].
5270 ///
71+ /// If `fee_rate` is set it will be used on the resulting transaction. Otherwise we'll retrieve
72+ /// a reasonable estimate from the configured chain source.
73+ ///
5374 /// [`BalanceDetails::total_anchor_channels_reserve_sats`]: crate::BalanceDetails::total_anchor_channels_reserve_sats
5475 pub fn send_to_address (
55- & self , address : & bitcoin:: Address , amount_sats : u64 ,
76+ & self , address : & bitcoin:: Address , amount_sats : u64 , fee_rate : Option < FeeRate > ,
5677 ) -> Result < Txid , Error > {
5778 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
5879 if rt_lock. is_none ( ) {
@@ -63,7 +84,8 @@ impl OnchainPayment {
6384 crate :: total_anchor_channels_reserve_sats ( & self . channel_manager , & self . config ) ;
6485 let send_amount =
6586 OnchainSendAmount :: ExactRetainingReserve { amount_sats, cur_anchor_reserve_sats } ;
66- self . wallet . send_to_address ( address, send_amount)
87+ let fee_rate_opt = maybe_map_fee_rate_opt ! ( fee_rate) ;
88+ self . wallet . send_to_address ( address, send_amount, fee_rate_opt)
6789 }
6890
6991 /// Send an on-chain payment to the given address, draining the available funds.
@@ -77,9 +99,12 @@ impl OnchainPayment {
7799 /// will try to send all spendable onchain funds, i.e.,
78100 /// [`BalanceDetails::spendable_onchain_balance_sats`].
79101 ///
102+ /// If `fee_rate` is set it will be used on the resulting transaction. Otherwise a reasonable
103+ /// we'll retrieve an estimate from the configured chain source.
104+ ///
80105 /// [`BalanceDetails::spendable_onchain_balance_sats`]: crate::balance::BalanceDetails::spendable_onchain_balance_sats
81106 pub fn send_all_to_address (
82- & self , address : & bitcoin:: Address , retain_reserves : bool ,
107+ & self , address : & bitcoin:: Address , retain_reserves : bool , fee_rate : Option < FeeRate > ,
83108 ) -> Result < Txid , Error > {
84109 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
85110 if rt_lock. is_none ( ) {
@@ -94,6 +119,7 @@ impl OnchainPayment {
94119 OnchainSendAmount :: AllDrainingReserve
95120 } ;
96121
97- self . wallet . send_to_address ( address, send_amount)
122+ let fee_rate_opt = maybe_map_fee_rate_opt ! ( fee_rate) ;
123+ self . wallet . send_to_address ( address, send_amount, fee_rate_opt)
98124 }
99125}
0 commit comments