2024-05-22 18:34:47 -07:00
|
|
|
use anyhow::Context;
|
2024-05-09 11:01:53 -07:00
|
|
|
use axum::routing::get;
|
2025-08-21 09:10:40 +02:00
|
|
|
use axum::routing::post;
|
2024-05-09 11:01:53 -07:00
|
|
|
use axum::routing::Router;
|
2024-05-25 19:16:36 -07:00
|
|
|
use neptune_explorer::alert_email;
|
feat: Add Announcement viewer
Every transaction can have zero or more announcements, which are essentially
messages that must be included across all future mergers and updates.
Announcements are typically used for transmitting information related to
receiving UTXOs, encrypted. However, a new use case is that of *transparent
transaction info*, which is an announcement containing the UTXOs and the
commitment randomnesses needed to reproduce the transaction's inputs and
outputs. With such a transparent transaction info announcement, third parties
can transparently audit transactions.
This commit adds a page for viewing announcements, and if the announcement can
be parsed as a transparent transaction info type announcement then it is
rendered as such, complete with native currency amounts and linkable UTXOs
(where possible).
The path for accessing announcements is any of
- `/announcement/digest/<hex-string>/<index>`
- `/announcement/tip/<index>`
- `/announcement/genesis/<index>`
- `/announcement/height/<height>/<index>`
- `/announcement/height_or_digest/<height-or-diges>/index/<index>`.
The last bullet point exists to support the quick lookup functionality, which is
also new. A `AnnouncementSelector` has display and from-string methods relating
these path formats to the relevant object. A suite of (prop)tests verifies
parsing.
Also, this commit enables mocking, which is useful when the neptune-core node
the explorer is connected to is outdated, unsynced, or for whatever reason does
not serve the desired data. The RPC client call is intercepted, and if it fails
and mocking is enabled, an imagined (pseudorandom) resource of the requested
type is returned. To enable mocking, compile with the "mock" feature flag and
set the "MOCK" environment variable.
2025-08-12 18:21:27 +02:00
|
|
|
use neptune_explorer::html::page::announcement::announcement_page;
|
2024-05-09 11:01:53 -07:00
|
|
|
use neptune_explorer::html::page::block::block_page;
|
2024-05-14 11:54:42 -07:00
|
|
|
use neptune_explorer::html::page::not_found::not_found_html_fallback;
|
2024-05-16 10:16:48 -07:00
|
|
|
use neptune_explorer::html::page::redirect_qs_to_path::redirect_query_string_to_path;
|
2024-05-09 11:01:53 -07:00
|
|
|
use neptune_explorer::html::page::root::root;
|
|
|
|
|
use neptune_explorer::html::page::utxo::utxo_page;
|
|
|
|
|
use neptune_explorer::model::app_state::AppState;
|
2024-05-25 19:16:36 -07:00
|
|
|
use neptune_explorer::neptune_rpc;
|
2024-05-09 11:01:53 -07:00
|
|
|
use neptune_explorer::rpc::block_digest::block_digest;
|
|
|
|
|
use neptune_explorer::rpc::block_info::block_info;
|
2025-10-02 15:57:38 +02:00
|
|
|
use neptune_explorer::rpc::circulating_supply::circulating_supply;
|
2025-08-21 07:50:46 +02:00
|
|
|
use neptune_explorer::rpc::pow_puzzle::pow_puzzle;
|
2025-08-21 09:10:40 +02:00
|
|
|
use neptune_explorer::rpc::provide_pow_solution::provide_pow_solution;
|
2024-05-09 11:01:53 -07:00
|
|
|
use neptune_explorer::rpc::utxo_digest::utxo_digest;
|
2024-05-14 11:54:42 -07:00
|
|
|
use tower_http::services::ServeDir;
|
2024-05-28 15:39:46 -07:00
|
|
|
use tracing::info;
|
2024-05-25 19:16:36 -07:00
|
|
|
use tracing_subscriber::EnvFilter;
|
2024-04-24 18:44:52 -07:00
|
|
|
|
|
|
|
|
#[tokio::main]
|
2024-05-22 18:34:47 -07:00
|
|
|
async fn main() -> Result<(), anyhow::Error> {
|
2024-05-25 19:16:36 -07:00
|
|
|
let filter = EnvFilter::from_default_env()
|
|
|
|
|
// Set the base level when not matched by other directives to INFO.
|
|
|
|
|
.add_directive("neptune_explorer=info".parse()?);
|
|
|
|
|
|
|
|
|
|
tracing_subscriber::fmt().with_env_filter(filter).init();
|
|
|
|
|
|
|
|
|
|
let app_state = AppState::init().await?;
|
|
|
|
|
|
|
|
|
|
let routes = setup_routes(app_state.clone());
|
|
|
|
|
|
2024-05-27 17:24:01 -07:00
|
|
|
let port = app_state.load().config.listen_port;
|
2024-05-25 19:16:36 -07:00
|
|
|
let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{port}"))
|
2024-05-22 18:34:47 -07:00
|
|
|
.await
|
2024-05-25 19:16:36 -07:00
|
|
|
.with_context(|| format!("Failed to bind to port {port}"))?;
|
|
|
|
|
|
2024-05-28 15:39:46 -07:00
|
|
|
// this will log warnings if smtp not configured or mis-configured.
|
|
|
|
|
alert_email::check_alert_params();
|
2024-04-24 18:44:52 -07:00
|
|
|
|
2024-12-31 09:58:40 -08:00
|
|
|
tokio::task::spawn(neptune_rpc::watchdog(app_state.clone()));
|
|
|
|
|
tokio::task::spawn(neptune_rpc::blockchain_watchdog(app_state));
|
2024-04-24 18:44:52 -07:00
|
|
|
|
2024-05-25 19:16:36 -07:00
|
|
|
info!("Running on http://localhost:{port}");
|
|
|
|
|
|
|
|
|
|
axum::serve(listener, routes)
|
|
|
|
|
.await
|
|
|
|
|
.with_context(|| "Axum server encountered an error")?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn setup_routes(app_state: AppState) -> Router {
|
|
|
|
|
Router::new()
|
2024-05-09 08:56:59 -07:00
|
|
|
// -- RPC calls --
|
2024-05-21 12:41:34 -07:00
|
|
|
.route("/rpc/block_info/*selector", get(block_info))
|
|
|
|
|
.route("/rpc/block_digest/*selector", get(block_digest))
|
2024-04-24 18:44:52 -07:00
|
|
|
.route("/rpc/utxo_digest/:index", get(utxo_digest))
|
2025-08-21 07:50:46 +02:00
|
|
|
.route("/rpc/pow_puzzle/*address", get(pow_puzzle))
|
2025-10-02 15:57:38 +02:00
|
|
|
.route("/rpc/circulating_supply", get(circulating_supply))
|
2025-08-21 09:10:40 +02:00
|
|
|
.route("/rpc/provide_pow_solution", post(provide_pow_solution))
|
2024-05-09 08:56:59 -07:00
|
|
|
// -- Dynamic HTML pages --
|
2024-04-24 18:44:52 -07:00
|
|
|
.route("/", get(root))
|
2024-05-21 12:41:34 -07:00
|
|
|
.route("/block/*selector", get(block_page))
|
2024-05-09 08:56:59 -07:00
|
|
|
.route("/utxo/:value", get(utxo_page))
|
feat: Add Announcement viewer
Every transaction can have zero or more announcements, which are essentially
messages that must be included across all future mergers and updates.
Announcements are typically used for transmitting information related to
receiving UTXOs, encrypted. However, a new use case is that of *transparent
transaction info*, which is an announcement containing the UTXOs and the
commitment randomnesses needed to reproduce the transaction's inputs and
outputs. With such a transparent transaction info announcement, third parties
can transparently audit transactions.
This commit adds a page for viewing announcements, and if the announcement can
be parsed as a transparent transaction info type announcement then it is
rendered as such, complete with native currency amounts and linkable UTXOs
(where possible).
The path for accessing announcements is any of
- `/announcement/digest/<hex-string>/<index>`
- `/announcement/tip/<index>`
- `/announcement/genesis/<index>`
- `/announcement/height/<height>/<index>`
- `/announcement/height_or_digest/<height-or-diges>/index/<index>`.
The last bullet point exists to support the quick lookup functionality, which is
also new. A `AnnouncementSelector` has display and from-string methods relating
these path formats to the relevant object. A suite of (prop)tests verifies
parsing.
Also, this commit enables mocking, which is useful when the neptune-core node
the explorer is connected to is outdated, unsynced, or for whatever reason does
not serve the desired data. The RPC client call is intercepted, and if it fails
and mocking is enabled, an imagined (pseudorandom) resource of the requested
type is returned. To enable mocking, compile with the "mock" feature flag and
set the "MOCK" environment variable.
2025-08-12 18:21:27 +02:00
|
|
|
.route("/announcement/*selector", get(announcement_page))
|
2024-05-16 10:16:48 -07:00
|
|
|
// -- Rewrite query-strings to path --
|
|
|
|
|
.route("/rqs", get(redirect_query_string_to_path))
|
2024-05-09 08:56:59 -07:00
|
|
|
// -- Static files --
|
2024-05-14 11:54:42 -07:00
|
|
|
.nest_service(
|
|
|
|
|
"/css",
|
|
|
|
|
ServeDir::new(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/web/css")),
|
2024-05-10 14:20:43 -07:00
|
|
|
)
|
2024-05-14 11:54:42 -07:00
|
|
|
.nest_service(
|
|
|
|
|
"/image",
|
|
|
|
|
ServeDir::new(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/web/image")),
|
2024-05-09 11:01:53 -07:00
|
|
|
)
|
2024-05-14 11:54:42 -07:00
|
|
|
// handle route not-found
|
2024-05-25 19:16:36 -07:00
|
|
|
.fallback(not_found_html_fallback)
|
2024-05-09 08:56:59 -07:00
|
|
|
// add state
|
2024-05-25 19:16:36 -07:00
|
|
|
.with_state(app_state.into())
|
2024-04-24 18:44:52 -07:00
|
|
|
}
|