adding unspent outputs stats

This commit is contained in:
aglkm
2024-09-30 16:31:40 +03:00
parent a8bf3f1b0a
commit aa49b2c20b
6 changed files with 240 additions and 104 deletions

View File

@@ -9,10 +9,9 @@ use crate::data::Transactions;
use crate::requests;
// Tokio Runtime Worker.
// Collecting all the data.
pub async fn run(dash: Arc<Mutex<Dashboard>>, blocks: Arc<Mutex<Vec<Block>>>,
txns: Arc<Mutex<Transactions>>, stats: Arc<Mutex<Statistics>>) -> Result<(), anyhow::Error> {
// Collecting main data.
pub async fn data(dash: Arc<Mutex<Dashboard>>, blocks: Arc<Mutex<Vec<Block>>>,
txns: Arc<Mutex<Transactions>>, stats: Arc<Mutex<Statistics>>) -> Result<(), anyhow::Error> {
let _ = requests::get_status(dash.clone()).await?;
let _ = requests::get_mempool(dash.clone()).await?;
let _ = requests::get_connected_peers(dash.clone(), stats.clone()).await?;
@@ -22,33 +21,31 @@ pub async fn run(dash: Arc<Mutex<Dashboard>>, blocks: Arc<Mutex<Vec<Block>>>,
let _ = requests::get_recent_blocks(dash.clone(), blocks.clone()).await?;
let _ = requests::get_txn_stats(dash.clone(), txns.clone()).await?;
Ok(())
}
// Collecting statistics.
pub async fn stats(dash: Arc<Mutex<Dashboard>>, txns: Arc<Mutex<Transactions>>, stats: Arc<Mutex<Statistics>>) -> Result<(), anyhow::Error> {
let _ = requests::get_unspent_outputs(dash.clone()).await?;
let mut stats = stats.lock().unwrap();
let dash = dash.lock().unwrap();
let txns = txns.lock().unwrap();
// Every day push new stats into the vectors
if let Some(v) = stats.date.last() {
// If new day, push the stats
if *v != format!("\"{}\"", Utc::now().format("%d-%m-%Y")) {
if stats.date.len() == 30 {
stats.date.remove(0);
stats.hashrate.remove(0);
stats.txns.remove(0);
stats.fees.remove(0);
}
stats.date.push(format!("\"{}\"", Utc::now().format("%d-%m-%Y")));
stats.hashrate.push(dash.hashrate_kgs.clone());
stats.txns.push(txns.period_24h.clone());
stats.fees.push(txns.fees_24h.clone());
}
} else {
// Vector is empty, pushing current stats
stats.date.push(format!("\"{}\"", Utc::now().format("%d-%m-%Y")));
stats.hashrate.push(dash.hashrate_kgs.clone());
stats.txns.push(txns.period_24h.clone());
stats.fees.push(txns.fees_24h.clone());
if stats.date.len() == 30 {
stats.date.remove(0);
stats.hashrate.remove(0);
stats.txns.remove(0);
stats.fees.remove(0);
stats.utxo_count.remove(0);
}
stats.date.push(format!("\"{}\"", Utc::now().format("%d-%m-%Y")));
stats.hashrate.push(dash.hashrate_kgs.clone());
stats.txns.push(txns.period_24h.clone());
stats.fees.push(txns.fees_24h.clone());
stats.utxo_count.push(dash.utxo_count.clone());
Ok(())
}