Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show if JSON API is enabled on /status #4014

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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
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
Loading