@@ -202,6 +202,81 @@ pub async fn get_info_async(config: &LndConfig) -> Result<NodeInfo, ApiError> {
202202 Ok ( node_info)
203203}
204204
205+ #[ cfg_attr( feature = "uniffi" , uniffi:: export) ]
206+ pub async fn lnd_get_info_async ( config : LndConfig ) -> Result < NodeInfo , ApiError > {
207+ let req_url = format ! ( "{}/v1/getinfo" , config. url) ;
208+ let client = async_client ( & config) ;
209+
210+ let response = client. get ( & req_url) . send ( ) . await
211+ . map_err ( |e| ApiError :: Json { reason : format ! ( "Failed to send request: {}" , e) } ) ?;
212+
213+ let response_text = response. text ( ) . await
214+ . map_err ( |e| ApiError :: Json { reason : format ! ( "Failed to read response text: {}" , e) } ) ?;
215+
216+ let info: GetInfoResponse = serde_json:: from_str ( & response_text) ?;
217+
218+ // get balance
219+ // /v1/balance/channels
220+ // https://lightning.engineering/api-docs/api/lnd/lightning/channel-balance/
221+ // send_balance_msats, receive_balance_msats, pending_balance, inactive_balance
222+ let balance_url = format ! ( "{}/v1/balance/channels" , config. url) ;
223+
224+ let balance_response = client. get ( & balance_url) . send ( ) . await
225+ . map_err ( |e| ApiError :: Json { reason : format ! ( "Failed to send balance request: {}" , e) } ) ?;
226+
227+ let balance_response_text = balance_response. text ( ) . await
228+ . map_err ( |e| ApiError :: Json { reason : format ! ( "Failed to read balance response text: {}" , e) } ) ?;
229+
230+ let balance: BalancesResponse = serde_json:: from_str ( & balance_response_text) ?;
231+
232+ let node_info = NodeInfo {
233+ alias : info. alias ,
234+ color : info. color ,
235+ pubkey : info. identity_pubkey ,
236+ network : info. chains [ 0 ] . network . clone ( ) ,
237+ block_height : info. block_height ,
238+ block_hash : info. block_hash ,
239+ send_balance_msat : balance
240+ . local_balance
241+ . msat
242+ . unwrap_or_default ( )
243+ . parse :: < i64 > ( )
244+ . unwrap_or_default ( ) ,
245+ receive_balance_msat : balance
246+ . remote_balance
247+ . msat
248+ . unwrap_or_default ( )
249+ . parse :: < i64 > ( )
250+ . unwrap_or_default ( ) ,
251+ unsettled_send_balance_msat : balance
252+ . unsettled_local_balance
253+ . msat
254+ . unwrap_or_default ( )
255+ . parse :: < i64 > ( )
256+ . unwrap_or_default ( ) ,
257+ unsettled_receive_balance_msat : balance
258+ . unsettled_remote_balance
259+ . msat
260+ . unwrap_or_default ( )
261+ . parse :: < i64 > ( )
262+ . unwrap_or_default ( ) ,
263+ pending_open_send_balance : balance
264+ . pending_open_local_balance
265+ . msat
266+ . unwrap_or_default ( )
267+ . parse :: < i64 > ( )
268+ . unwrap_or_default ( ) ,
269+ pending_open_receive_balance : balance
270+ . pending_open_remote_balance
271+ . msat
272+ . unwrap_or_default ( )
273+ . parse :: < i64 > ( )
274+ . unwrap_or_default ( ) ,
275+ ..Default :: default ( )
276+ } ;
277+ Ok ( node_info)
278+ }
279+
205280pub fn create_invoice (
206281 config : & LndConfig ,
207282 invoice_params : CreateInvoiceParams ,
0 commit comments