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

Weight 0 vs not member #159

Merged
merged 5 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
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
9 changes: 3 additions & 6 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 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
9 changes: 3 additions & 6 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 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
}
}
}
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
9 changes: 7 additions & 2 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,6 +131,11 @@ 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,
Expand Down