@@ -2,6 +2,7 @@ use dotenv::dotenv;
2
2
use serde:: { Deserialize , Serialize } ;
3
3
use std:: env;
4
4
use std:: sync:: Arc ;
5
+ use tracing:: debug;
5
6
6
7
/// Represents a credit purchase offer
7
8
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -39,12 +40,6 @@ pub struct Config {
39
40
pub lnbits_invoice_read_key : Option < String > ,
40
41
/// LNBits webhook verification key (if using LNBits)
41
42
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 > ,
48
43
/// Whether Coinbase payments are enabled
49
44
pub coinbase_enabled : bool ,
50
45
/// Coinbase Commerce API key (if applicable)
@@ -89,37 +84,74 @@ impl Config {
89
84
. expect ( "Failed to parse OFFERS_JSON environment variable" ) ;
90
85
91
86
// 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) ;
99
108
100
109
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
+ } ) ;
104
118
105
119
// LNBits configuration
106
120
let lnbits_url = env:: var ( "LNBITS_URL" ) . ok ( ) ;
121
+ if let Some ( url) = & lnbits_url {
122
+ debug ! ( "Found LNBITS_URL: {}" , url) ;
123
+ }
107
124
let lnbits_admin_key = env:: var ( "LNBITS_ADMIN_KEY" ) . ok ( ) ;
125
+ if lnbits_admin_key. is_some ( ) {
126
+ debug ! ( "Found LNBITS_ADMIN_KEY" ) ;
127
+ }
108
128
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
+ }
109
132
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
+ }
115
136
116
137
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
+ } ) ;
120
146
121
147
let coinbase_api_key = env:: var ( "COINBASE_API_KEY" ) . ok ( ) ;
148
+ if coinbase_api_key. is_some ( ) {
149
+ debug ! ( "Found COINBASE_API_KEY" ) ;
150
+ }
122
151
let coinbase_webhook_secret = env:: var ( "COINBASE_WEBHOOK_SECRET" ) . ok ( ) ;
152
+ if coinbase_webhook_secret. is_some ( ) {
153
+ debug ! ( "Found COINBASE_WEBHOOK_SECRET" ) ;
154
+ }
123
155
124
156
Self {
125
157
host,
@@ -130,9 +162,6 @@ impl Config {
130
162
lnbits_admin_key,
131
163
lnbits_invoice_read_key,
132
164
lnbits_webhook_key,
133
- lnd_rest_endpoint,
134
- lnd_macaroon_hex,
135
- lnd_cert_path,
136
165
coinbase_enabled,
137
166
coinbase_api_key,
138
167
coinbase_webhook_secret,
0 commit comments