bright_lightning/lnd/models/
info.rs1use serde::{Deserialize, Serialize};
2use std::{collections::HashMap, fmt::Display};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct Chain {
6 pub chain: String,
7 pub network: String,
8}
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct Feature {
11 pub name: String,
12 pub is_required: bool,
13 pub is_known: bool,
14}
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct FeaturesEntry {
17 pub key: u32,
18 pub value: Feature,
19}
20#[allow(clippy::struct_excessive_bools)]
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct LndInfo {
23 pub version: String,
24 pub commit_hash: String,
25 pub identity_pubkey: String,
26 pub alias: String,
27 pub color: String,
28 pub num_pending_channels: u32,
29 pub num_active_channels: u32,
30 pub num_inactive_channels: u32,
31 pub num_peers: u32,
32 pub block_height: u32,
33 pub block_hash: String,
34 pub best_header_timestamp: String,
35 pub synced_to_chain: bool,
36 pub synced_to_graph: bool,
37 pub testnet: bool,
38 pub chains: Vec<Chain>,
39 pub uris: Vec<String>,
40 pub features: HashMap<String, Feature>,
41 pub require_htlc_interceptor: bool,
42 pub store_final_htlc_resolutions: bool,
43}
44
45impl TryFrom<&str> for LndInfo {
46 type Error = anyhow::Error;
47 fn try_from(value: &str) -> Result<Self, Self::Error> {
48 Ok(serde_json::from_str(value)?)
49 }
50}
51impl TryFrom<&String> for LndInfo {
52 type Error = anyhow::Error;
53 fn try_from(value: &String) -> Result<Self, Self::Error> {
54 Ok(serde_json::from_str(value)?)
55 }
56}
57impl TryFrom<String> for LndInfo {
58 type Error = anyhow::Error;
59 fn try_from(value: String) -> Result<Self, Self::Error> {
60 Ok(serde_json::from_str(&value)?)
61 }
62}
63impl Display for LndInfo {
64 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65 write!(f, "{}", serde_json::to_string_pretty(self).unwrap())
66 }
67}