Skip to content

Commit

Permalink
Show if JSON API is enabled on /status (#4014)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Oct 22, 2024
1 parent 205dff6 commit ef2212b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ impl Index {
self.index_sats
}

pub fn status(&self) -> Result<StatusHtml> {
pub fn status(&self, json_api: bool) -> Result<StatusHtml> {
let rtx = self.database.begin_read()?;

let statistic_to_count = rtx.open_table(STATISTIC_TO_COUNT)?;
Expand Down Expand Up @@ -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(),
Expand Down
9 changes: 7 additions & 2 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
}
Expand Down Expand Up @@ -3631,6 +3634,8 @@ mod tests {
<dd>false</dd>
<dt>transaction index</dt>
<dd>false</dd>
<dt>json api</dt>
<dd>true</dd>
<dt>git branch</dt>
<dd>.*</dd>
<dt>git commit</dt>
Expand Down
1 change: 1 addition & 0 deletions src/templates/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions templates/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ <h1>Status</h1>
<dd>{{ self.sat_index }}</dd>
<dt>transaction index</dt>
<dd>{{ self.transaction_index }}</dd>
<dt>json api</dt>
<dd>{{ self.json_api }}</dd>
%% if !env!("GIT_BRANCH").is_empty() {
<dt>git branch</dt>
<dd>{{ env!("GIT_BRANCH") }}</dd>
Expand Down
1 change: 1 addition & 0 deletions tests/json_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ef2212b

Please sign in to comment.