From b58637d63d9e21f7242de56480ead892c9c048ad Mon Sep 17 00:00:00 2001 From: spacesops Date: Tue, 5 May 2026 22:57:56 -0400 Subject: [PATCH] fix: use configured RPC proxy credentials and print startup URL Wire spaced RPC user/password from CLI into AppState so /rpc/spaced no longer uses hardcoded credentials, and add a clear startup console URL that includes the port. Co-authored-by: Cursor --- subs/src/main.rs | 37 +++++++++++++++++++++++++++++++++---- subs/src/routes/console.rs | 7 ++++++- subs/src/state.rs | 16 ++++++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/subs/src/main.rs b/subs/src/main.rs index 51e99d7..0517ff7 100644 --- a/subs/src/main.rs +++ b/subs/src/main.rs @@ -85,7 +85,7 @@ async fn main() -> Result<()> { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "subsd=info,tower_http=debug".into()), + .unwrap_or_else(|_| "subs=info,tower_http=debug".into()), ) .with(tracing_subscriber::fmt::layer()) .init(); @@ -150,7 +150,16 @@ async fn run_normal(cli: Cli) -> Result<()> { operator.load_all_spaces().await?; // Build app state and run server - run_server(operator, config, cli.port, Some(rpc_url.clone()), None).await + run_server( + operator, + config, + cli.port, + Some(rpc_url.clone()), + cli.rpc_user.clone(), + cli.rpc_password.clone(), + None, + ) + .await } #[cfg(feature = "test-rig")] @@ -226,10 +235,19 @@ async fn run_server( config: ConfigStore, port: u16, spaced_rpc_url: Option, + spaced_rpc_user: Option, + spaced_rpc_password: Option, bitcoin_rpc_url: Option, ) -> Result<()> { // Build app state - let state = AppState::with_rpc_urls(operator, config, spaced_rpc_url, bitcoin_rpc_url); + let state = AppState::with_rpc_urls( + operator, + config, + spaced_rpc_url, + spaced_rpc_user, + spaced_rpc_password, + bitcoin_rpc_url, + ); run_server_inner(state, port).await } @@ -244,7 +262,16 @@ async fn run_server_with_testrig( test_rig: std::sync::Arc, ) -> Result<()> { // Build app state with test rig - let state = AppState::with_test_rig(operator, config, Some(spaced_rpc_url), Some(bitcoin_rpc_url), Some(certrelay_url), test_rig); + let state = AppState::with_test_rig( + operator, + config, + Some(spaced_rpc_url), + Some("user".to_string()), + Some("pass".to_string()), + Some(bitcoin_rpc_url), + Some(certrelay_url), + test_rig, + ); run_server_inner(state, port).await } @@ -266,6 +293,8 @@ async fn run_server_inner(state: AppState, port: u16) -> Result<()> { // Start server let addr = SocketAddr::from(([0, 0, 0, 0], port)); tracing::info!("Starting server on http://{}", addr); + tracing::info!("Server URL: http://127.0.0.1:{}", port); + println!("Server URL: http://127.0.0.1:{} (port {})", port, port); let listener = tokio::net::TcpListener::bind(addr).await?; axum::serve(listener, app) diff --git a/subs/src/routes/console.rs b/subs/src/routes/console.rs index 9e1376a..9e585ba 100644 --- a/subs/src/routes/console.rs +++ b/subs/src/routes/console.rs @@ -84,7 +84,12 @@ pub async fn proxy_spaced( .as_ref() .ok_or_else(|| json_error(StatusCode::SERVICE_UNAVAILABLE, "Spaced RPC URL not configured"))?; - proxy_rpc_call(rpc_url, &request, Some(("user", "pass"))).await + let auth = state + .spaced_rpc_user + .as_deref() + .map(|user| (user, state.spaced_rpc_password.as_deref().unwrap_or(""))); + + proxy_rpc_call(rpc_url, &request, auth).await } /// POST /rpc/bitcoin - Proxy RPC call to bitcoind (test-rig only) diff --git a/subs/src/state.rs b/subs/src/state.rs index 2868d71..5f03320 100644 --- a/subs/src/state.rs +++ b/subs/src/state.rs @@ -16,6 +16,10 @@ pub struct AppState { pub config: Arc, /// Spaced RPC URL for the console pub spaced_rpc_url: Option, + /// Spaced RPC username for proxied calls + pub spaced_rpc_user: Option, + /// Spaced RPC password for proxied calls + pub spaced_rpc_password: Option, /// Bitcoin RPC URL (only available in test-rig mode) pub bitcoin_rpc_url: Option, /// Certrelay URL (only available in test-rig mode) @@ -31,12 +35,16 @@ impl AppState { operator: Operator, config: ConfigStore, spaced_rpc_url: Option, + spaced_rpc_user: Option, + spaced_rpc_password: Option, _bitcoin_rpc_url: Option, ) -> Self { Self { operator: Arc::new(operator), config: Arc::new(config), spaced_rpc_url, + spaced_rpc_user, + spaced_rpc_password, bitcoin_rpc_url: None, certrelay_url: None, } @@ -47,12 +55,16 @@ impl AppState { operator: Operator, config: ConfigStore, spaced_rpc_url: Option, + spaced_rpc_user: Option, + spaced_rpc_password: Option, bitcoin_rpc_url: Option, ) -> Self { Self { operator: Arc::new(operator), config: Arc::new(config), spaced_rpc_url, + spaced_rpc_user, + spaced_rpc_password, bitcoin_rpc_url, certrelay_url: None, test_rig: None, @@ -64,6 +76,8 @@ impl AppState { operator: Operator, config: ConfigStore, spaced_rpc_url: Option, + spaced_rpc_user: Option, + spaced_rpc_password: Option, bitcoin_rpc_url: Option, certrelay_url: Option, test_rig: Arc, @@ -72,6 +86,8 @@ impl AppState { operator: Arc::new(operator), config: Arc::new(config), spaced_rpc_url, + spaced_rpc_user, + spaced_rpc_password, bitcoin_rpc_url, certrelay_url, test_rig: Some(test_rig),