Skip to content

Commit

Permalink
Merge pull request #4965 from nymtech/bugfix/invalid-gateways-response
Browse files Browse the repository at this point in the history
bugfix: fix expected return type on /v1/gateways endpoint
  • Loading branch information
jstuczyn authored Oct 11, 2024
2 parents 8113948 + 493390d commit 08aa0af
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
9 changes: 2 additions & 7 deletions common/client-libs/validator-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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?)
}

Expand Down Expand Up @@ -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?)
}

Expand Down
5 changes: 2 additions & 3 deletions common/client-libs/validator-client/src/nym_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
}
Expand Down
21 changes: 10 additions & 11 deletions explorer-api/src/gateways/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@

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;

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)]
Expand All @@ -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()
}

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions explorer-api/src/tasks.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2022 - Nym Technologies SA <[email protected]>
// 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};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 08aa0af

Please sign in to comment.