Add total interractions to contract count

Closes #6
This commit is contained in:
Dagur Valberg Johannsson 2024-11-13 11:27:22 +01:00
parent b1e88ff261
commit 5d4b525743
No known key found for this signature in database
GPG key ID: FD701804AEE88107

View file

@ -16,6 +16,7 @@ use crate::{db::DB, timeutil::time_now};
pub struct ContractCount {
active: u64,
ended: u64,
interactions: u64,
}
fn db_contract_count_all(db: &Connection) -> Result<ContractCount> {
@ -31,7 +32,15 @@ fn db_contract_count_all(db: &Connection) -> Result<ContractCount> {
|row| row.get(0),
)?;
Ok(ContractCount { active, ended })
let interactions: u64 = db.query_row("SELECT COUNT(*) FROM pool_history_entry", [], |row| {
row.get(0)
})?;
Ok(ContractCount {
active,
ended,
interactions,
})
}
fn db_contract_count_by_token(db: &Connection, token_id: &str) -> Result<ContractCount> {
@ -47,7 +56,17 @@ fn db_contract_count_by_token(db: &Connection, token_id: &str) -> Result<Contrac
|row| row.get(0),
)?;
Ok(ContractCount { active, ended })
let interactions: u64 = db.query_row(
"SELECT COUNT(*) FROM pool_history_entry phe JOIN pool p ON phe.pool = p.creation_utxo WHERE p.token_id = ?",
[token_id],
|row| row.get(0),
)?;
Ok(ContractCount {
active,
ended,
interactions,
})
}
#[get("/contract/count")]