Merge pull request #4965 from nymtech/bugfix/invalid-gateways-response

bugfix: fix expected return type on /v1/gateways endpoint
This commit is contained in:
Jędrzej Stuczyński
2024-10-11 17:50:16 +01:00
committed by GitHub
4 changed files with 16 additions and 25 deletions
@@ -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<C, S> Client<C, S> {
Ok(self.nym_api.get_active_mixnodes_detailed().await?)
}
pub async fn get_cached_gateways(
&self,
) -> Result<Vec<LegacyGatewayBondWithId>, ValidatorClientError> {
pub async fn get_cached_gateways(&self) -> Result<Vec<GatewayBond>, 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<Vec<LegacyGatewayBondWithId>, ValidatorClientError> {
pub async fn get_cached_gateways(&self) -> Result<Vec<GatewayBond>, ValidatorClientError> {
Ok(self.nym_api.get_gateways().await?)
}
@@ -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<Vec<LegacyGatewayBondWithId>, NymAPIError> {
async fn get_gateways(&self) -> Result<Vec<GatewayBond>, NymAPIError> {
self.get_json(&[routes::API_VERSION, routes::GATEWAYS], NO_PARAMS)
.await
}
+10 -11
View File
@@ -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<IdentityKey, LegacyGatewayBondWithId>,
pub(crate) gateways: Cache<IdentityKey, GatewayBond>,
}
#[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<LegacyGatewayBondWithId> {
pub(crate) async fn get_gateways(&self) -> Vec<GatewayBond> {
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<LegacyGatewayBondWithId>) {
pub(crate) async fn update_cache(&self, gateways: Vec<GatewayBond>) {
let mut guard = self.gateways.write().await;
for gateway in gateways {
+2 -4
View File
@@ -1,8 +1,8 @@
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
// 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<Vec<LegacyGatewayBondWithId>, ValidatorClientError> {
async fn retrieve_all_gateways(&self) -> Result<Vec<GatewayBond>, ValidatorClientError> {
info!("About to retrieve all gateways...");
self.state
.inner