Skip to content

Commit

Permalink
Merge pull request #159 from CosmWasm/weight-0-vs-not-member
Browse files Browse the repository at this point in the history
Weight 0 vs not member
  • Loading branch information
ethanfrey authored Dec 7, 2020
2 parents 5c6a76c + 41e07a5 commit f996203
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 36 deletions.
2 changes: 1 addition & 1 deletion contracts/cw3-fixed-multisig/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
}
},
{
"description": "Returns VoterResponse",
"description": "Returns VoterInfo",
"type": "object",
"required": [
"voter"
Expand Down
11 changes: 4 additions & 7 deletions contracts/cw3-fixed-multisig/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cw0::{maybe_canonical, Expiration};
use cw2::set_contract_version;
use cw3::{
ProposalListResponse, ProposalResponse, Status, ThresholdResponse, Vote, VoteInfo,
VoteListResponse, VoteResponse, VoterListResponse, VoterResponse,
VoteListResponse, VoteResponse, VoterInfo, VoterListResponse, VoterResponse,
};
use cw_storage_plus::Bound;

Expand Down Expand Up @@ -400,13 +400,10 @@ fn list_votes(
Ok(VoteListResponse { votes: votes? })
}

fn query_voter(deps: Deps, voter: HumanAddr) -> StdResult<VoterResponse> {
fn query_voter(deps: Deps, voter: HumanAddr) -> StdResult<VoterInfo> {
let voter_raw = deps.api.canonical_address(&voter)?;
let weight = VOTERS.may_load(deps.storage, &voter_raw)?;
Ok(VoterResponse {
addr: voter,
weight,
})
Ok(VoterInfo { weight })
}

fn list_voters(
Expand All @@ -426,7 +423,7 @@ fn list_voters(
let (key, weight) = item?;
Ok(VoterResponse {
addr: api.human_address(&CanonicalAddr::from(key))?,
weight: Some(weight),
weight,
})
})
.collect();
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw3-fixed-multisig/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub enum QueryMsg {
start_after: Option<HumanAddr>,
limit: Option<u32>,
},
/// Returns VoterResponse
/// Returns VoterInfo
Voter { address: HumanAddr },
/// Returns VoterListResponse
ListVoters {
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw3-flex-multisig/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
}
},
{
"description": "Returns VoterResponse",
"description": "Returns VoterInfo",
"type": "object",
"required": [
"voter"
Expand Down
13 changes: 5 additions & 8 deletions contracts/cw3-flex-multisig/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cw0::{maybe_canonical, Expiration};
use cw2::set_contract_version;
use cw3::{
ProposalListResponse, ProposalResponse, Status, ThresholdResponse, Vote, VoteInfo,
VoteListResponse, VoteResponse, VoterListResponse, VoterResponse,
VoteListResponse, VoteResponse, VoterInfo, VoterListResponse, VoterResponse,
};
use cw4::Cw4Contract;
use cw_storage_plus::Bound;
Expand Down Expand Up @@ -404,15 +404,12 @@ fn list_votes(
Ok(VoteListResponse { votes: votes? })
}

fn query_voter(deps: Deps, voter: HumanAddr) -> StdResult<VoterResponse> {
fn query_voter(deps: Deps, voter: HumanAddr) -> StdResult<VoterInfo> {
let cfg = CONFIG.load(deps.storage)?;
let voter_raw = deps.api.canonical_address(&voter)?;
let weight = cfg.group_addr.is_member(&deps.querier, &voter_raw)?;

Ok(VoterResponse {
addr: voter,
weight,
})
Ok(VoterInfo { weight })
}

fn list_voters(
Expand All @@ -427,7 +424,7 @@ fn list_voters(
.into_iter()
.map(|member| VoterResponse {
addr: member.addr,
weight: Some(member.weight),
weight: member.weight,
})
.collect();
Ok(VoterListResponse { voters })
Expand Down Expand Up @@ -610,7 +607,7 @@ mod tests {
voters.voters,
vec![VoterResponse {
addr: OWNER.into(),
weight: Some(1)
weight: 1
}]
);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw3-flex-multisig/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub enum QueryMsg {
start_after: Option<HumanAddr>,
limit: Option<u32>,
},
/// Returns VoterResponse
/// Returns VoterInfo
Voter { address: HumanAddr },
/// Returns VoterListResponse
ListVoters {
Expand Down
3 changes: 2 additions & 1 deletion packages/cw3/examples/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cosmwasm_schema::{export_schema, export_schema_with_title, remove_schemas, s

use cw3::{
Cw3HandleMsg, Cw3QueryMsg, ProposalListResponse, ProposalResponse, ThresholdResponse,
VoteListResponse, VoteResponse, VoterListResponse, VoterResponse,
VoteListResponse, VoteResponse, VoterInfo, VoterListResponse, VoterResponse,
};

fn main() {
Expand All @@ -24,6 +24,7 @@ fn main() {
export_schema(&schema_for!(ProposalListResponse), &out_dir);
export_schema(&schema_for!(VoteResponse), &out_dir);
export_schema(&schema_for!(VoteListResponse), &out_dir);
export_schema(&schema_for!(VoterInfo), &out_dir);
export_schema(&schema_for!(VoterResponse), &out_dir);
export_schema(&schema_for!(VoterListResponse), &out_dir);
export_schema(&schema_for!(ThresholdResponse), &out_dir);
Expand Down
4 changes: 2 additions & 2 deletions packages/cw3/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
}
},
{
"description": "Voter extension: Returns VoterResponse",
"description": "Voter extension: Returns VoterInfo",
"type": "object",
"required": [
"voter"
Expand All @@ -183,7 +183,7 @@
}
},
{
"description": "Voter extension: Returns VoterListResponse",
"description": "ListVoters extension: Returns VoterListResponse",
"type": "object",
"required": [
"list_voters"
Expand Down
15 changes: 15 additions & 0 deletions packages/cw3/schema/voter_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "VoterInfo",
"type": "object",
"properties": {
"weight": {
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
}
}
}
8 changes: 3 additions & 5 deletions packages/cw3/schema/voter_list_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@
"VoterResponse": {
"type": "object",
"required": [
"addr"
"addr",
"weight"
],
"properties": {
"addr": {
"$ref": "#/definitions/HumanAddr"
},
"weight": {
"type": [
"integer",
"null"
],
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
Expand Down
8 changes: 3 additions & 5 deletions packages/cw3/schema/voter_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
"title": "VoterResponse",
"type": "object",
"required": [
"addr"
"addr",
"weight"
],
"properties": {
"addr": {
"$ref": "#/definitions/HumanAddr"
},
"weight": {
"type": [
"integer",
"null"
],
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cw3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use crate::helpers::{Cw3CanonicalContract, Cw3Contract};
pub use crate::msg::{Cw3HandleMsg, Vote};
pub use crate::query::{
Cw3QueryMsg, ProposalListResponse, ProposalResponse, Status, ThresholdResponse, VoteInfo,
VoteListResponse, VoteResponse, VoterListResponse, VoterResponse,
VoteListResponse, VoteResponse, VoterInfo, VoterListResponse, VoterResponse,
};

#[cfg(test)]
Expand Down
11 changes: 8 additions & 3 deletions packages/cw3/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ pub enum Cw3QueryMsg {
start_after: Option<HumanAddr>,
limit: Option<u32>,
},
/// Voter extension: Returns VoterResponse
/// Voter extension: Returns VoterInfo
Voter { address: HumanAddr },
/// Voter extension: Returns VoterListResponse
/// ListVoters extension: Returns VoterListResponse
ListVoters {
start_after: Option<HumanAddr>,
limit: Option<u32>,
Expand Down Expand Up @@ -131,10 +131,15 @@ pub struct VoteResponse {
pub vote: Option<Vote>,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct VoterInfo {
pub weight: Option<u64>,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct VoterResponse {
pub addr: HumanAddr,
pub weight: Option<u64>,
pub weight: u64,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
Expand Down

0 comments on commit f996203

Please sign in to comment.