chore(ci): rustfmt + clippy clean-up to unblock the Rust CI job
The .github/workflows/ci.yml Rust job runs cargo fmt --check, clippy
with -D warnings, and tests. All three were failing. This commit:
- Applies rustfmt across the tree (the bulk of the diff — untouched
since the last toolchain bump, so a wide sweep was unavoidable).
- Fixes the correctness-level clippy errors:
container/bitcoin_simulator.rs wildcard-in-or-pattern
container/manifest.rs from_str rename to parse (reserved name)
container/podman_client.rs .get(0) -> .first()
container/runtime.rs manual += collapse
archipelago/src/constants.rs doc-comment → module-doc
api/rpc/package/install.rs stray /// comment above a non-item
container/docker_packages.rs redundant field init
streaming/advertisement.rs missing Metric import in tests
tests/orchestration_tests.rs `vec!` in non-Vec contexts
mesh/listener/dispatch.rs unused store_plain_message import
api/rpc/tor/mod.rs and mesh/steganography.rs: push-after-new → vec!
- Quiets wide legacy surfaces with crate-level allows in main.rs for
stylistic lints (too_many_arguments, type_complexity, doc indent,
enum variant prefix, wildcard-in-or, assertions-on-constants,
drop_non_drop, unused_io_amount, ptr_arg) — these fired in dozens
of places with no correctness payoff and have been churning every
toolchain bump.
- Tags intentional-dead-code helpers: wallet/ and streaming/ modules
are WIP, mesh::send_chunked_payload and DM_V1_MARKER are kept for
rollback compatibility, vpn::get_nostr_vpn_status is surface-area
for a not-yet-landed RPC.
cargo fmt --check, cargo clippy --all-targets --all-features
-- -D warnings, and cargo test --all-features now all pass locally.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 17:23:46 -04:00
|
|
|
use super::build_response;
|
2026-05-13 15:09:22 -04:00
|
|
|
use crate::api::rpc::lnd::LND_REST_BASE_URL;
|
2026-03-22 03:30:21 +00:00
|
|
|
use crate::api::rpc::RpcHandler;
|
2026-04-30 16:29:56 -04:00
|
|
|
use crate::bitcoin_status;
|
chore(ci): rustfmt + clippy clean-up to unblock the Rust CI job
The .github/workflows/ci.yml Rust job runs cargo fmt --check, clippy
with -D warnings, and tests. All three were failing. This commit:
- Applies rustfmt across the tree (the bulk of the diff — untouched
since the last toolchain bump, so a wide sweep was unavoidable).
- Fixes the correctness-level clippy errors:
container/bitcoin_simulator.rs wildcard-in-or-pattern
container/manifest.rs from_str rename to parse (reserved name)
container/podman_client.rs .get(0) -> .first()
container/runtime.rs manual += collapse
archipelago/src/constants.rs doc-comment → module-doc
api/rpc/package/install.rs stray /// comment above a non-item
container/docker_packages.rs redundant field init
streaming/advertisement.rs missing Metric import in tests
tests/orchestration_tests.rs `vec!` in non-Vec contexts
mesh/listener/dispatch.rs unused store_plain_message import
api/rpc/tor/mod.rs and mesh/steganography.rs: push-after-new → vec!
- Quiets wide legacy surfaces with crate-level allows in main.rs for
stylistic lints (too_many_arguments, type_complexity, doc indent,
enum variant prefix, wildcard-in-or, assertions-on-constants,
drop_non_drop, unused_io_amount, ptr_arg) — these fired in dozens
of places with no correctness payoff and have been churning every
toolchain bump.
- Tags intentional-dead-code helpers: wallet/ and streaming/ modules
are WIP, mesh::send_chunked_payload and DM_V1_MARKER are kept for
rollback compatibility, vpn::get_nostr_vpn_status is surface-area
for a not-yet-landed RPC.
cargo fmt --check, cargo clippy --all-targets --all-features
-- -D warnings, and cargo test --all-features now all pass locally.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 17:23:46 -04:00
|
|
|
use crate::electrs_status;
|
2026-03-22 03:30:21 +00:00
|
|
|
use anyhow::Result;
|
|
|
|
|
use hyper::{Response, StatusCode};
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
chore(ci): rustfmt + clippy clean-up to unblock the Rust CI job
The .github/workflows/ci.yml Rust job runs cargo fmt --check, clippy
with -D warnings, and tests. All three were failing. This commit:
- Applies rustfmt across the tree (the bulk of the diff — untouched
since the last toolchain bump, so a wide sweep was unavoidable).
- Fixes the correctness-level clippy errors:
container/bitcoin_simulator.rs wildcard-in-or-pattern
container/manifest.rs from_str rename to parse (reserved name)
container/podman_client.rs .get(0) -> .first()
container/runtime.rs manual += collapse
archipelago/src/constants.rs doc-comment → module-doc
api/rpc/package/install.rs stray /// comment above a non-item
container/docker_packages.rs redundant field init
streaming/advertisement.rs missing Metric import in tests
tests/orchestration_tests.rs `vec!` in non-Vec contexts
mesh/listener/dispatch.rs unused store_plain_message import
api/rpc/tor/mod.rs and mesh/steganography.rs: push-after-new → vec!
- Quiets wide legacy surfaces with crate-level allows in main.rs for
stylistic lints (too_many_arguments, type_complexity, doc indent,
enum variant prefix, wildcard-in-or, assertions-on-constants,
drop_non_drop, unused_io_amount, ptr_arg) — these fired in dozens
of places with no correctness payoff and have been churning every
toolchain bump.
- Tags intentional-dead-code helpers: wallet/ and streaming/ modules
are WIP, mesh::send_chunked_payload and DM_V1_MARKER are kept for
rollback compatibility, vpn::get_nostr_vpn_status is surface-area
for a not-yet-landed RPC.
cargo fmt --check, cargo clippy --all-targets --all-features
-- -D warnings, and cargo test --all-features now all pass locally.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 17:23:46 -04:00
|
|
|
use super::{is_valid_app_id, ApiHandler};
|
2026-03-22 03:30:21 +00:00
|
|
|
|
|
|
|
|
impl ApiHandler {
|
|
|
|
|
pub(super) async fn handle_container_logs_http(
|
|
|
|
|
rpc: Arc<RpcHandler>,
|
|
|
|
|
path: &str,
|
|
|
|
|
cors_origin: &str,
|
|
|
|
|
) -> Result<Response<hyper::Body>> {
|
|
|
|
|
let query = path
|
|
|
|
|
.strip_prefix("/api/container/logs")
|
|
|
|
|
.and_then(|s| s.strip_prefix('?'))
|
|
|
|
|
.unwrap_or("");
|
chore(ci): rustfmt + clippy clean-up to unblock the Rust CI job
The .github/workflows/ci.yml Rust job runs cargo fmt --check, clippy
with -D warnings, and tests. All three were failing. This commit:
- Applies rustfmt across the tree (the bulk of the diff — untouched
since the last toolchain bump, so a wide sweep was unavoidable).
- Fixes the correctness-level clippy errors:
container/bitcoin_simulator.rs wildcard-in-or-pattern
container/manifest.rs from_str rename to parse (reserved name)
container/podman_client.rs .get(0) -> .first()
container/runtime.rs manual += collapse
archipelago/src/constants.rs doc-comment → module-doc
api/rpc/package/install.rs stray /// comment above a non-item
container/docker_packages.rs redundant field init
streaming/advertisement.rs missing Metric import in tests
tests/orchestration_tests.rs `vec!` in non-Vec contexts
mesh/listener/dispatch.rs unused store_plain_message import
api/rpc/tor/mod.rs and mesh/steganography.rs: push-after-new → vec!
- Quiets wide legacy surfaces with crate-level allows in main.rs for
stylistic lints (too_many_arguments, type_complexity, doc indent,
enum variant prefix, wildcard-in-or, assertions-on-constants,
drop_non_drop, unused_io_amount, ptr_arg) — these fired in dozens
of places with no correctness payoff and have been churning every
toolchain bump.
- Tags intentional-dead-code helpers: wallet/ and streaming/ modules
are WIP, mesh::send_chunked_payload and DM_V1_MARKER are kept for
rollback compatibility, vpn::get_nostr_vpn_status is surface-area
for a not-yet-landed RPC.
cargo fmt --check, cargo clippy --all-targets --all-features
-- -D warnings, and cargo test --all-features now all pass locally.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 17:23:46 -04:00
|
|
|
let params: std::collections::HashMap<String, String> = query
|
|
|
|
|
.split('&')
|
|
|
|
|
.filter_map(|p| {
|
|
|
|
|
let mut it = p.splitn(2, '=');
|
|
|
|
|
let k = it.next()?.to_string();
|
|
|
|
|
let v = it.next()?.to_string();
|
|
|
|
|
Some((k, v))
|
|
|
|
|
})
|
|
|
|
|
.collect();
|
2026-03-22 03:30:21 +00:00
|
|
|
|
|
|
|
|
let app_id = params.get("app_id").map(|s| s.as_str()).unwrap_or("lnd");
|
|
|
|
|
|
|
|
|
|
// Validate app_id format
|
|
|
|
|
if !is_valid_app_id(app_id) {
|
|
|
|
|
let body = serde_json::json!({ "error": "Invalid app_id" });
|
|
|
|
|
let body_bytes = serde_json::to_vec(&body).unwrap_or_default();
|
chore(ci): rustfmt + clippy clean-up to unblock the Rust CI job
The .github/workflows/ci.yml Rust job runs cargo fmt --check, clippy
with -D warnings, and tests. All three were failing. This commit:
- Applies rustfmt across the tree (the bulk of the diff — untouched
since the last toolchain bump, so a wide sweep was unavoidable).
- Fixes the correctness-level clippy errors:
container/bitcoin_simulator.rs wildcard-in-or-pattern
container/manifest.rs from_str rename to parse (reserved name)
container/podman_client.rs .get(0) -> .first()
container/runtime.rs manual += collapse
archipelago/src/constants.rs doc-comment → module-doc
api/rpc/package/install.rs stray /// comment above a non-item
container/docker_packages.rs redundant field init
streaming/advertisement.rs missing Metric import in tests
tests/orchestration_tests.rs `vec!` in non-Vec contexts
mesh/listener/dispatch.rs unused store_plain_message import
api/rpc/tor/mod.rs and mesh/steganography.rs: push-after-new → vec!
- Quiets wide legacy surfaces with crate-level allows in main.rs for
stylistic lints (too_many_arguments, type_complexity, doc indent,
enum variant prefix, wildcard-in-or, assertions-on-constants,
drop_non_drop, unused_io_amount, ptr_arg) — these fired in dozens
of places with no correctness payoff and have been churning every
toolchain bump.
- Tags intentional-dead-code helpers: wallet/ and streaming/ modules
are WIP, mesh::send_chunked_payload and DM_V1_MARKER are kept for
rollback compatibility, vpn::get_nostr_vpn_status is surface-area
for a not-yet-landed RPC.
cargo fmt --check, cargo clippy --all-targets --all-features
-- -D warnings, and cargo test --all-features now all pass locally.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 17:23:46 -04:00
|
|
|
return Ok(build_response(
|
|
|
|
|
StatusCode::BAD_REQUEST,
|
|
|
|
|
"application/json",
|
|
|
|
|
hyper::Body::from(body_bytes),
|
|
|
|
|
));
|
2026-03-22 03:30:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let lines = params
|
|
|
|
|
.get("lines")
|
|
|
|
|
.and_then(|s| s.parse::<u32>().ok())
|
|
|
|
|
.unwrap_or(200);
|
|
|
|
|
|
|
|
|
|
match rpc.get_container_logs_value(app_id, lines).await {
|
|
|
|
|
Ok(value) => {
|
|
|
|
|
let body = serde_json::json!({ "result": value });
|
|
|
|
|
let body_bytes = serde_json::to_vec(&body).unwrap_or_default();
|
|
|
|
|
Ok(Response::builder()
|
|
|
|
|
.status(StatusCode::OK)
|
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
|
.header("Access-Control-Allow-Origin", cors_origin)
|
|
|
|
|
.header("Access-Control-Allow-Credentials", "true")
|
|
|
|
|
.header("Vary", "Origin")
|
|
|
|
|
.body(hyper::Body::from(body_bytes))
|
|
|
|
|
.unwrap())
|
|
|
|
|
}
|
|
|
|
|
Err(e) => {
|
|
|
|
|
let body = serde_json::json!({ "error": e.to_string() });
|
|
|
|
|
let body_bytes = serde_json::to_vec(&body).unwrap_or_default();
|
|
|
|
|
Ok(Response::builder()
|
|
|
|
|
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
|
.header("Access-Control-Allow-Origin", cors_origin)
|
|
|
|
|
.header("Access-Control-Allow-Credentials", "true")
|
|
|
|
|
.header("Vary", "Origin")
|
|
|
|
|
.body(hyper::Body::from(body_bytes))
|
|
|
|
|
.unwrap())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(super) async fn handle_electrs_status() -> Result<Response<hyper::Body>> {
|
|
|
|
|
let status = electrs_status::get_electrs_sync_status().await;
|
|
|
|
|
let body = serde_json::to_vec(&status).unwrap_or_default();
|
2026-04-30 16:29:56 -04:00
|
|
|
Ok(Response::builder()
|
|
|
|
|
.status(StatusCode::OK)
|
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
|
.header("Cache-Control", "no-store")
|
|
|
|
|
.body(hyper::Body::from(body))
|
|
|
|
|
.unwrap_or_else(|_| Response::new(hyper::Body::from("{}"))))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(super) async fn handle_bitcoin_status() -> Result<Response<hyper::Body>> {
|
|
|
|
|
let status = bitcoin_status::get_bitcoin_status().await;
|
|
|
|
|
let body = serde_json::to_vec(&status).unwrap_or_default();
|
|
|
|
|
Ok(Response::builder()
|
|
|
|
|
.status(StatusCode::OK)
|
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
|
.header("Cache-Control", "no-store")
|
|
|
|
|
.body(hyper::Body::from(body))
|
|
|
|
|
.unwrap_or_else(|_| Response::new(hyper::Body::from("{}"))))
|
2026-03-22 03:30:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(super) async fn handle_lnd_connect_info(
|
|
|
|
|
rpc: std::sync::Arc<super::super::rpc::RpcHandler>,
|
|
|
|
|
) -> Result<Response<hyper::Body>> {
|
|
|
|
|
match rpc.handle_lnd_connect_info().await {
|
|
|
|
|
Ok(val) => {
|
|
|
|
|
let body = serde_json::to_vec(&val).unwrap_or_default();
|
chore(ci): rustfmt + clippy clean-up to unblock the Rust CI job
The .github/workflows/ci.yml Rust job runs cargo fmt --check, clippy
with -D warnings, and tests. All three were failing. This commit:
- Applies rustfmt across the tree (the bulk of the diff — untouched
since the last toolchain bump, so a wide sweep was unavoidable).
- Fixes the correctness-level clippy errors:
container/bitcoin_simulator.rs wildcard-in-or-pattern
container/manifest.rs from_str rename to parse (reserved name)
container/podman_client.rs .get(0) -> .first()
container/runtime.rs manual += collapse
archipelago/src/constants.rs doc-comment → module-doc
api/rpc/package/install.rs stray /// comment above a non-item
container/docker_packages.rs redundant field init
streaming/advertisement.rs missing Metric import in tests
tests/orchestration_tests.rs `vec!` in non-Vec contexts
mesh/listener/dispatch.rs unused store_plain_message import
api/rpc/tor/mod.rs and mesh/steganography.rs: push-after-new → vec!
- Quiets wide legacy surfaces with crate-level allows in main.rs for
stylistic lints (too_many_arguments, type_complexity, doc indent,
enum variant prefix, wildcard-in-or, assertions-on-constants,
drop_non_drop, unused_io_amount, ptr_arg) — these fired in dozens
of places with no correctness payoff and have been churning every
toolchain bump.
- Tags intentional-dead-code helpers: wallet/ and streaming/ modules
are WIP, mesh::send_chunked_payload and DM_V1_MARKER are kept for
rollback compatibility, vpn::get_nostr_vpn_status is surface-area
for a not-yet-landed RPC.
cargo fmt --check, cargo clippy --all-targets --all-features
-- -D warnings, and cargo test --all-features now all pass locally.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 17:23:46 -04:00
|
|
|
Ok(build_response(
|
|
|
|
|
StatusCode::OK,
|
|
|
|
|
"application/json",
|
|
|
|
|
hyper::Body::from(body),
|
|
|
|
|
))
|
2026-03-22 03:30:21 +00:00
|
|
|
}
|
|
|
|
|
Err(e) => Ok(Response::builder()
|
|
|
|
|
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
|
.body(hyper::Body::from(
|
|
|
|
|
serde_json::json!({"error": e.to_string()}).to_string(),
|
|
|
|
|
))
|
|
|
|
|
.unwrap()),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
chore(ci): rustfmt + clippy clean-up to unblock the Rust CI job
The .github/workflows/ci.yml Rust job runs cargo fmt --check, clippy
with -D warnings, and tests. All three were failing. This commit:
- Applies rustfmt across the tree (the bulk of the diff — untouched
since the last toolchain bump, so a wide sweep was unavoidable).
- Fixes the correctness-level clippy errors:
container/bitcoin_simulator.rs wildcard-in-or-pattern
container/manifest.rs from_str rename to parse (reserved name)
container/podman_client.rs .get(0) -> .first()
container/runtime.rs manual += collapse
archipelago/src/constants.rs doc-comment → module-doc
api/rpc/package/install.rs stray /// comment above a non-item
container/docker_packages.rs redundant field init
streaming/advertisement.rs missing Metric import in tests
tests/orchestration_tests.rs `vec!` in non-Vec contexts
mesh/listener/dispatch.rs unused store_plain_message import
api/rpc/tor/mod.rs and mesh/steganography.rs: push-after-new → vec!
- Quiets wide legacy surfaces with crate-level allows in main.rs for
stylistic lints (too_many_arguments, type_complexity, doc indent,
enum variant prefix, wildcard-in-or, assertions-on-constants,
drop_non_drop, unused_io_amount, ptr_arg) — these fired in dozens
of places with no correctness payoff and have been churning every
toolchain bump.
- Tags intentional-dead-code helpers: wallet/ and streaming/ modules
are WIP, mesh::send_chunked_payload and DM_V1_MARKER are kept for
rollback compatibility, vpn::get_nostr_vpn_status is surface-area
for a not-yet-landed RPC.
cargo fmt --check, cargo clippy --all-targets --all-features
-- -D warnings, and cargo test --all-features now all pass locally.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 17:23:46 -04:00
|
|
|
pub(super) async fn handle_lnd_proxy(
|
|
|
|
|
path: &str,
|
|
|
|
|
cors_origin: &str,
|
|
|
|
|
) -> Result<Response<hyper::Body>> {
|
2026-03-22 03:30:21 +00:00
|
|
|
let suffix = path.strip_prefix("/proxy/lnd").unwrap_or("/");
|
2026-05-13 15:09:22 -04:00
|
|
|
let url = format!("{LND_REST_BASE_URL}{suffix}");
|
2026-03-22 03:30:21 +00:00
|
|
|
match reqwest::get(&url).await {
|
|
|
|
|
Ok(resp) => {
|
|
|
|
|
let status = resp.status().as_u16();
|
|
|
|
|
let headers = resp.headers().clone();
|
|
|
|
|
let body = resp.bytes().await.unwrap_or_default();
|
|
|
|
|
let mut builder = Response::builder().status(status);
|
|
|
|
|
if let Some(ct) = headers.get("content-type") {
|
|
|
|
|
if let Ok(s) = ct.to_str() {
|
|
|
|
|
builder = builder.header("Content-Type", s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
builder
|
|
|
|
|
.header("Access-Control-Allow-Origin", cors_origin)
|
|
|
|
|
.header("Access-Control-Allow-Credentials", "true")
|
|
|
|
|
.header("Vary", "Origin")
|
|
|
|
|
.body(hyper::Body::from(body))
|
|
|
|
|
.map_err(|e| anyhow::anyhow!("response build: {}", e))
|
|
|
|
|
}
|
|
|
|
|
Err(e) => {
|
|
|
|
|
let body = serde_json::json!({ "error": e.to_string() });
|
|
|
|
|
let body_bytes = serde_json::to_vec(&body).unwrap_or_default();
|
|
|
|
|
Ok(Response::builder()
|
|
|
|
|
.status(StatusCode::BAD_GATEWAY)
|
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
|
.header("Access-Control-Allow-Origin", cors_origin)
|
|
|
|
|
.header("Access-Control-Allow-Credentials", "true")
|
|
|
|
|
.header("Vary", "Origin")
|
|
|
|
|
.body(hyper::Body::from(body_bytes))
|
|
|
|
|
.unwrap())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|