@@ -244,6 +244,81 @@ pub async fn get_balance(
244244 Ok ( Json ( json ! ( balance) ) )
245245}
246246
247+ #[ derive( Serialize ) ]
248+ #[ serde( rename_all = "camelCase" ) ]
249+ pub struct NodeInfoResponse {
250+ node_id : String ,
251+ channels : Vec < Channel > ,
252+ }
253+
254+ #[ derive( Serialize ) ]
255+ #[ serde( rename_all = "camelCase" ) ]
256+ struct Channel {
257+ state : String ,
258+ channel_id : String ,
259+ balance_sat : u64 ,
260+ inbound_liquidity_sat : u64 ,
261+ capacity_sat : u64 ,
262+ funding_tx_id : Option < String > ,
263+ }
264+
265+ pub async fn get_node_info (
266+ Extension ( state) : Extension < State > ,
267+ ) -> Result < Json < Value > , ( StatusCode , Json < Value > ) > {
268+ let nodes = state
269+ . mutiny_wallet
270+ . node_manager
271+ . list_nodes ( )
272+ . await
273+ . map_err ( |e| handle_mutiny_err ( e) ) ?;
274+ let node_pubkey: PublicKey ;
275+ if !nodes. is_empty ( ) {
276+ node_pubkey = nodes[ 0 ] ;
277+ } else {
278+ return Err ( (
279+ StatusCode :: INTERNAL_SERVER_ERROR ,
280+ Json ( json ! ( { "error" : "unable to get node info" } ) ) ,
281+ ) ) ;
282+ }
283+
284+ let channels = state
285+ . mutiny_wallet
286+ . node_manager
287+ . list_channels ( )
288+ . await
289+ . map_err ( |e| handle_mutiny_err ( e) ) ?;
290+ let channels = channels
291+ . into_iter ( )
292+ . map ( |channel| {
293+ let state = match channel. is_usable {
294+ true => "usable" ,
295+ false => "unusable" ,
296+ }
297+ . to_string ( ) ;
298+ let funding_tx_id = match channel. outpoint {
299+ Some ( outpoint) => Some ( outpoint. txid . to_string ( ) ) ,
300+ None => None ,
301+ } ;
302+
303+ Channel {
304+ state,
305+ channel_id : channel. user_chan_id ,
306+ balance_sat : channel. balance ,
307+ inbound_liquidity_sat : channel. inbound ,
308+ capacity_sat : channel. size ,
309+ funding_tx_id,
310+ }
311+ } )
312+ . collect ( ) ;
313+
314+ let node_info = NodeInfoResponse {
315+ node_id : node_pubkey. to_string ( ) ,
316+ channels,
317+ } ;
318+
319+ Ok ( Json ( json ! ( node_info) ) )
320+ }
321+
247322fn handle_mutiny_err ( err : MutinyError ) -> ( StatusCode , Json < Value > ) {
248323 let err = json ! ( {
249324 "error" : format!( "{err}" ) ,
0 commit comments