@@ -17,6 +17,24 @@ use bitcoin::{Address, Txid};
17
17
18
18
use std:: sync:: { Arc , RwLock } ;
19
19
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
+
20
38
/// A payment handler allowing to send and receive on-chain payments.
21
39
///
22
40
/// Should be retrieved by calling [`Node::onchain_payment`].
@@ -50,9 +68,12 @@ impl OnchainPayment {
50
68
/// This will respect any on-chain reserve we need to keep, i.e., won't allow to cut into
51
69
/// [`BalanceDetails::total_anchor_channels_reserve_sats`].
52
70
///
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
+ ///
53
74
/// [`BalanceDetails::total_anchor_channels_reserve_sats`]: crate::BalanceDetails::total_anchor_channels_reserve_sats
54
75
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 > ,
56
77
) -> Result < Txid , Error > {
57
78
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
58
79
if rt_lock. is_none ( ) {
@@ -63,7 +84,8 @@ impl OnchainPayment {
63
84
crate :: total_anchor_channels_reserve_sats ( & self . channel_manager , & self . config ) ;
64
85
let send_amount =
65
86
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)
67
89
}
68
90
69
91
/// Send an on-chain payment to the given address, draining the available funds.
@@ -77,9 +99,12 @@ impl OnchainPayment {
77
99
/// will try to send all spendable onchain funds, i.e.,
78
100
/// [`BalanceDetails::spendable_onchain_balance_sats`].
79
101
///
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
+ ///
80
105
/// [`BalanceDetails::spendable_onchain_balance_sats`]: crate::balance::BalanceDetails::spendable_onchain_balance_sats
81
106
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 > ,
83
108
) -> Result < Txid , Error > {
84
109
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
85
110
if rt_lock. is_none ( ) {
@@ -94,6 +119,7 @@ impl OnchainPayment {
94
119
OnchainSendAmount :: AllDrainingReserve
95
120
} ;
96
121
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)
98
124
}
99
125
}
0 commit comments