From 493390d92bbdcf67828b54b467143f0a7a97d669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Fri, 11 Oct 2024 16:05:53 +0100 Subject: [PATCH] bugfix: fix expected return type on /v1/gateways endpoint --- .../validator-client/src/client.rs | 9 ++------ .../validator-client/src/nym_api/mod.rs | 5 ++--- explorer-api/src/gateways/models.rs | 21 +++++++++---------- explorer-api/src/tasks.rs | 6 ++---- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/common/client-libs/validator-client/src/client.rs b/common/client-libs/validator-client/src/client.rs index eee67ba509..fc68ae748c 100644 --- a/common/client-libs/validator-client/src/client.rs +++ b/common/client-libs/validator-client/src/client.rs @@ -17,7 +17,6 @@ use nym_api_requests::ecash::{ BlindSignRequestBody, BlindedSignatureResponse, PartialCoinIndicesSignatureResponse, PartialExpirationDateSignatureResponse, VerificationKeyResponse, }; -use nym_api_requests::legacy::LegacyGatewayBondWithId; use nym_api_requests::models::{ GatewayCoreStatusResponse, MixnodeCoreStatusResponse, MixnodeStatusResponse, RewardEstimationResponse, StakeSaturationResponse, @@ -240,9 +239,7 @@ impl Client { Ok(self.nym_api.get_active_mixnodes_detailed().await?) } - pub async fn get_cached_gateways( - &self, - ) -> Result, ValidatorClientError> { + pub async fn get_cached_gateways(&self) -> Result, ValidatorClientError> { Ok(self.nym_api.get_gateways().await?) } @@ -324,9 +321,7 @@ impl NymApiClient { Ok(self.nym_api.get_mixnodes().await?) } - pub async fn get_cached_gateways( - &self, - ) -> Result, ValidatorClientError> { + pub async fn get_cached_gateways(&self) -> Result, ValidatorClientError> { Ok(self.nym_api.get_gateways().await?) } diff --git a/common/client-libs/validator-client/src/nym_api/mod.rs b/common/client-libs/validator-client/src/nym_api/mod.rs index 2ecadd7641..a664a503ab 100644 --- a/common/client-libs/validator-client/src/nym_api/mod.rs +++ b/common/client-libs/validator-client/src/nym_api/mod.rs @@ -10,7 +10,6 @@ use nym_api_requests::ecash::models::{ VerifyEcashTicketBody, }; use nym_api_requests::ecash::VerificationKeyResponse; -use nym_api_requests::legacy::LegacyGatewayBondWithId; use nym_api_requests::models::{ AnnotationResponse, LegacyDescribedMixNode, NodePerformanceResponse, }; @@ -38,7 +37,7 @@ use nym_contracts_common::IdentityKey; pub use nym_http_api_client::Client; use nym_http_api_client::{ApiClient, NO_PARAMS}; use nym_mixnet_contract_common::mixnode::MixNodeDetails; -use nym_mixnet_contract_common::{IdentityKeyRef, NodeId}; +use nym_mixnet_contract_common::{GatewayBond, IdentityKeyRef, NodeId}; use time::format_description::BorrowedFormatItem; use time::Date; @@ -98,7 +97,7 @@ pub trait NymApiClientExt: ApiClient { .await } - async fn get_gateways(&self) -> Result, NymAPIError> { + async fn get_gateways(&self) -> Result, NymAPIError> { self.get_json(&[routes::API_VERSION, routes::GATEWAYS], NO_PARAMS) .await } diff --git a/explorer-api/src/gateways/models.rs b/explorer-api/src/gateways/models.rs index c3a2cd9062..a3ed406067 100644 --- a/explorer-api/src/gateways/models.rs +++ b/explorer-api/src/gateways/models.rs @@ -3,8 +3,7 @@ use crate::{cache::Cache, location::LocationCacheItem}; use nym_explorer_api_requests::{Location, PrettyDetailedGatewayBond}; -use nym_mixnet_contract_common::IdentityKey; -use nym_validator_client::legacy::LegacyGatewayBondWithId; +use nym_mixnet_contract_common::{GatewayBond, IdentityKey}; use serde::Serialize; use std::{sync::Arc, time::SystemTime}; use tokio::sync::RwLock; @@ -12,7 +11,7 @@ use tokio::sync::RwLock; use super::location::GatewayLocationCache; pub(crate) struct GatewayCache { - pub(crate) gateways: Cache, + pub(crate) gateways: Cache, } #[derive(Clone, Debug, Serialize, JsonSchema)] @@ -38,20 +37,20 @@ impl ThreadsafeGatewayCache { fn create_detailed_gateway( &self, - bond: LegacyGatewayBondWithId, + bond: GatewayBond, location: Option<&LocationCacheItem>, ) -> PrettyDetailedGatewayBond { PrettyDetailedGatewayBond { - pledge_amount: bond.bond.pledge_amount, - owner: bond.bond.owner, - block_height: bond.bond.block_height, - gateway: bond.bond.gateway, - proxy: bond.bond.proxy, + pledge_amount: bond.pledge_amount, + owner: bond.owner, + block_height: bond.block_height, + gateway: bond.gateway, + proxy: bond.proxy, location: location.and_then(|l| l.location.clone()), } } - pub(crate) async fn get_gateways(&self) -> Vec { + pub(crate) async fn get_gateways(&self) -> Vec { self.gateways.read().await.gateways.get_all() } @@ -107,7 +106,7 @@ impl ThreadsafeGatewayCache { .insert(identy_key, LocationCacheItem::new_from_location(location)); } - pub(crate) async fn update_cache(&self, gateways: Vec) { + pub(crate) async fn update_cache(&self, gateways: Vec) { let mut guard = self.gateways.write().await; for gateway in gateways { diff --git a/explorer-api/src/tasks.rs b/explorer-api/src/tasks.rs index 52c0192538..f14408f1c8 100644 --- a/explorer-api/src/tasks.rs +++ b/explorer-api/src/tasks.rs @@ -1,8 +1,8 @@ // Copyright 2022 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +use nym_mixnet_contract_common::GatewayBond; use nym_task::TaskClient; -use nym_validator_client::legacy::LegacyGatewayBondWithId; use nym_validator_client::models::MixNodeBondAnnotated; use nym_validator_client::nyxd::error::NyxdError; use nym_validator_client::nyxd::{Paging, TendermintRpcClient, ValidatorResponse}; @@ -47,9 +47,7 @@ impl ExplorerApiTasks { .await } - async fn retrieve_all_gateways( - &self, - ) -> Result, ValidatorClientError> { + async fn retrieve_all_gateways(&self) -> Result, ValidatorClientError> { info!("About to retrieve all gateways..."); self.state .inner