Skip to content

Commit 7fc08ae

Browse files
committed
rusk: Expose /stats/account_count endpoint for public account count
1 parent b31d4ae commit 7fc08ae

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

node/src/archive/sqlite.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,9 @@ impl Archive {
234234
Ok(last_account_id)
235235
}
236236

237-
/// Count finalized transfer transactions for the transfer contract, split by topic.
238-
/// Returns (moonlight_count, phoenix_count).
239-
pub async fn fetch_tx_count(
240-
&self,
241-
) -> Result<(u64, u64)> {
237+
/// Count finalized transfer transactions for the transfer contract, split
238+
/// by topic. Returns (moonlight_count, phoenix_count).
239+
pub async fn fetch_tx_count(&self) -> Result<(u64, u64)> {
242240
let mut conn = self.sqlite_archive.acquire().await?;
243241

244242
let transfer_src = dusk_core::transfer::TRANSFER_CONTRACT.to_string();

rusk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Add `status` to GQL block fields
1515
- Add activaction height for host queries
1616
- Add blob config section
17+
- add `/stats/account_count` endpoint [#3625]
1718
- add `/stats/tx_count` endpoint [#3625]
1819

1920
### Changed

rusk/src/lib/http/chain.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ impl HandleRequest for RuskNode {
6868
("blocks", _, "gas-price") => true,
6969
("blobs", Some(_), "commitment") => true,
7070
("blobs", Some(_), "hash") => true,
71+
("stats", _, "account_count") => true,
7172
("stats", _, "tx_count") => true,
7273

7374
_ => false,
@@ -122,6 +123,7 @@ impl HandleRequest for RuskNode {
122123
self.blob_by_hash(&hash, request.is_json()).await
123124
}
124125

126+
("stats", _, "account_count") => self.get_account_count().await,
125127
("stats", _, "tx_count") => self.get_tx_count().await,
126128

127129
_ => anyhow::bail!("Unsupported"),
@@ -390,7 +392,29 @@ impl RuskNode {
390392
})))
391393
}
392394

393-
/// Returns the total number of finalized transactions observed in the
395+
/// Returns the total number of active public accounts recorded in the
396+
/// archive node. The response is a JSON object:
397+
/// ```json
398+
/// { "public_accounts": 12345 }
399+
/// ```
400+
///
401+
/// # Errors
402+
/// Returns an error if the archive feature is not enabled.
403+
async fn get_account_count(&self) -> anyhow::Result<ResponseData> {
404+
#[cfg(feature = "archive")]
405+
{
406+
let count = self.archive().fetch_active_accounts().await?;
407+
let body = serde_json::json!({ "public_accounts": count });
408+
Ok(ResponseData::new(body))
409+
}
410+
411+
#[cfg(not(feature = "archive"))]
412+
{
413+
anyhow::bail!("The archive feature is required for this endpoint.");
414+
}
415+
}
416+
417+
/// Returns the total number of finalized transactions observed in the
394418
/// archive, split into `public`, `shielded` and `total. The response is
395419
/// a JSON object:
396420
/// ```json

0 commit comments

Comments
 (0)