From 63cd115e9be792e171b520240347713183243225 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Tue, 22 Oct 2024 16:30:36 -0700 Subject: [PATCH] Show if JSON API is enabled on /status --- src/index.rs | 3 ++- src/subcommand/server.rs | 9 +++++++-- src/templates/status.rs | 1 + templates/status.html | 2 ++ tests/json_api.rs | 1 + 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/index.rs b/src/index.rs index dc0a57da4f..c5b9f36e99 100644 --- a/src/index.rs +++ b/src/index.rs @@ -505,7 +505,7 @@ impl Index { self.index_sats } - pub fn status(&self) -> Result { + pub fn status(&self, json_api: bool) -> Result { let rtx = self.database.begin_read()?; let statistic_to_count = rtx.open_table(STATISTIC_TO_COUNT)?; @@ -541,6 +541,7 @@ impl Index { initial_sync_time: Duration::from_micros(initial_sync_time), inscription_index: self.has_inscription_index(), inscriptions: blessed_inscriptions + cursed_inscriptions, + json_api, lost_sats: statistic(Statistic::LostSats)?, minimum_rune_for_next_block: Rune::minimum_at_height( self.settings.chain().network(), diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 472fbed9ed..8cc7763f57 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -1095,9 +1095,12 @@ impl Server { ) -> ServerResult { task::block_in_place(|| { Ok(if accept_json { - Json(index.status()?).into_response() + Json(index.status(server_config.json_api_enabled)?).into_response() } else { - index.status()?.page(server_config).into_response() + index + .status(server_config.json_api_enabled)? + .page(server_config) + .into_response() }) }) } @@ -3631,6 +3634,8 @@ mod tests {
false
transaction index
false
+
json api
+
true
git branch
.*
git commit
diff --git a/src/templates/status.rs b/src/templates/status.rs index 8efe0a2fef..92c4df3f10 100644 --- a/src/templates/status.rs +++ b/src/templates/status.rs @@ -10,6 +10,7 @@ pub struct StatusHtml { pub initial_sync_time: Duration, pub inscription_index: bool, pub inscriptions: u64, + pub json_api: bool, pub lost_sats: u64, pub minimum_rune_for_next_block: Rune, pub rune_index: bool, diff --git a/templates/status.html b/templates/status.html index be47e68ea7..e403777dc3 100644 --- a/templates/status.html +++ b/templates/status.html @@ -38,6 +38,8 @@

Status

{{ self.sat_index }}
transaction index
{{ self.transaction_index }}
+
json api
+
{{ self.json_api }}
%% if !env!("GIT_BRANCH").is_empty() {
git branch
{{ env!("GIT_BRANCH") }}
diff --git a/tests/json_api.rs b/tests/json_api.rs index 8047033127..dd6c0d16c2 100644 --- a/tests/json_api.rs +++ b/tests/json_api.rs @@ -502,6 +502,7 @@ fn get_status() { initial_sync_time: dummy_duration, inscription_index: true, inscriptions: 1, + json_api: true, lost_sats: 0, minimum_rune_for_next_block: Rune(99218849511960410), rune_index: true,