Skip to content

Commit b031161

Browse files
committed
🗑️ clean up legacy code
1 parent ef41a84 commit b031161

File tree

5 files changed

+59
-42
lines changed

5 files changed

+59
-42
lines changed

scripts/demo/test-flow.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fi
102102

103103
# Step 4: Try to access the API with no credits (should get 402)
104104
echo -e "${BLUE}Step 5: Trying to access API with no credits...${NC}"
105-
RESPONSE=$(curl -s -w "%{http_code}" -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/latest-block")
105+
RESPONSE=$(curl -s -w "%{http_code}" -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/block")
106106
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
107107
BODY=$(echo "$RESPONSE" | sed '$d')
108108

src/api/auth.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use axum::{
55
middleware::Next,
66
response::{IntoResponse, Response},
77
};
8-
use axum::extract::FromRef;
98
use tracing::{debug, error};
109

1110
/// Error when authentication fails

src/config/mod.rs

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use dotenv::dotenv;
22
use serde::{Deserialize, Serialize};
33
use std::env;
44
use std::sync::Arc;
5+
use tracing::debug;
56

67
/// Represents a credit purchase offer
78
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -39,12 +40,6 @@ pub struct Config {
3940
pub lnbits_invoice_read_key: Option<String>,
4041
/// LNBits webhook verification key (if using LNBits)
4142
pub lnbits_webhook_key: Option<String>,
42-
/// Legacy: Lightning node REST endpoint (if applicable)
43-
pub lnd_rest_endpoint: Option<String>,
44-
/// Legacy: LND macaroon in hex format (if applicable)
45-
pub lnd_macaroon_hex: Option<String>,
46-
/// Legacy: Path to LND TLS certificate (if applicable)
47-
pub lnd_cert_path: Option<String>,
4843
/// Whether Coinbase payments are enabled
4944
pub coinbase_enabled: bool,
5045
/// Coinbase Commerce API key (if applicable)
@@ -89,37 +84,74 @@ impl Config {
8984
.expect("Failed to parse OFFERS_JSON environment variable");
9085

9186
// Get configuration from environment
92-
let host = env::var("HOST").unwrap_or_else(|_| "127.0.0.1".to_string());
93-
let port = env::var("PORT")
94-
.unwrap_or_else(|_| "8080".to_string())
95-
.parse()
96-
.expect("PORT must be a number");
97-
let redis_url =
98-
env::var("REDIS_URL").unwrap_or_else(|_| "redis://localhost:6379".to_string());
87+
let host = env::var("HOST").unwrap_or_else(|_| {
88+
debug!("HOST not found in environment, using default");
89+
"127.0.0.1".to_string()
90+
});
91+
92+
let port = match env::var("PORT") {
93+
Ok(val) => {
94+
debug!("Found PORT in environment: {}", val);
95+
val.parse().expect("PORT must be a number")
96+
}
97+
Err(_) => {
98+
debug!("PORT not found in environment, using default: 8080");
99+
8080
100+
}
101+
};
102+
103+
let redis_url = env::var("REDIS_URL").unwrap_or_else(|_| {
104+
debug!("REDIS_URL not found in environment, using default");
105+
"redis://localhost:6379".to_string()
106+
});
107+
debug!("REDIS_URL: {}", redis_url);
99108

100109
let lightning_enabled = env::var("LIGHTNING_ENABLED")
101-
.unwrap_or_else(|_| "true".to_string())
102-
.parse()
103-
.unwrap_or(true);
110+
.map(|val| {
111+
debug!("Found LIGHTNING_ENABLED in environment: {}", val);
112+
val.parse().unwrap_or(true)
113+
})
114+
.unwrap_or_else(|_| {
115+
debug!("LIGHTNING_ENABLED not found in environment, using default: true");
116+
true
117+
});
104118

105119
// LNBits configuration
106120
let lnbits_url = env::var("LNBITS_URL").ok();
121+
if let Some(url) = &lnbits_url {
122+
debug!("Found LNBITS_URL: {}", url);
123+
}
107124
let lnbits_admin_key = env::var("LNBITS_ADMIN_KEY").ok();
125+
if lnbits_admin_key.is_some() {
126+
debug!("Found LNBITS_ADMIN_KEY");
127+
}
108128
let lnbits_invoice_read_key = env::var("LNBITS_INVOICE_READ_KEY").ok();
129+
if lnbits_invoice_read_key.is_some() {
130+
debug!("Found LNBITS_INVOICE_READ_KEY");
131+
}
109132
let lnbits_webhook_key = env::var("LNBITS_WEBHOOK_KEY").ok();
110-
111-
// Legacy LND configuration - kept for backward compatibility
112-
let lnd_rest_endpoint = env::var("LND_REST_ENDPOINT").ok();
113-
let lnd_macaroon_hex = env::var("LND_MACAROON_HEX").ok();
114-
let lnd_cert_path = env::var("LND_CERT_PATH").ok();
133+
if lnbits_webhook_key.is_some() {
134+
debug!("Found LNBITS_WEBHOOK_KEY");
135+
}
115136

116137
let coinbase_enabled = env::var("COINBASE_ENABLED")
117-
.unwrap_or_else(|_| "true".to_string())
118-
.parse()
119-
.unwrap_or(true);
138+
.map(|val| {
139+
debug!("Found COINBASE_ENABLED in environment: {}", val);
140+
val.parse().unwrap_or(true)
141+
})
142+
.unwrap_or_else(|_| {
143+
debug!("COINBASE_ENABLED not found in environment, using default: true");
144+
true
145+
});
120146

121147
let coinbase_api_key = env::var("COINBASE_API_KEY").ok();
148+
if coinbase_api_key.is_some() {
149+
debug!("Found COINBASE_API_KEY");
150+
}
122151
let coinbase_webhook_secret = env::var("COINBASE_WEBHOOK_SECRET").ok();
152+
if coinbase_webhook_secret.is_some() {
153+
debug!("Found COINBASE_WEBHOOK_SECRET");
154+
}
123155

124156
Self {
125157
host,
@@ -130,9 +162,6 @@ impl Config {
130162
lnbits_admin_key,
131163
lnbits_invoice_read_key,
132164
lnbits_webhook_key,
133-
lnd_rest_endpoint,
134-
lnd_macaroon_hex,
135-
lnd_cert_path,
136165
coinbase_enabled,
137166
coinbase_api_key,
138167
coinbase_webhook_secret,

src/payments/lightning/mod.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,7 @@ impl LightningProvider {
8585
}
8686
}
8787
} else {
88-
// Check for legacy LND config as fallback
89-
if config.lnd_rest_endpoint.is_none() {
90-
return Err(LightningError::ConfigError(
91-
"Neither LNBits nor LND configuration provided".to_string(),
92-
));
93-
}
94-
95-
// Using legacy LND client (not supported in this implementation)
96-
error!("Legacy LND REST API no longer supported - please use LNBits");
97-
return Err(LightningError::ConfigError(
98-
"Legacy LND REST API no longer supported - please use LNBits".to_string(),
99-
));
88+
None
10089
};
10190

10291
Ok(Self {

src/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static HTTP_CLIENT: Lazy<Client> = Lazy::new(Client::new);
5353
/// Convert USD amount to satoshis using current market rate from Kraken
5454
pub async fn convert_usd_to_sats(amount_usd: f64) -> Result<u64, ConversionError> {
5555
let cache_duration = Duration::seconds(600); // 10 minutes
56-
56+
5757
// We need to check if update is needed and get the current value in separate blocks
5858
// to avoid holding the mutex across .await points (which would make the future !Send)
5959
let needs_update = {

0 commit comments

Comments
 (0)