forked from tari-project/sha-p2pool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added http status server and 2 basic stats to the new endpoint, hash …
…rate calculation in progress
- Loading branch information
Showing
18 changed files
with
282 additions
and
82 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 The Tari Project | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
pub mod stats; | ||
pub mod stats; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,37 @@ | ||
// Copyright 2024 The Tari Project | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
use axum::extract::State; | ||
use axum::http::StatusCode; | ||
use axum::Json; | ||
use itertools::Itertools; | ||
use log::error; | ||
|
||
use crate::server::http::stats::models::Stats; | ||
use crate::server::http::stats::server::AppState; | ||
|
||
pub async fn handle_get_stats() -> (StatusCode, Json<Stats>) { | ||
todo!() | ||
} | ||
const LOG_TARGET: &str = "p2pool::server::stats::get"; | ||
|
||
pub async fn handle_get_stats(State(state): State<AppState>) -> Result<Json<Stats>, StatusCode> { | ||
let chain = state.share_chain.blocks(0).await.map_err(|error| { | ||
error!(target: LOG_TARGET, "Failed to get blocks of share chain: {error:?}"); | ||
StatusCode::INTERNAL_SERVER_ERROR | ||
})?; | ||
|
||
// collect number of miners | ||
let num_of_miners = chain.iter() | ||
.map(|block| block.miner_wallet_address()) | ||
.filter(|addr_opt| addr_opt.is_some()) | ||
.map(|addr| addr.as_ref().unwrap().to_base58()) | ||
.unique() | ||
.count(); | ||
|
||
// last won block | ||
let last_block_won = chain.iter() | ||
.filter(|block| block.sent_to_main_chain()) | ||
.last() | ||
.cloned() | ||
.map(|block| block.into()); | ||
|
||
Ok(Json(Stats { num_of_miners, last_block_won })) | ||
} |
Oops, something went wrong.