@@ -109,6 +109,13 @@ pub enum Command {
109109 #[ arg( long, help = "Amount is sats or the string \" all\" " ) ]
110110 amount_sat : model:: AmountSatOrAll ,
111111 } ,
112+ /// Open a channel with peer
113+ Fundchannel {
114+ #[ arg( long, help = "Peer id" ) ]
115+ id : String ,
116+ #[ arg( long, help = "Amount in sats or the string \" all\" " ) ]
117+ amount_sat : model:: AmountSatOrAll ,
118+ } ,
112119 /// Close a channel with peer
113120 Close {
114121 #[ arg( long, help = "Peer id, channel id or short channel id" ) ]
@@ -216,6 +223,9 @@ pub async fn command_handler<P: AsRef<Path>>(cmd: Command, config: Config<P>) ->
216223 destination,
217224 amount_sat,
218225 } => withdraw_handler ( config, destination, amount_sat) . await ,
226+ Command :: Fundchannel { id, amount_sat } => {
227+ fundchannel_handler ( config, id, amount_sat) . await
228+ }
219229 Command :: Close { id } => close_handler ( config, id) . await ,
220230 Command :: Stop => stop ( config) . await ,
221231 }
@@ -356,6 +366,37 @@ async fn withdraw_handler<P: AsRef<Path>>(
356366 Ok ( ( ) )
357367}
358368
369+ async fn fundchannel_handler < P : AsRef < Path > > (
370+ config : Config < P > ,
371+ id : String ,
372+ amount_sat : model:: AmountSatOrAll ,
373+ ) -> Result < ( ) > {
374+ let mut node: gl_client:: node:: ClnClient = get_node ( config) . await ?;
375+ let id_bytes = hex:: FromHex :: from_hex ( & id)
376+ . map_err ( |e| Error :: custom ( format ! ( "Invalid hex string: {id}. {e}" ) ) ) ?;
377+ let res = node
378+ . fund_channel ( cln:: FundchannelRequest {
379+ id : id_bytes,
380+ amount : Some ( amount_sat. into ( ) ) ,
381+ feerate : None ,
382+ announce : None ,
383+ minconf : None ,
384+ push_msat : None ,
385+ close_to : None ,
386+ request_amt : None ,
387+ compact_lease : None ,
388+ utxos : vec ! [ ] ,
389+ mindepth : None ,
390+ reserve : None ,
391+ channel_type : vec ! [ ] ,
392+ } )
393+ . await
394+ . map_err ( |e| Error :: custom ( e. message ( ) ) ) ?
395+ . into_inner ( ) ;
396+ println ! ( "{:?}" , res) ;
397+ Ok ( ( ) )
398+ }
399+
359400async fn close_handler < P : AsRef < Path > > ( config : Config < P > , id : String ) -> Result < ( ) > {
360401 let mut node: gl_client:: node:: ClnClient = get_node ( config) . await ?;
361402 let res = node
0 commit comments