diff --git a/common/client-libs/validator-client/src/client.rs b/common/client-libs/validator-client/src/client.rs index 30ddb307b2..8ae389084a 100644 --- a/common/client-libs/validator-client/src/client.rs +++ b/common/client-libs/validator-client/src/client.rs @@ -11,11 +11,9 @@ use validator_api_requests::coconut::{ VerifyCredentialBody, VerifyCredentialResponse, }; use validator_api_requests::models::{ - DeprecatedRewardEstimationResponse, DeprecatedUptimeResponse, GatewayCoreStatusResponse, - MixnodeCoreStatusResponse, MixnodeStatusResponse, RewardEstimationResponse, - StakeSaturationResponse, + GatewayCoreStatusResponse, MixnodeCoreStatusResponse, MixnodeStatusResponse, + RewardEstimationResponse, StakeSaturationResponse, }; -use validator_api_requests::Deprecated; #[cfg(feature = "nymd-client")] use crate::nymd::traits::MixnetQueryClient; @@ -706,69 +704,4 @@ impl ApiClient { .verify_bandwidth_credential(request_body) .await?) } - - // ================================================= - // DEPRECATED ROUTES - // TO REMOVE ONCE OTHER PARTS OF THE SYSTEM MIGRATED - // ================================================= - - pub async fn deprecated_get_mixnode_core_status_count_by_identity( - &self, - identity: IdentityKeyRef<'_>, - since: Option, - ) -> Result, ValidatorClientError> { - Ok(self - .validator_api - .deprecated_get_mixnode_core_status_count_by_identity(identity, since) - .await?) - } - - pub async fn deprecated_get_mixnode_status_by_identity( - &self, - identity: IdentityKeyRef<'_>, - ) -> Result, ValidatorClientError> { - Ok(self - .validator_api - .deprecated_get_mixnode_status_by_identity(identity) - .await?) - } - - pub async fn deprecated_get_mixnode_reward_estimation_by_identity( - &self, - identity: IdentityKeyRef<'_>, - ) -> Result { - Ok(self - .validator_api - .deprecated_get_mixnode_reward_estimation_by_identity(identity) - .await?) - } - - pub async fn deprecated_get_mixnode_stake_saturation_by_identity( - &self, - identity: IdentityKeyRef<'_>, - ) -> Result, ValidatorClientError> { - Ok(self - .validator_api - .deprecated_get_mixnode_stake_saturation_by_identity(identity) - .await?) - } - - pub async fn deprecated_get_mixnode_avg_uptime_by_identity( - &self, - identity: IdentityKeyRef<'_>, - ) -> Result { - Ok(self - .validator_api - .deprecated_get_mixnode_avg_uptime_by_identity(identity) - .await?) - } - - pub async fn deprecated_get_mixnode_avg_uptimes_by_identity( - &self, - ) -> Result, ValidatorClientError> { - Ok(self - .validator_api - .deprecated_get_mixnode_avg_uptimes_by_identity() - .await?) - } } diff --git a/common/client-libs/validator-client/src/validator_api/mod.rs b/common/client-libs/validator-client/src/validator_api/mod.rs index a63e714066..2dcb50c62f 100644 --- a/common/client-libs/validator-client/src/validator_api/mod.rs +++ b/common/client-libs/validator-client/src/validator_api/mod.rs @@ -12,11 +12,10 @@ use validator_api_requests::coconut::{ VerifyCredentialBody, VerifyCredentialResponse, }; use validator_api_requests::models::{ - DeprecatedRewardEstimationResponse, DeprecatedUptimeResponse, GatewayCoreStatusResponse, - InclusionProbabilityResponse, MixNodeBondAnnotated, MixnodeCoreStatusResponse, - MixnodeStatusResponse, RewardEstimationResponse, StakeSaturationResponse, UptimeResponse, + GatewayCoreStatusResponse, InclusionProbabilityResponse, MixNodeBondAnnotated, + MixnodeCoreStatusResponse, MixnodeStatusResponse, RewardEstimationResponse, + StakeSaturationResponse, UptimeResponse, }; -use validator_api_requests::Deprecated; pub mod error; pub mod routes; @@ -378,151 +377,6 @@ impl Client { ) .await } - - // ================================================= - // DEPRECATED ROUTES - // TO REMOVE ONCE OTHER PARTS OF THE SYSTEM MIGRATED - // ================================================= - - pub async fn deprecated_get_mixnode_core_status_count_by_identity( - &self, - identity: IdentityKeyRef<'_>, - since: Option, - ) -> Result, ValidatorAPIError> { - if let Some(since) = since { - self.query_validator_api( - &[ - routes::API_VERSION, - routes::STATUS_ROUTES, - routes::MIXNODE, - routes::DEPRECATED, - identity, - CORE_STATUS_COUNT, - ], - &[(SINCE_ARG, since.to_string())], - ) - .await - } else { - self.query_validator_api( - &[ - routes::API_VERSION, - routes::STATUS_ROUTES, - routes::MIXNODE, - routes::DEPRECATED, - identity, - CORE_STATUS_COUNT, - ], - NO_PARAMS, - ) - .await - } - } - - pub async fn deprecated_get_mixnode_status_by_identity( - &self, - identity: IdentityKeyRef<'_>, - ) -> Result, ValidatorAPIError> { - self.query_validator_api( - &[ - routes::API_VERSION, - routes::STATUS_ROUTES, - routes::MIXNODE, - routes::DEPRECATED, - identity, - routes::STATUS, - ], - NO_PARAMS, - ) - .await - } - - pub async fn deprecated_get_mixnode_reward_estimation_by_identity( - &self, - identity: IdentityKeyRef<'_>, - ) -> Result { - self.query_validator_api( - &[ - routes::API_VERSION, - routes::STATUS_ROUTES, - routes::MIXNODE, - routes::DEPRECATED, - identity, - routes::REWARD_ESTIMATION, - ], - NO_PARAMS, - ) - .await - } - - pub async fn deprecated_get_mixnode_stake_saturation_by_identity( - &self, - identity: IdentityKeyRef<'_>, - ) -> Result, ValidatorAPIError> { - self.query_validator_api( - &[ - routes::API_VERSION, - routes::STATUS_ROUTES, - routes::MIXNODE, - routes::DEPRECATED, - identity, - routes::STAKE_SATURATION, - ], - NO_PARAMS, - ) - .await - } - - pub async fn deprecated_get_mixnode_inclusion_probability_by_identity( - &self, - identity: IdentityKeyRef<'_>, - ) -> Result, ValidatorAPIError> { - self.query_validator_api( - &[ - routes::API_VERSION, - routes::STATUS_ROUTES, - routes::MIXNODE, - routes::DEPRECATED, - identity, - routes::INCLUSION_CHANCE, - ], - NO_PARAMS, - ) - .await - } - - pub async fn deprecated_get_mixnode_avg_uptime_by_identity( - &self, - identity: IdentityKeyRef<'_>, - ) -> Result { - self.query_validator_api( - &[ - routes::API_VERSION, - routes::STATUS_ROUTES, - routes::MIXNODE, - routes::DEPRECATED, - identity, - routes::AVG_UPTIME, - ], - NO_PARAMS, - ) - .await - } - - pub async fn deprecated_get_mixnode_avg_uptimes_by_identity( - &self, - ) -> Result, ValidatorAPIError> { - self.query_validator_api( - &[ - routes::API_VERSION, - routes::STATUS_ROUTES, - routes::MIXNODES, - routes::DEPRECATED, - routes::AVG_UPTIME, - ], - NO_PARAMS, - ) - .await - } } // utility function that should solve the double slash problem in validator API forever. diff --git a/common/client-libs/validator-client/src/validator_api/routes.rs b/common/client-libs/validator-client/src/validator_api/routes.rs index 04e657bb46..8f1a125c80 100644 --- a/common/client-libs/validator-client/src/validator_api/routes.rs +++ b/common/client-libs/validator-client/src/validator_api/routes.rs @@ -6,7 +6,6 @@ use network_defaults::VALIDATOR_API_VERSION; pub const API_VERSION: &str = VALIDATOR_API_VERSION; pub const MIXNODES: &str = "mixnodes"; pub const GATEWAYS: &str = "gateways"; -pub const DEPRECATED: &str = "deprecated"; pub const DETAILED: &str = "detailed"; pub const ACTIVE: &str = "active"; diff --git a/explorer-api/src/mix_node/http.rs b/explorer-api/src/mix_node/http.rs index 25b1cdf4bc..95905ff5d3 100644 --- a/explorer-api/src/mix_node/http.rs +++ b/explorer-api/src/mix_node/http.rs @@ -8,7 +8,6 @@ use crate::mix_node::econ_stats::retrieve_mixnode_econ_stats; use crate::mix_node::models::{ EconomicDynamicsStats, NodeDescription, NodeStats, PrettyDetailedMixNodeBond, SummedDelegations, }; -use crate::mix_nodes; use crate::state::ExplorerApiStateContext; use mixnet_contract_common::{Delegation, NodeId}; use reqwest::Error as ReqwestError; @@ -27,15 +26,6 @@ pub fn mix_node_make_default_routes(settings: &OpenApiSettings) -> (Vec, get_description, get_stats, get_economic_dynamics_stats, - // ================================================= - // TO REMOVE ONCE OTHER PARTS OF THE SYSTEM MIGRATED - // ================================================= - deprecated_get_delegations_by_identity, - deprecated_get_delegations_summed_by_identity, - deprecated_get_by_identity, - deprecated_get_description_by_identity, - deprecated_get_stats_by_identity, - deprecated_get_economic_dynamics_stats_by_identity, ] } @@ -204,126 +194,3 @@ pub(crate) async fn get_economic_dynamics_stats( } } } - -// ================================================= -// TO REMOVE ONCE OTHER PARTS OF THE SYSTEM MIGRATED -// ================================================= - -#[openapi(tag = "mix_nodes")] -#[get("/deprecated/")] -pub(crate) async fn deprecated_get_by_identity( - pubkey: &str, - state: &State, -) -> Result, NotFound> { - let mix_id = match mix_nodes::helpers::best_effort_pubkey_to_mix_id(state, pubkey).await { - Some(mix_id) => mix_id, - None => { - warn!( - "there doesn't seem to exist a mixnode with identity {}", - pubkey - ); - return Err(NotFound("Mixnode not found".into())); - } - }; - get_by_id(mix_id, state).await -} - -#[openapi(tag = "mix_node")] -#[get("/deprecated//delegations")] -pub(crate) async fn deprecated_get_delegations_by_identity( - pubkey: &str, - state: &State, -) -> Json> { - let mix_id = match mix_nodes::helpers::best_effort_pubkey_to_mix_id(state, pubkey).await { - Some(mix_id) => mix_id, - None => { - warn!( - "there doesn't seem to exist a mixnode with identity {}", - pubkey - ); - return Json(Vec::new()); - } - }; - - get_delegations(mix_id, state).await -} - -#[openapi(tag = "mix_node")] -#[get("/deprecated//delegations/summed")] -pub(crate) async fn deprecated_get_delegations_summed_by_identity( - pubkey: &str, - state: &State, -) -> Json> { - let mix_id = match mix_nodes::helpers::best_effort_pubkey_to_mix_id(state, pubkey).await { - Some(mix_id) => mix_id, - None => { - warn!( - "there doesn't seem to exist a mixnode with identity {}", - pubkey - ); - return Json(Vec::new()); - } - }; - - get_delegations_summed(mix_id, state).await -} - -#[openapi(tag = "mix_node")] -#[get("/deprecated//description")] -pub(crate) async fn deprecated_get_description_by_identity( - pubkey: &str, - state: &State, -) -> Option> { - let mix_id = match mix_nodes::helpers::best_effort_pubkey_to_mix_id(state, pubkey).await { - Some(mix_id) => mix_id, - None => { - warn!( - "there doesn't seem to exist a mixnode with identity {}", - pubkey - ); - return None; - } - }; - - get_description(mix_id, state).await -} - -#[openapi(tag = "mix_node")] -#[get("/deprecated//stats")] -pub(crate) async fn deprecated_get_stats_by_identity( - pubkey: &str, - state: &State, -) -> Option> { - let mix_id = match mix_nodes::helpers::best_effort_pubkey_to_mix_id(state, pubkey).await { - Some(mix_id) => mix_id, - None => { - warn!( - "there doesn't seem to exist a mixnode with identity {}", - pubkey - ); - return None; - } - }; - - get_stats(mix_id, state).await -} - -#[openapi(tag = "mix_node")] -#[get("/deprecated//economic-dynamics-stats")] -pub(crate) async fn deprecated_get_economic_dynamics_stats_by_identity( - pubkey: &str, - state: &State, -) -> Option> { - let mix_id = match mix_nodes::helpers::best_effort_pubkey_to_mix_id(state, pubkey).await { - Some(mix_id) => mix_id, - None => { - warn!( - "there doesn't seem to exist a mixnode with identity {}", - pubkey - ); - return None; - } - }; - - get_economic_dynamics_stats(mix_id, state).await -} diff --git a/explorer-api/src/mix_nodes/helpers.rs b/explorer-api/src/mix_nodes/helpers.rs deleted file mode 100644 index 8dec26ebf4..0000000000 --- a/explorer-api/src/mix_nodes/helpers.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2022 - Nym Technologies SA -// SPDX-License-Identifier: Apache-2.0 - -use crate::state::ExplorerApiStateContext; -use mixnet_contract_common::NodeId; - -pub(crate) async fn best_effort_pubkey_to_mix_id( - state: &ExplorerApiStateContext, - pub_key: &str, -) -> Option { - state - .inner - .get_mix_node_by_pubkey(pub_key) - .await - .map(|node| node.mix_id()) -} diff --git a/explorer-api/src/mix_nodes/mod.rs b/explorer-api/src/mix_nodes/mod.rs index a02e2bc043..e2aced241a 100644 --- a/explorer-api/src/mix_nodes/mod.rs +++ b/explorer-api/src/mix_nodes/mod.rs @@ -3,7 +3,6 @@ use std::time::Duration; -pub(crate) mod helpers; pub(crate) mod http; pub(crate) mod location; pub(crate) mod models; diff --git a/validator-api/src/node_status_api/deprecated_routes.rs b/validator-api/src/node_status_api/deprecated_routes.rs deleted file mode 100644 index 79b4a0333f..0000000000 --- a/validator-api/src/node_status_api/deprecated_routes.rs +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright 2022 - Nym Technologies SA -// SPDX-License-Identifier: Apache-2.0 - -use crate::node_status_api::helpers::{ - _compute_mixnode_reward_estimation, _get_mixnode_avg_uptime, - _get_mixnode_inclusion_probability, _get_mixnode_reward_estimation, - _get_mixnode_stake_saturation, _get_mixnode_status, _mixnode_core_status_count, - _mixnode_report, _mixnode_uptime_history, -}; -use crate::node_status_api::models::{ErrorResponse, MixnodeStatusReport, MixnodeUptimeHistory}; -use crate::{NodeStatusCache, ValidatorApiStorage, ValidatorCache}; -use mixnet_contract_common::NodeId; -use rocket::http::Status; -use rocket::serde::json::Json; -use rocket::State; -use rocket_okapi::openapi; -use validator_api_requests::models::{ - DeprecatedComputeRewardEstParam, DeprecatedRewardEstimationResponse, DeprecatedUptimeResponse, - InclusionProbabilityResponse, MixnodeCoreStatusResponse, MixnodeStatus, MixnodeStatusResponse, - StakeSaturationResponse, -}; -use validator_api_requests::{Deprecatable, Deprecated}; - -// Note: this is a very dangerous method to call as the same identity in the past might have -// referred to a completely different node id! -async fn mixnode_identity_to_current_node_id( - storage: &ValidatorApiStorage, - identity: &str, -) -> Result { - storage - .mix_identity_to_latest_mix_id(identity) - .await - .map_err(|err| ErrorResponse::new(err.to_string(), Status::NotFound))? - .ok_or_else(|| ErrorResponse::new("no mixnode with provided identity", Status::NotFound)) -} - -#[openapi(tag = "status")] -#[get("/mixnode/deprecated//report")] -pub(crate) async fn mixnode_report_by_identity( - storage: &State, - identity: &str, -) -> Result>, ErrorResponse> { - let mix_id = mixnode_identity_to_current_node_id(storage, identity).await?; - Ok(Json(_mixnode_report(storage, mix_id).await?.deprecate())) -} - -#[openapi(tag = "status")] -#[get("/mixnode/deprecated//history")] -pub(crate) async fn mixnode_uptime_history_by_identity( - storage: &State, - identity: &str, -) -> Result>, ErrorResponse> { - let mix_id = mixnode_identity_to_current_node_id(storage, identity).await?; - Ok(Json( - _mixnode_uptime_history(storage, mix_id).await?.deprecate(), - )) -} - -#[openapi(tag = "status")] -#[get("/mixnode/deprecated//core-status-count?")] -pub(crate) async fn mixnode_core_status_count_by_identity( - storage: &State, - identity: &str, - since: Option, -) -> Result>, ErrorResponse> { - let mix_id = mixnode_identity_to_current_node_id(storage, identity).await?; - Ok(Json( - _mixnode_core_status_count(storage, mix_id, since) - .await? - .deprecate(), - )) -} - -#[openapi(tag = "status")] -#[get("/mixnode/deprecated//status")] -pub(crate) async fn get_mixnode_status_by_identity( - storage: &State, - cache: &State, - identity: &str, -) -> Json> { - match mixnode_identity_to_current_node_id(storage, identity).await { - Ok(mix_id) => Json(_get_mixnode_status(cache, mix_id).await.deprecate()), - Err(_) => Json( - MixnodeStatusResponse { - status: MixnodeStatus::NotFound, - } - .deprecate(), - ), - } -} - -#[openapi(tag = "status")] -#[get("/mixnode/deprecated//reward-estimation")] -pub(crate) async fn get_mixnode_reward_estimation_by_identity( - cache: &State, - storage: &State, - identity: &str, -) -> Result, ErrorResponse> { - let mix_id = mixnode_identity_to_current_node_id(storage, identity).await?; - let new_estimation = _get_mixnode_reward_estimation(cache, mix_id).await?; - - Ok(Json(new_estimation.into())) -} - -#[openapi(tag = "status")] -#[post( - "/mixnode/deprecated//compute-reward-estimation", - data = "" -)] -pub(crate) async fn compute_mixnode_reward_estimation_by_identity( - user_reward_param: Json, - cache: &State, - storage: &State, - identity: &str, -) -> Result, ErrorResponse> { - let mix_id = mixnode_identity_to_current_node_id(storage, identity).await?; - let estimation = - _compute_mixnode_reward_estimation(user_reward_param.into_inner().into(), cache, mix_id) - .await?; - - Ok(Json(estimation.into())) -} - -#[openapi(tag = "status")] -#[get("/mixnode/deprecated//stake-saturation")] -pub(crate) async fn get_mixnode_stake_saturation_by_identity( - cache: &State, - storage: &State, - identity: &str, -) -> Result>, ErrorResponse> { - let mix_id = mixnode_identity_to_current_node_id(storage, identity).await?; - - Ok(Json( - _get_mixnode_stake_saturation(cache, mix_id) - .await? - .deprecate(), - )) -} - -#[openapi(tag = "status")] -#[get("/mixnode/deprecated//inclusion-probability")] -pub(crate) async fn get_mixnode_inclusion_probability_by_identity( - cache: &State, - storage: &State, - identity: &str, -) -> Result>, ErrorResponse> { - let mix_id = mixnode_identity_to_current_node_id(storage, identity).await?; - - Ok(Json( - _get_mixnode_inclusion_probability(cache, mix_id) - .await? - .deprecate(), - )) -} - -#[openapi(tag = "status")] -#[get("/mixnode/deprecated//avg_uptime")] -pub(crate) async fn get_mixnode_avg_uptime_by_identity( - cache: &State, - storage: &State, - identity: &str, -) -> Result, ErrorResponse> { - let mix_id = mixnode_identity_to_current_node_id(storage, identity).await?; - - let new_response = _get_mixnode_avg_uptime(cache, storage, mix_id).await?; - - Ok(Json(DeprecatedUptimeResponse { - identity: identity.into(), - avg_uptime: new_response.avg_uptime, - deprecated: true, - })) -} - -// DEPRECATED: the uptime is available as part of the `/mixnodes/detailed` endpoint -#[openapi(tag = "status")] -#[get("/mixnodes/deprecated/avg_uptime")] -pub(crate) async fn get_mixnode_avg_uptimes_by_identity( - cache: &State, - storage: &State, -) -> Result>, ErrorResponse> { - let mixnodes = cache.mixnodes().await; - - let mut response = Vec::new(); - for mixnode in mixnodes { - let new_response = _get_mixnode_avg_uptime(cache, storage, mixnode.mix_id()).await?; - - response.push(DeprecatedUptimeResponse { - identity: mixnode.bond_information.identity().into(), - avg_uptime: new_response.avg_uptime, - deprecated: true, - }) - } - - Ok(Json(response)) -} diff --git a/validator-api/src/node_status_api/mod.rs b/validator-api/src/node_status_api/mod.rs index 125e2ea44c..08cf612dba 100644 --- a/validator-api/src/node_status_api/mod.rs +++ b/validator-api/src/node_status_api/mod.rs @@ -7,7 +7,6 @@ use rocket::Route; use rocket_okapi::{openapi_get_routes_spec, settings::OpenApiSettings}; use std::time::Duration; pub(crate) mod cache; -pub(crate) mod deprecated_routes; pub(crate) mod helpers; pub(crate) mod local_guard; pub(crate) mod models; @@ -38,19 +37,6 @@ pub(crate) fn node_status_routes( routes::get_mixnode_inclusion_probability, routes::get_mixnode_avg_uptime, routes::get_mixnode_inclusion_probabilities, - // ================================================= - // TO REMOVE ONCE OTHER PARTS OF THE SYSTEM MIGRATED - // ================================================= - deprecated_routes::mixnode_report_by_identity, - deprecated_routes::mixnode_uptime_history_by_identity, - deprecated_routes::mixnode_core_status_count_by_identity, - deprecated_routes::get_mixnode_status_by_identity, - deprecated_routes::get_mixnode_reward_estimation_by_identity, - deprecated_routes::compute_mixnode_reward_estimation_by_identity, - deprecated_routes::get_mixnode_stake_saturation_by_identity, - deprecated_routes::get_mixnode_inclusion_probability_by_identity, - deprecated_routes::get_mixnode_avg_uptime_by_identity, - deprecated_routes::get_mixnode_avg_uptimes_by_identity, ] } else { // in the minimal variant we would not have access to endpoints relying on existence @@ -60,12 +46,6 @@ pub(crate) fn node_status_routes( routes::get_mixnode_stake_saturation, routes::get_mixnode_inclusion_probability, routes::get_mixnode_inclusion_probabilities, - // ================================================= - // TO REMOVE ONCE OTHER PARTS OF THE SYSTEM MIGRATED - // ================================================= - deprecated_routes::get_mixnode_status_by_identity, - deprecated_routes::get_mixnode_stake_saturation_by_identity, - deprecated_routes::get_mixnode_inclusion_probability_by_identity, ] } } diff --git a/validator-api/src/storage/mod.rs b/validator-api/src/storage/mod.rs index e6e62681bf..a6ef8b044a 100644 --- a/validator-api/src/storage/mod.rs +++ b/validator-api/src/storage/mod.rs @@ -71,6 +71,7 @@ impl ValidatorApiStorage { }) } + #[allow(unused)] pub(crate) async fn mix_identity_to_mix_ids( &self, identity: &str, @@ -81,6 +82,7 @@ impl ValidatorApiStorage { .await?) } + #[allow(unused)] pub(crate) async fn mix_identity_to_latest_mix_id( &self, identity: &str, diff --git a/validator-api/validator-api-requests/src/models.rs b/validator-api/validator-api-requests/src/models.rs index 368e3ca8b2..248164ac46 100644 --- a/validator-api/validator-api-requests/src/models.rs +++ b/validator-api/validator-api-requests/src/models.rs @@ -4,7 +4,6 @@ use cosmwasm_std::Decimal; use mixnet_contract_common::mixnode::MixNodeDetails; use mixnet_contract_common::reward_params::{Performance, RewardingParams}; -use mixnet_contract_common::rewarding::helpers::truncate_reward_amount; use mixnet_contract_common::rewarding::RewardEstimate; use mixnet_contract_common::{Interval, MixNode, NodeId, RewardedSetNodeStatus}; use schemars::JsonSchema; @@ -213,103 +212,3 @@ pub struct InclusionProbability { pub in_active: f64, pub in_reserve: f64, } - -// deprecated - -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] -pub struct DeprecatedUptimeResponse { - pub identity: String, - pub avg_uptime: u8, - pub deprecated: bool, -} - -#[derive(Deserialize, JsonSchema)] -pub struct DeprecatedComputeRewardEstParam { - pub uptime: Option, - pub is_active: Option, - pub pledge_amount: Option, - pub total_delegation: Option, - pub deprecated: bool, -} - -impl From for ComputeRewardEstParam { - fn from(deprecated_params: DeprecatedComputeRewardEstParam) -> Self { - ComputeRewardEstParam { - performance: deprecated_params - .uptime - .map(|u| Performance::from_percentage_value(u as u64).unwrap_or_default()), - active_in_rewarded_set: deprecated_params.is_active, - pledge_amount: deprecated_params.pledge_amount, - total_delegation: deprecated_params.total_delegation, - } - } -} - -impl From for DeprecatedComputeRewardEstParam { - fn from(new_params: ComputeRewardEstParam) -> Self { - DeprecatedComputeRewardEstParam { - uptime: new_params.performance.map(|p| p.round_to_integer()), - is_active: new_params.active_in_rewarded_set, - pledge_amount: new_params.pledge_amount, - total_delegation: new_params.total_delegation, - deprecated: true, - } - } -} - -#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)] -pub struct DeprecatedRewardEstimationResponse { - pub estimated_total_node_reward: u64, - pub estimated_operator_reward: u64, - pub estimated_delegators_reward: u64, - pub estimated_node_profit: u64, - pub estimated_operator_cost: u64, - - pub reward_params: RewardingParams, - pub as_at: i64, - pub deprecated: bool, -} - -impl From for DeprecatedRewardEstimationResponse { - fn from(new_estimation: RewardEstimationResponse) -> Self { - DeprecatedRewardEstimationResponse { - estimated_total_node_reward: truncate_reward_amount( - new_estimation.estimation.total_node_reward, - ) - .u128() - .try_into() - .unwrap_or_default(), - estimated_operator_reward: truncate_reward_amount(new_estimation.estimation.operator) - .u128() - .try_into() - .unwrap_or_default(), - estimated_delegators_reward: truncate_reward_amount( - new_estimation.estimation.delegates, - ) - .u128() - .try_into() - .unwrap_or_default(), - estimated_node_profit: if new_estimation.estimation.operator - < new_estimation.estimation.operating_cost - { - 0 - } else { - truncate_reward_amount( - new_estimation.estimation.operator - new_estimation.estimation.operating_cost, - ) - .u128() - .try_into() - .unwrap_or_default() - }, - estimated_operator_cost: truncate_reward_amount( - new_estimation.estimation.operating_cost, - ) - .u128() - .try_into() - .unwrap_or_default(), - reward_params: new_estimation.reward_params, - as_at: new_estimation.as_at, - deprecated: true, - } - } -}