@@ -11,7 +11,8 @@ use ldk_server_client::ldk_server_protos::api::{
1111 OpenChannelRequest ,
1212} ;
1313use ldk_server_client:: ldk_server_protos:: types:: {
14- bolt11_invoice_description, Bolt11InvoiceDescription , PageToken , Payment ,
14+ bolt11_invoice_description, channel_config, Bolt11InvoiceDescription , ChannelConfig , PageToken ,
15+ Payment ,
1516} ;
1617use std:: fmt:: Debug ;
1718
@@ -101,6 +102,29 @@ enum Commands {
101102 push_to_counterparty_msat : Option < u64 > ,
102103 #[ arg( long) ]
103104 announce_channel : bool ,
105+ // Channel config options
106+ #[ arg( long, help = "Forwarding fee proportional (in millionths of a satoshi)" ) ]
107+ forwarding_fee_proportional_millionths : Option < u32 > ,
108+ #[ arg( long, help = "Forwarding fee base (in milli-satoshi)" ) ]
109+ forwarding_fee_base_msat : Option < u32 > ,
110+ #[ arg( long, help = "CLTV expiry delta" ) ]
111+ cltv_expiry_delta : Option < u32 > ,
112+ #[ arg( long, help = "Force close avoidance max fee (in satoshis)" ) ]
113+ force_close_avoidance_max_fee_satoshis : Option < u64 > ,
114+ #[ arg( long, help = "Accept underpaying HTLCs" ) ]
115+ accept_underpaying_htlcs : Option < bool > ,
116+ #[ arg(
117+ long,
118+ help = "Max dust HTLC exposure as fixed limit (in milli-satoshi)" ,
119+ conflicts_with = "max_dust_htlc_fee_rate_multiplier"
120+ ) ]
121+ max_dust_htlc_fixed_limit_msat : Option < u64 > ,
122+ #[ arg(
123+ long,
124+ help = "Max dust HTLC exposure as fee rate multiplier" ,
125+ conflicts_with = "max_dust_htlc_fixed_limit_msat"
126+ ) ]
127+ max_dust_htlc_fee_rate_multiplier : Option < u64 > ,
104128 } ,
105129 ListChannels ,
106130 ListPayments {
@@ -213,15 +237,32 @@ async fn main() {
213237 channel_amount_sats,
214238 push_to_counterparty_msat,
215239 announce_channel,
240+ forwarding_fee_proportional_millionths,
241+ forwarding_fee_base_msat,
242+ cltv_expiry_delta,
243+ force_close_avoidance_max_fee_satoshis,
244+ accept_underpaying_htlcs,
245+ max_dust_htlc_fixed_limit_msat,
246+ max_dust_htlc_fee_rate_multiplier,
216247 } => {
248+ let channel_config = build_channel_config (
249+ forwarding_fee_proportional_millionths,
250+ forwarding_fee_base_msat,
251+ cltv_expiry_delta,
252+ force_close_avoidance_max_fee_satoshis,
253+ accept_underpaying_htlcs,
254+ max_dust_htlc_fixed_limit_msat,
255+ max_dust_htlc_fee_rate_multiplier,
256+ ) ;
257+
217258 handle_response_result (
218259 client
219260 . open_channel ( OpenChannelRequest {
220261 node_pubkey,
221262 address,
222263 channel_amount_sats,
223264 push_to_counterparty_msat,
224- channel_config : None ,
265+ channel_config,
225266 announce_channel,
226267 } )
227268 . await ,
@@ -236,6 +277,52 @@ async fn main() {
236277 }
237278}
238279
280+ fn build_channel_config (
281+ forwarding_fee_proportional_millionths : Option < u32 > , forwarding_fee_base_msat : Option < u32 > ,
282+ cltv_expiry_delta : Option < u32 > , force_close_avoidance_max_fee_satoshis : Option < u64 > ,
283+ accept_underpaying_htlcs : Option < bool > , max_dust_htlc_fixed_limit_msat : Option < u64 > ,
284+ max_dust_htlc_fee_rate_multiplier : Option < u64 > ,
285+ ) -> Option < ChannelConfig > {
286+ // Only create a config if at least one field is set
287+ if forwarding_fee_proportional_millionths. is_none ( )
288+ && forwarding_fee_base_msat. is_none ( )
289+ && cltv_expiry_delta. is_none ( )
290+ && force_close_avoidance_max_fee_satoshis. is_none ( )
291+ && accept_underpaying_htlcs. is_none ( )
292+ && max_dust_htlc_fixed_limit_msat. is_none ( )
293+ && max_dust_htlc_fee_rate_multiplier. is_none ( )
294+ {
295+ return None ;
296+ }
297+
298+ let max_dust_htlc_exposure = match (
299+ max_dust_htlc_fixed_limit_msat,
300+ max_dust_htlc_fee_rate_multiplier,
301+ ) {
302+ ( Some ( _) , Some ( _) ) => {
303+ // This case should be unreachable due to clap's conflict_with enforcement, but we handle it just in case.
304+ handle_error ( LdkServerError :: new (
305+ InvalidRequestError ,
306+ "Only one of max_dust_htlc_fixed_limit_msat or max_dust_htlc_fee_rate_multiplier can be set." . to_string ( ) ,
307+ ) ) ;
308+ } ,
309+ ( Some ( limit) , None ) => Some ( channel_config:: MaxDustHtlcExposure :: FixedLimitMsat ( limit) ) ,
310+ ( None , Some ( multiplier) ) => {
311+ Some ( channel_config:: MaxDustHtlcExposure :: FeeRateMultiplier ( multiplier) )
312+ } ,
313+ ( None , None ) => None ,
314+ } ;
315+
316+ Some ( ChannelConfig {
317+ forwarding_fee_proportional_millionths,
318+ forwarding_fee_base_msat,
319+ cltv_expiry_delta,
320+ force_close_avoidance_max_fee_satoshis,
321+ accept_underpaying_htlcs,
322+ max_dust_htlc_exposure,
323+ } )
324+ }
325+
239326async fn list_n_payments (
240327 client : LdkServerClient , number_of_payments : Option < u64 > ,
241328) -> Result < Vec < Payment > , LdkServerError > {
0 commit comments