-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(analytics): implement ledger and most activity-based analytics (#…
…482) * Use outputs table for all analytics, and add additional endpoints. * Fix start/end timestamps * Fix Eq derives * Update storage deposit endpoint and add more output endpoints * Add block analytics and stringify responses * I should really test before pushing * 🤦♂️ * Revert native token * Use bee rent structure * Refactor routes and add additional ledger analytics. Use milestone indexes instead of timestamps. * Fix addresses analytics * Create API document. Remove milestone analytics endpoint. Make address analytics default. * Missed import * Update README
- Loading branch information
Alexandcoats
authored
Aug 4, 2022
1 parent
1df58dd
commit 755f9d2
Showing
14 changed files
with
1,004 additions
and
179 deletions.
There are no files selected for viewing
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
49 changes: 49 additions & 0 deletions
49
bin/inx-chronicle/src/api/stardust/analytics/extractors.rs
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2022 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use async_trait::async_trait; | ||
use axum::extract::{FromRequest, Query}; | ||
use chronicle::types::tangle::MilestoneIndex; | ||
use serde::Deserialize; | ||
|
||
use crate::api::ApiError; | ||
|
||
#[derive(Copy, Clone, Deserialize, Default)] | ||
#[serde(default, deny_unknown_fields, rename_all = "camelCase")] | ||
pub struct LedgerIndex { | ||
pub ledger_index: Option<MilestoneIndex>, | ||
} | ||
|
||
#[async_trait] | ||
impl<B: Send> FromRequest<B> for LedgerIndex { | ||
type Rejection = ApiError; | ||
|
||
async fn from_request(req: &mut axum::extract::RequestParts<B>) -> Result<Self, Self::Rejection> { | ||
let Query(query) = Query::<LedgerIndex>::from_request(req) | ||
.await | ||
.map_err(ApiError::QueryError)?; | ||
Ok(query) | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone, Deserialize, Default)] | ||
#[serde(default, deny_unknown_fields, rename_all = "camelCase")] | ||
pub struct MilestoneRange { | ||
pub start_index: Option<MilestoneIndex>, | ||
pub end_index: Option<MilestoneIndex>, | ||
} | ||
|
||
#[async_trait] | ||
impl<B: Send> FromRequest<B> for MilestoneRange { | ||
type Rejection = ApiError; | ||
|
||
async fn from_request(req: &mut axum::extract::RequestParts<B>) -> Result<Self, Self::Rejection> { | ||
let Query(MilestoneRange { start_index, end_index }) = Query::<MilestoneRange>::from_request(req) | ||
.await | ||
.map_err(ApiError::QueryError)?; | ||
if matches!((start_index, end_index), (Some(start), Some(end)) if end < start) { | ||
return Err(ApiError::BadTimeRange); | ||
} | ||
Ok(MilestoneRange { start_index, end_index }) | ||
} | ||
} |
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
44 changes: 34 additions & 10 deletions
44
bin/inx-chronicle/src/api/stardust/analytics/responses.rs
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,28 +1,52 @@ | ||
// Copyright 2022 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use bee_api_types_stardust::responses::RentStructureResponse; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::api::responses::impl_success_response; | ||
|
||
/// Response of `GET /api/analytics/addresses[?start_timestamp=<i64>&end_timestamp=<i64>]`. | ||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)] | ||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct AddressAnalyticsResponse { | ||
pub total_addresses: u64, | ||
pub receiving_addresses: u64, | ||
pub sending_addresses: u64, | ||
pub total_active_addresses: String, | ||
pub receiving_addresses: String, | ||
pub sending_addresses: String, | ||
} | ||
|
||
impl_success_response!(AddressAnalyticsResponse); | ||
|
||
/// Response of `GET /api/analytics/transactions[?start_timestamp=<i64>&end_timestamp=<i64>]`. | ||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)] | ||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct TransactionsAnalyticsResponse { | ||
pub count: u64, | ||
pub total_value: f64, | ||
pub average_value: f64, | ||
pub struct OutputAnalyticsResponse { | ||
pub count: String, | ||
pub total_value: String, | ||
} | ||
|
||
impl_success_response!(TransactionsAnalyticsResponse); | ||
impl_success_response!(OutputAnalyticsResponse); | ||
|
||
/// Response of `GET /api/analytics/transactions[?start_timestamp=<i64>&end_timestamp=<i64>]`. | ||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct BlockAnalyticsResponse { | ||
pub count: String, | ||
} | ||
|
||
impl_success_response!(BlockAnalyticsResponse); | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct StorageDepositAnalyticsResponse { | ||
pub output_count: String, | ||
pub storage_deposit_return_count: String, | ||
pub storage_deposit_return_total_value: String, | ||
pub total_key_bytes: String, | ||
pub total_data_bytes: String, | ||
pub total_byte_cost: String, | ||
pub ledger_index: u32, | ||
pub rent_structure: RentStructureResponse, | ||
} | ||
|
||
impl_success_response!(StorageDepositAnalyticsResponse); |
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
Oops, something went wrong.