Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions subs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -226,10 +235,19 @@ async fn run_server(
config: ConfigStore,
port: u16,
spaced_rpc_url: Option<String>,
spaced_rpc_user: Option<String>,
spaced_rpc_password: Option<String>,
bitcoin_rpc_url: Option<String>,
) -> 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
}

Expand All @@ -244,7 +262,16 @@ async fn run_server_with_testrig(
test_rig: std::sync::Arc<testrig::TestRigHandle>,
) -> 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
}

Expand All @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion subs/src/routes/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions subs/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub struct AppState {
pub config: Arc<ConfigStore>,
/// Spaced RPC URL for the console
pub spaced_rpc_url: Option<String>,
/// Spaced RPC username for proxied calls
pub spaced_rpc_user: Option<String>,
/// Spaced RPC password for proxied calls
pub spaced_rpc_password: Option<String>,
/// Bitcoin RPC URL (only available in test-rig mode)
pub bitcoin_rpc_url: Option<String>,
/// Certrelay URL (only available in test-rig mode)
Expand All @@ -31,12 +35,16 @@ impl AppState {
operator: Operator,
config: ConfigStore,
spaced_rpc_url: Option<String>,
spaced_rpc_user: Option<String>,
spaced_rpc_password: Option<String>,
_bitcoin_rpc_url: Option<String>,
) -> 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,
}
Expand All @@ -47,12 +55,16 @@ impl AppState {
operator: Operator,
config: ConfigStore,
spaced_rpc_url: Option<String>,
spaced_rpc_user: Option<String>,
spaced_rpc_password: Option<String>,
bitcoin_rpc_url: Option<String>,
) -> 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,
Expand All @@ -64,6 +76,8 @@ impl AppState {
operator: Operator,
config: ConfigStore,
spaced_rpc_url: Option<String>,
spaced_rpc_user: Option<String>,
spaced_rpc_password: Option<String>,
bitcoin_rpc_url: Option<String>,
certrelay_url: Option<String>,
test_rig: Arc<TestRigHandle>,
Expand All @@ -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),
Expand Down