Skip to content

Commit

Permalink
Merge pull request #158 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 ae587a1 + be20beb commit 5c6a76c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
6 changes: 2 additions & 4 deletions contracts/cw3-fixed-multisig/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,7 @@ fn list_votes(

fn query_voter(deps: Deps, voter: HumanAddr) -> StdResult<VoterResponse> {
let voter_raw = deps.api.canonical_address(&voter)?;
let weight = VOTERS
.may_load(deps.storage, &voter_raw)?
.unwrap_or_default();
let weight = VOTERS.may_load(deps.storage, &voter_raw)?;
Ok(VoterResponse {
addr: voter,
weight,
Expand All @@ -428,7 +426,7 @@ fn list_voters(
let (key, weight) = item?;
Ok(VoterResponse {
addr: api.human_address(&CanonicalAddr::from(key))?,
weight,
weight: Some(weight),
})
})
.collect();
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 @@ -407,10 +407,7 @@ fn list_votes(
fn query_voter(deps: Deps, voter: HumanAddr) -> StdResult<VoterResponse> {
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)?
.unwrap_or_default();
let weight = cfg.group_addr.is_member(&deps.querier, &voter_raw)?;

Ok(VoterResponse {
addr: voter,
Expand All @@ -430,7 +427,7 @@ fn list_voters(
.into_iter()
.map(|member| VoterResponse {
addr: member.addr,
weight: member.weight,
weight: Some(member.weight),
})
.collect();
Ok(VoterListResponse { voters })
Expand Down Expand Up @@ -613,7 +610,7 @@ mod tests {
voters.voters,
vec![VoterResponse {
addr: OWNER.into(),
weight: 1
weight: Some(1)
}]
);
}
Expand Down
8 changes: 5 additions & 3 deletions packages/cw3/schema/voter_list_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
"VoterResponse": {
"type": "object",
"required": [
"addr",
"weight"
"addr"
],
"properties": {
"addr": {
"$ref": "#/definitions/HumanAddr"
},
"weight": {
"type": "integer",
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
}
Expand Down
8 changes: 5 additions & 3 deletions packages/cw3/schema/voter_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
"title": "VoterResponse",
"type": "object",
"required": [
"addr",
"weight"
"addr"
],
"properties": {
"addr": {
"$ref": "#/definitions/HumanAddr"
},
"weight": {
"type": "integer",
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cw3/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub struct VoteResponse {
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct VoterResponse {
pub addr: HumanAddr,
pub weight: u64,
pub weight: Option<u64>,
}

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

0 comments on commit 5c6a76c

Please sign in to comment.