Skip to content

Commit

Permalink
bugfix: introduce 'LegacyPendingMixNodeChanges' that does not contain…
Browse files Browse the repository at this point in the history
… 'cost_params_change'
  • Loading branch information
jstuczyn committed Oct 24, 2024
1 parent d2df542 commit 89700b7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
30 changes: 28 additions & 2 deletions common/cosmwasm-smart-contracts/mixnet-contract/src/mixnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Coin, Decimal, StdResult, Uint128};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};

/// Full details associated with given mixnode.
Expand Down Expand Up @@ -647,14 +648,39 @@ impl From<LegacyMixLayer> for u8 {
export_to = "ts-packages/types/src/types/rust/PendingMixnodeChanges.ts"
)
)]
#[cw_serde]
#[derive(Default, Copy)]
// note: we had to remove `#[cw_serde]` as it enforces `#[serde(deny_unknown_fields)]` which we do not want
// with the addition of .cost_params_change field
#[derive(
::cosmwasm_schema::serde::Serialize,
::cosmwasm_schema::serde::Deserialize,
::std::clone::Clone,
::std::fmt::Debug,
::std::cmp::PartialEq,
::cosmwasm_schema::schemars::JsonSchema,
Default,
Copy,
)]
#[schemars(crate = "::cosmwasm_schema::schemars")]
pub struct PendingMixNodeChanges {
pub pledge_change: Option<EpochEventId>,

#[serde(default)]
pub cost_params_change: Option<IntervalEventId>,
}

#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct LegacyPendingMixNodeChanges {
pub pledge_change: Option<EpochEventId>,
}

impl From<PendingMixNodeChanges> for LegacyPendingMixNodeChanges {
fn from(value: PendingMixNodeChanges) -> Self {
LegacyPendingMixNodeChanges {
pledge_change: value.pledge_change,
}
}
}

impl PendingMixNodeChanges {
pub fn new_empty() -> PendingMixNodeChanges {
PendingMixNodeChanges {
Expand Down
18 changes: 3 additions & 15 deletions nym-api/nym-api-requests/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
// SPDX-License-Identifier: GPL-3.0-only

use cosmwasm_std::Decimal;
use nym_mixnet_contract_common::mixnode::PendingMixNodeChanges;
use nym_mixnet_contract_common::{
GatewayBond, LegacyMixLayer, MixNodeBond, MixNodeDetails, NodeId, NodeRewarding,
};
use nym_mixnet_contract_common::mixnode::LegacyPendingMixNodeChanges;
use nym_mixnet_contract_common::{GatewayBond, LegacyMixLayer, MixNodeBond, NodeId, NodeRewarding};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::ops::Deref;
Expand Down Expand Up @@ -64,7 +62,7 @@ pub struct LegacyMixNodeDetailsWithLayer {

/// Adjustments to the mixnode that are ought to happen during future epoch transitions.
#[serde(default)]
pub pending_changes: PendingMixNodeChanges,
pub pending_changes: LegacyPendingMixNodeChanges,
}

impl LegacyMixNodeDetailsWithLayer {
Expand All @@ -80,13 +78,3 @@ impl LegacyMixNodeDetailsWithLayer {
self.bond_information.is_unbonding
}
}

impl From<LegacyMixNodeDetailsWithLayer> for MixNodeDetails {
fn from(value: LegacyMixNodeDetailsWithLayer) -> Self {
MixNodeDetails {
bond_information: value.bond_information.into(),
rewarding_details: value.rewarding_details,
pending_changes: value.pending_changes,
}
}
}
2 changes: 1 addition & 1 deletion nym-api/src/nym_contract_cache/cache/refresher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl NymContractCacheRefresher {
layer,
},
rewarding_details: detail.rewarding_details,
pending_changes: detail.pending_changes,
pending_changes: detail.pending_changes.into(),
})
}

Expand Down

0 comments on commit 89700b7

Please sign in to comment.