Skip to content

Commit 5176dde

Browse files
Copilotntheile
andcommitted
Fix AlbyInfoResponse structure and handle missing nodeAlias
Co-authored-by: ntheile <1273575+ntheile@users.noreply.github.com>
1 parent 0d7f430 commit 5176dde

2 files changed

Lines changed: 59 additions & 36 deletions

File tree

crates/lni/alby/api.rs

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -107,41 +107,29 @@ pub async fn get_info(config: AlbyConfig) -> Result<NodeInfo, ApiError> {
107107
reason: e.to_string(),
108108
})?;
109109

110-
// Get balance from Alby Hub API
110+
// Get balance from Alby Hub API (this is optional, as balance might not be available)
111111
let balance_response = client
112112
.get(&format!("{}/balances", get_base_url(&config)))
113113
.send()
114-
.await
115-
.map_err(|e| ApiError::Http {
116-
reason: e.to_string(),
117-
})?;
118-
119-
if !balance_response.status().is_success() {
120-
let status = balance_response.status();
121-
let error_text = balance_response.text().await.unwrap_or_default();
122-
return Err(ApiError::Http {
123-
reason: format!("HTTP {} - {}", status, error_text),
124-
});
125-
}
126-
127-
let balances: AlbyBalancesResponse = balance_response.json().await.map_err(|e| ApiError::Json {
128-
reason: e.to_string(),
129-
})?;
114+
.await;
130115

131-
// Convert Alby balance to msat (assuming it's in sats)
132-
let balance_msat = balances.balances
133-
.iter()
134-
.find(|b| b.currency == "btc" || b.currency == "sats")
135-
.map(|b| b.balance * 1000)
136-
.unwrap_or(0);
116+
let balance_msat = match balance_response {
117+
Ok(response) if response.status().is_success() => {
118+
match response.json::<AlbyBalancesResponse>().await {
119+
Ok(balances) => balances.balance.unwrap_or(0) * 1000, // Convert sats to msats
120+
Err(_) => 0, // If parsing fails, default to 0
121+
}
122+
}
123+
_ => 0, // If request fails, default to 0
124+
};
137125

138126
Ok(NodeInfo {
139-
alias: info.alias,
140-
color: info.color,
141-
pubkey: info.pubkey,
127+
alias: info.node_alias.unwrap_or_else(|| "Alby Hub".to_string()),
128+
color: "".to_string(), // Alby Hub doesn't provide color
129+
pubkey: "".to_string(), // Alby Hub doesn't provide pubkey in info endpoint
142130
network: info.network,
143-
block_height: info.block_height,
144-
block_hash: info.block_hash,
131+
block_height: 0, // Alby Hub doesn't provide block height in info endpoint
132+
block_hash: "".to_string(), // Alby Hub doesn't provide block hash in info endpoint
145133
send_balance_msat: balance_msat,
146134
receive_balance_msat: 0, // Alby Hub doesn't distinguish send/receive balance
147135
..Default::default()

crates/lni/alby/types.rs

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,59 @@ use serde::Deserialize;
22

33
#[derive(Debug, Deserialize)]
44
pub struct AlbyInfoResponse {
5-
pub alias: String,
6-
pub color: String,
7-
pub pubkey: String,
8-
pub network: String,
9-
pub block_height: i64,
10-
pub block_hash: String,
5+
#[serde(rename = "backendType")]
6+
pub backend_type: String,
7+
#[serde(rename = "setupCompleted")]
8+
pub setup_completed: bool,
9+
#[serde(rename = "oauthRedirect")]
10+
pub oauth_redirect: bool,
11+
pub running: bool,
12+
pub unlocked: bool,
13+
#[serde(rename = "albyAuthUrl")]
14+
pub alby_auth_url: String,
15+
#[serde(rename = "nextBackupReminder")]
16+
pub next_backup_reminder: String,
17+
#[serde(rename = "albyUserIdentifier")]
18+
pub alby_user_identifier: String,
19+
#[serde(rename = "albyAccountConnected")]
20+
pub alby_account_connected: bool,
1121
pub version: String,
22+
pub network: String,
23+
#[serde(rename = "enableAdvancedSetup")]
24+
pub enable_advanced_setup: bool,
25+
#[serde(rename = "ldkVssEnabled")]
26+
pub ldk_vss_enabled: bool,
27+
#[serde(rename = "vssSupported")]
28+
pub vss_supported: bool,
29+
#[serde(rename = "startupState")]
30+
pub startup_state: String,
31+
#[serde(rename = "startupError")]
32+
pub startup_error: String,
33+
#[serde(rename = "startupErrorTime")]
34+
pub startup_error_time: String,
35+
#[serde(rename = "autoUnlockPasswordSupported")]
36+
pub auto_unlock_password_supported: bool,
37+
#[serde(rename = "autoUnlockPasswordEnabled")]
38+
pub auto_unlock_password_enabled: bool,
39+
pub currency: String,
40+
pub relay: String,
41+
#[serde(rename = "nodeAlias")]
42+
pub node_alias: Option<String>, // This can be empty/missing, so using Option
43+
#[serde(rename = "mempoolUrl")]
44+
pub mempool_url: String,
1245
}
1346

1447
#[derive(Debug, Deserialize)]
1548
pub struct AlbyBalance {
1649
pub balance: i64,
17-
pub currency: String,
1850
}
1951

2052
#[derive(Debug, Deserialize)]
2153
pub struct AlbyBalancesResponse {
22-
pub balances: Vec<AlbyBalance>,
54+
#[serde(rename = "balance")]
55+
pub balance: Option<i64>,
56+
#[serde(rename = "unit")]
57+
pub unit: Option<String>,
2358
}
2459

2560
#[derive(Debug, Deserialize)]

0 commit comments

Comments
 (0)