lnbits_rs/api/
wallet.rs

1//! Wallet related api
2
3use anyhow::{bail, Result};
4use serde::{Deserialize, Serialize};
5
6use super::LNBitsEndpoint;
7
8/// Wallet details
9#[derive(Debug, Serialize, Deserialize)]
10pub struct WalletDetails {
11    /// Documented as "id" in the API docs, but is actually not sent
12    pub id: Option<String>,
13    /// Name
14    pub name: String,
15}
16
17impl crate::LNBitsClient {
18    /// Get wallet details
19    pub async fn get_wallet_details(&self) -> Result<WalletDetails> {
20        let body = self
21            .make_get(
22                LNBitsEndpoint::Wallet,
23                crate::api::LNBitsRequestKey::InvoiceRead,
24            )
25            .await?;
26        match serde_json::from_str(&body) {
27            Ok(res) => Ok(res),
28            Err(_) => {
29                log::error!("Api error response on get wallet details");
30                log::error!("{}", body);
31                bail!("Could not get wallet details")
32            }
33        }
34    }
35}