Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace serde/jsonschema derives with cosmwasm_schema::cw_serde #910

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions contracts/cw1-subkeys/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::fmt;

use cosmwasm_schema::cw_serde;
use cosmwasm_std::Addr;
use cw_storage_plus::Map;
use cw_utils::{Expiration, NativeBalance};
Expand All @@ -10,7 +9,8 @@ use cw_utils::{Expiration, NativeBalance};
// Could have implemented permissions for each cosmos module(StakingPermissions, GovPermissions etc...)
// But that meant a lot of code for each module. Keeping the permissions inside one struct is more
// optimal. Define other modules permissions here.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, Default, Copy)]
#[cw_serde]
#[derive(Eq, Default, Copy)]
pub struct Permissions {
pub delegate: bool,
pub redelegate: bool,
Expand All @@ -28,7 +28,8 @@ impl fmt::Display for Permissions {
}
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema, Default)]
#[cw_serde]
#[derive(Default)]
pub struct Allowance {
pub balance: NativeBalance,
pub expires: Expiration,
Expand Down
7 changes: 3 additions & 4 deletions contracts/cw1-whitelist/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use cosmwasm_schema::cw_serde;
use cosmwasm_std::Addr;
use cw_storage_plus::Item;

#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug, Default)]
#[cw_serde]
#[derive(Eq, Default)]
pub struct AdminList {
pub admins: Vec<Addr>,
pub mutable: bool,
Expand Down
4 changes: 1 addition & 3 deletions contracts/cw20-base/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{StdError, StdResult, Uint128};
use cw20::{Cw20Coin, Logo, MinterResponse};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

pub use cw20::Cw20ExecuteMsg as ExecuteMsg;

Expand Down Expand Up @@ -122,7 +120,7 @@ pub enum QueryMsg {
DownloadLogo {},
}

#[derive(Serialize, Deserialize, JsonSchema)]
#[cw_serde]
pub struct MigrateMsg {}

#[cfg(test)]
Expand Down
6 changes: 2 additions & 4 deletions contracts/cw20-ics20/src/ibc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use cosmwasm_schema::cw_serde;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
Expand All @@ -26,7 +23,8 @@ pub const ICS20_ORDERING: IbcOrder = IbcOrder::Unordered;
/// The format for sending an ics20 packet.
/// Proto defined here: https://github.com/cosmos/cosmos-sdk/blob/v0.42.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20
/// This is compatible with the JSON serialization
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug, Default)]
#[cw_serde]
#[derive(Eq, Default)]
pub struct Ics20Packet {
/// amount of tokens to transfer is encoded as a string, but limited to u64 max
pub amount: Uint128,
Expand Down
18 changes: 10 additions & 8 deletions packages/cw20/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Binary, Uint128};

Expand Down Expand Up @@ -64,7 +61,8 @@ pub struct TokenInfoResponse {
pub total_supply: Uint128,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
#[cw_serde]
#[derive(Default)]
pub struct AllowanceResponse {
pub allowance: Uint128,
pub expires: Expiration,
Expand All @@ -79,7 +77,8 @@ pub struct MinterResponse {
pub cap: Option<Uint128>,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
#[cw_serde]
#[derive(Default)]
pub struct MarketingInfoResponse {
/// A URL pointing to the project behind this token.
pub project: Option<String>,
Expand All @@ -106,7 +105,8 @@ pub struct AllowanceInfo {
pub expires: Expiration,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
#[cw_serde]
#[derive(Default)]
pub struct AllAllowancesResponse {
pub allowances: Vec<AllowanceInfo>,
}
Expand All @@ -118,12 +118,14 @@ pub struct SpenderAllowanceInfo {
pub expires: Expiration,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
#[cw_serde]
#[derive(Default)]
pub struct AllSpenderAllowancesResponse {
pub allowances: Vec<SpenderAllowanceInfo>,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug, Default)]
#[cw_serde]
#[derive(Eq, Default)]
pub struct AllAccountsResponse {
pub accounts: Vec<String>,
}
5 changes: 2 additions & 3 deletions packages/cw3/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::fmt;

use cosmwasm_schema::cw_serde;
Expand Down Expand Up @@ -31,8 +30,8 @@ where
},
}

#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, JsonSchema, Debug)]
#[serde(rename_all = "lowercase")]
#[cw_serde]
#[derive(Copy, Eq)]
Comment on lines +33 to +34
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cw_serde have rename_all = "snake_case". It shouldn't have any difference from lowercase for those variants

pub enum Vote {
/// Marks support for the proposal.
Yes,
Expand Down