diff --git a/src/analytics/ledger/active_addresses.rs b/src/analytics/ledger/active_addresses.rs index c16eb2247..94d6c3e10 100644 --- a/src/analytics/ledger/active_addresses.rs +++ b/src/analytics/ledger/active_addresses.rs @@ -1,4 +1,4 @@ -// Copyright 2023 IOTA Stiftung +// Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 use std::collections::HashSet; @@ -43,7 +43,7 @@ impl IntervalAnalytics for AddressActivityMeasurement { impl Analytics for AddressActivityAnalytics { type Measurement = AddressActivityMeasurement; - fn handle_transaction(&mut self, consumed: &[LedgerSpent], created: &[LedgerOutput], ctx: &dyn AnalyticsContext) { + fn handle_transaction(&mut self, consumed: &[LedgerSpent], created: &[LedgerOutput], _ctx: &dyn AnalyticsContext) { for output in consumed { if let Some(a) = output.owning_address() { self.addresses.insert(*a); @@ -51,7 +51,7 @@ impl Analytics for AddressActivityAnalytics { } for output in created { - if let Some(a) = output.output.owning_address(ctx.at().milestone_timestamp) { + if let Some(a) = output.owning_address() { self.addresses.insert(*a); } } diff --git a/src/analytics/ledger/address_balance.rs b/src/analytics/ledger/address_balance.rs index a80ec4218..90dfd0971 100644 --- a/src/analytics/ledger/address_balance.rs +++ b/src/analytics/ledger/address_balance.rs @@ -4,10 +4,7 @@ use std::collections::HashMap; use super::*; -use crate::model::{ - payload::milestone::MilestoneTimestamp, - utxo::{Address, TokenAmount}, -}; +use crate::model::utxo::{Address, TokenAmount}; #[derive(Debug)] pub(crate) struct AddressBalanceMeasurement { @@ -32,13 +29,10 @@ pub(crate) struct AddressBalancesAnalytics { impl AddressBalancesAnalytics { /// Initialize the analytics by reading the current ledger state. - pub(crate) fn init<'a>( - unspent_outputs: impl IntoIterator, - milestone_timestamp: MilestoneTimestamp, - ) -> Self { + pub(crate) fn init<'a>(unspent_outputs: impl IntoIterator) -> Self { let mut balances = HashMap::new(); for output in unspent_outputs { - if let Some(&a) = output.output.owning_address(milestone_timestamp) { + if let Some(&a) = output.owning_address() { *balances.entry(a).or_default() += output.amount(); } } @@ -49,9 +43,9 @@ impl AddressBalancesAnalytics { impl Analytics for AddressBalancesAnalytics { type Measurement = AddressBalanceMeasurement; - fn handle_transaction(&mut self, consumed: &[LedgerSpent], created: &[LedgerOutput], ctx: &dyn AnalyticsContext) { + fn handle_transaction(&mut self, consumed: &[LedgerSpent], created: &[LedgerOutput], _ctx: &dyn AnalyticsContext) { for output in consumed { - if let Some(a) = output.owning_address() { + if let Some(a) = output.output.owning_address() { // All inputs should be present in `addresses`. If not, we skip it's value. if let Some(amount) = self.balances.get_mut(a) { *amount -= output.amount(); @@ -63,7 +57,7 @@ impl Analytics for AddressBalancesAnalytics { } for output in created { - if let Some(&a) = output.output.owning_address(ctx.at().milestone_timestamp) { + if let Some(&a) = output.owning_address() { // All inputs should be present in `addresses`. If not, we skip it's value. *self.balances.entry(a).or_default() += output.amount(); } diff --git a/src/analytics/mod.rs b/src/analytics/mod.rs index 7af647d6b..2f2a64308 100644 --- a/src/analytics/mod.rs +++ b/src/analytics/mod.rs @@ -23,7 +23,7 @@ use crate::{ model::{ ledger::{LedgerOutput, LedgerSpent}, metadata::LedgerInclusionState, - payload::{milestone::MilestoneTimestamp, Payload, TransactionEssence}, + payload::{Payload, TransactionEssence}, protocol::ProtocolParameters, tangle::{MilestoneIndex, MilestoneIndexTimestamp}, utxo::Input, @@ -152,12 +152,9 @@ impl Analytic { choice: &AnalyticsChoice, protocol_params: &ProtocolParameters, unspent_outputs: impl IntoIterator, - milestone_timestamp: MilestoneTimestamp, ) -> Self { Self(match choice { - AnalyticsChoice::AddressBalance => { - Box::new(AddressBalancesAnalytics::init(unspent_outputs, milestone_timestamp)) as _ - } + AnalyticsChoice::AddressBalance => Box::new(AddressBalancesAnalytics::init(unspent_outputs)) as _, AnalyticsChoice::BaseTokenActivity => Box::::default() as _, AnalyticsChoice::BlockActivity => Box::::default() as _, AnalyticsChoice::ActiveAddresses => Box::::default() as _, @@ -399,7 +396,7 @@ mod test { ledger::{LedgerOutput, LedgerSpent}, metadata::BlockMetadata, node::NodeConfiguration, - payload::{milestone::MilestoneTimestamp, MilestoneId, MilestonePayload}, + payload::{MilestoneId, MilestonePayload}, protocol::ProtocolParameters, tangle::{MilestoneIndex, MilestoneIndexTimestamp}, }, @@ -447,11 +444,10 @@ mod test { fn init<'a>( protocol_params: ProtocolParameters, unspent_outputs: impl IntoIterator + Copy, - milestone_timestamp: MilestoneTimestamp, ) -> Self { Self { active_addresses: Default::default(), - address_balance: AddressBalancesAnalytics::init(unspent_outputs, milestone_timestamp), + address_balance: AddressBalancesAnalytics::init(unspent_outputs), base_tokens: Default::default(), ledger_outputs: LedgerOutputMeasurement::init(unspent_outputs), ledger_size: LedgerSizeAnalytics::init(protocol_params, unspent_outputs), diff --git a/src/bin/inx-chronicle/api/error.rs b/src/bin/inx-chronicle/api/error.rs index 091fb5d71..0c51e857e 100644 --- a/src/bin/inx-chronicle/api/error.rs +++ b/src/bin/inx-chronicle/api/error.rs @@ -19,11 +19,6 @@ pub type ApiResult = Result; pub trait ErrorStatus: std::error::Error { /// Gets the HTTP status code associated with this error. fn status(&self) -> StatusCode; - - /// Gets the u16 status code representation associated with this error. - fn code(&self) -> u16 { - self.status().as_u16() - } } #[derive(Debug, Error)] diff --git a/src/bin/inx-chronicle/cli/analytics.rs b/src/bin/inx-chronicle/cli/analytics.rs index b2bf03d04..fb947cb7a 100644 --- a/src/bin/inx-chronicle/cli/analytics.rs +++ b/src/bin/inx-chronicle/cli/analytics.rs @@ -1,4 +1,4 @@ -// Copyright 2023 IOTA Stiftung +// Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 use std::collections::HashSet; @@ -23,7 +23,9 @@ use tracing::{debug, info}; use crate::config::ChronicleConfig; -/// This command accepts both milestone index and date ranges. The following rules apply: +/// This command accepts both milestone index and date ranges. +/// +/// The following rules apply: /// /// - If both milestone and date are specified, the date will be used for interval analytics /// while the milestone will be used for per-milestone analytics. @@ -264,14 +266,7 @@ pub async fn fill_analytics( let analytics = analytics_choices .iter() - .map(|choice| { - Analytic::init( - choice, - &milestone.protocol_params, - &ledger_state, - milestone.at.milestone_timestamp, - ) - }) + .map(|choice| Analytic::init(choice, &milestone.protocol_params, &ledger_state)) .collect::>(); state = Some(AnalyticsState { analytics, diff --git a/src/bin/inx-chronicle/inx/influx/analytics.rs b/src/bin/inx-chronicle/inx/influx/analytics.rs index 8e837ed43..02f76be58 100644 --- a/src/bin/inx-chronicle/inx/influx/analytics.rs +++ b/src/bin/inx-chronicle/inx/influx/analytics.rs @@ -72,14 +72,7 @@ impl InxWorker { let analytics = analytics_choices .iter() - .map(|choice| { - Analytic::init( - choice, - &milestone.protocol_params, - &ledger_state, - milestone.at.milestone_timestamp, - ) - }) + .map(|choice| Analytic::init(choice, &milestone.protocol_params, &ledger_state)) .collect::>(); *state = Some(AnalyticsState { analytics,