From 704b1932f84833f37a74c8439d02d47da8efca2c Mon Sep 17 00:00:00 2001 From: egasimus Date: Mon, 26 Aug 2024 19:26:56 +0300 Subject: [PATCH 1/7] derive Serialize for PosParams and OwnedPosParams this would enable our client library `@fadroma/namada` to automatically convert the response from `/vp/pos/pos_params` without having to explicitly list every field (see https://github.com/hackbg/fadroma/blob/e7d5d551f818a6441ef54309a2517792b03ee7d3/packages/namada/src/decode.rs#L201-L223) --- crates/proof_of_stake/src/parameters.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/proof_of_stake/src/parameters.rs b/crates/proof_of_stake/src/parameters.rs index 6d63529f06..050f4e4cca 100644 --- a/crates/proof_of_stake/src/parameters.rs +++ b/crates/proof_of_stake/src/parameters.rs @@ -3,6 +3,7 @@ use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; +use serde::{Serialize, Deserialize}; use namada_core::arith::checked; use namada_core::dec::Dec; use namada_core::storage::Epoch; @@ -17,7 +18,7 @@ use thiserror::Error; /// Proof-of-Stake system parameters. This includes parameters that are used in /// PoS but are read from other accounts storage (governance). -#[derive(Debug, Clone, BorshDeserialize, BorshDeserializer, BorshSerialize)] +#[derive(Debug, Clone, BorshDeserialize, BorshDeserializer, BorshSerialize, Serialize)] pub struct PosParams { /// PoS-owned params pub owned: OwnedPosParams, @@ -28,7 +29,7 @@ pub struct PosParams { /// Proof-of-Stake system parameters owned by the PoS address, set at genesis /// and can only be changed via governance -#[derive(Debug, Clone, BorshDeserialize, BorshDeserializer, BorshSerialize)] +#[derive(Debug, Clone, BorshDeserialize, BorshDeserializer, BorshSerialize, Serialize)] pub struct OwnedPosParams { /// A maximum number of consensus validators pub max_validator_slots: u64, From 0e883487783a23ca2125e01ab1ccf413cbad0ce2 Mon Sep 17 00:00:00 2001 From: egasimus Date: Mon, 26 Aug 2024 19:29:15 +0300 Subject: [PATCH 2/7] derive Serialize for GovernanceParameters this would enable @fadroma/namada to automatically serialize the response from `/vp/governance/parameters` to JSON without having to explicitly list each field (see https://github.com/hackbg/fadroma/blob/e7d5d551f818a6441ef54309a2517792b03ee7d3/packages/namada/src/decode.rs#L201-L223) --- crates/governance/src/parameters.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/governance/src/parameters.rs b/crates/governance/src/parameters.rs index 77a60cc8bc..60facf7cb2 100644 --- a/crates/governance/src/parameters.rs +++ b/crates/governance/src/parameters.rs @@ -1,3 +1,4 @@ +use serde::Serialize; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; use namada_core::token; use namada_macros::BorshDeserializer; @@ -18,6 +19,7 @@ use super::storage::keys as goverance_storage; BorshSerialize, BorshDeserialize, BorshDeserializer, + Serialize, )] /// Governance parameter structure pub struct GovernanceParameters { From 1673cafa8702bd1e52ddc48c974008e1014a8861 Mon Sep 17 00:00:00 2001 From: egasimus Date: Mon, 26 Aug 2024 20:26:42 +0300 Subject: [PATCH 3/7] remove unused serde::Deserialize import --- crates/proof_of_stake/src/parameters.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/proof_of_stake/src/parameters.rs b/crates/proof_of_stake/src/parameters.rs index 050f4e4cca..6150ba8bb9 100644 --- a/crates/proof_of_stake/src/parameters.rs +++ b/crates/proof_of_stake/src/parameters.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; -use serde::{Serialize, Deserialize}; +use serde::Serialize; use namada_core::arith::checked; use namada_core::dec::Dec; use namada_core::storage::Epoch; From f34c144909c242933b30fcd354f799b5b9081c09 Mon Sep 17 00:00:00 2001 From: egasimus Date: Mon, 26 Aug 2024 20:49:06 +0300 Subject: [PATCH 4/7] fix clippy lint in around PosParams and OwnedPosParams --- crates/proof_of_stake/src/parameters.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/proof_of_stake/src/parameters.rs b/crates/proof_of_stake/src/parameters.rs index 6150ba8bb9..acd56a3a86 100644 --- a/crates/proof_of_stake/src/parameters.rs +++ b/crates/proof_of_stake/src/parameters.rs @@ -18,7 +18,9 @@ use thiserror::Error; /// Proof-of-Stake system parameters. This includes parameters that are used in /// PoS but are read from other accounts storage (governance). -#[derive(Debug, Clone, BorshDeserialize, BorshDeserializer, BorshSerialize, Serialize)] +#[derive( + Debug, Clone, BorshDeserialize, BorshDeserializer, BorshSerialize, Serialize +)] pub struct PosParams { /// PoS-owned params pub owned: OwnedPosParams, @@ -29,7 +31,9 @@ pub struct PosParams { /// Proof-of-Stake system parameters owned by the PoS address, set at genesis /// and can only be changed via governance -#[derive(Debug, Clone, BorshDeserialize, BorshDeserializer, BorshSerialize, Serialize)] +#[derive( + Debug, Clone, BorshDeserialize, BorshDeserializer, BorshSerialize, Serialize +)] pub struct OwnedPosParams { /// A maximum number of consensus validators pub max_validator_slots: u64, From a42a80292281ba746273fe03fd8545cfb95c46ea Mon Sep 17 00:00:00 2001 From: Adam A Date: Tue, 27 Aug 2024 03:23:49 +0300 Subject: [PATCH 5/7] chore: make fmt --- crates/governance/src/parameters.rs | 2 +- crates/proof_of_stake/src/parameters.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/governance/src/parameters.rs b/crates/governance/src/parameters.rs index 60facf7cb2..c1fbc3dead 100644 --- a/crates/governance/src/parameters.rs +++ b/crates/governance/src/parameters.rs @@ -1,10 +1,10 @@ -use serde::Serialize; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; use namada_core::token; use namada_macros::BorshDeserializer; #[cfg(feature = "migrations")] use namada_migrations::*; use namada_state::{StorageRead, StorageResult, StorageWrite}; +use serde::Serialize; use super::storage::keys as goverance_storage; diff --git a/crates/proof_of_stake/src/parameters.rs b/crates/proof_of_stake/src/parameters.rs index acd56a3a86..74831b3853 100644 --- a/crates/proof_of_stake/src/parameters.rs +++ b/crates/proof_of_stake/src/parameters.rs @@ -3,7 +3,6 @@ use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; -use serde::Serialize; use namada_core::arith::checked; use namada_core::dec::Dec; use namada_core::storage::Epoch; @@ -14,12 +13,13 @@ use namada_governance::parameters::GovernanceParameters; use namada_macros::BorshDeserializer; #[cfg(feature = "migrations")] use namada_migrations::*; +use serde::Serialize; use thiserror::Error; /// Proof-of-Stake system parameters. This includes parameters that are used in /// PoS but are read from other accounts storage (governance). #[derive( - Debug, Clone, BorshDeserialize, BorshDeserializer, BorshSerialize, Serialize + Debug, Clone, BorshDeserialize, BorshDeserializer, BorshSerialize, Serialize, )] pub struct PosParams { /// PoS-owned params @@ -32,7 +32,7 @@ pub struct PosParams { /// Proof-of-Stake system parameters owned by the PoS address, set at genesis /// and can only be changed via governance #[derive( - Debug, Clone, BorshDeserialize, BorshDeserializer, BorshSerialize, Serialize + Debug, Clone, BorshDeserialize, BorshDeserializer, BorshSerialize, Serialize, )] pub struct OwnedPosParams { /// A maximum number of consensus validators From 18a1fedff92d475928418bc33bf82012d3793c8e Mon Sep 17 00:00:00 2001 From: Adam A Date: Tue, 27 Aug 2024 03:29:26 +0300 Subject: [PATCH 6/7] chore: update changelog --- .changelog/unreleased/SDK/3702-main.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/SDK/3702-main.md diff --git a/.changelog/unreleased/SDK/3702-main.md b/.changelog/unreleased/SDK/3702-main.md new file mode 100644 index 0000000000..9996b8aa1e --- /dev/null +++ b/.changelog/unreleased/SDK/3702-main.md @@ -0,0 +1,2 @@ +- Implement serde::Serialize for GovernanceParameters, PosParams, OwnedPosParams + ([\#3702](https://github.com/anoma/namada/pull/3702)) \ No newline at end of file From 66ea996630792cc269a395c69c91d0df2d3e7b35 Mon Sep 17 00:00:00 2001 From: Adam A Date: Thu, 29 Aug 2024 13:34:04 +0300 Subject: [PATCH 7/7] move changelog entry from invalid directory --- .changelog/unreleased/{SDK => improvements}/3702-main.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/unreleased/{SDK => improvements}/3702-main.md (100%) diff --git a/.changelog/unreleased/SDK/3702-main.md b/.changelog/unreleased/improvements/3702-main.md similarity index 100% rename from .changelog/unreleased/SDK/3702-main.md rename to .changelog/unreleased/improvements/3702-main.md