From 251e6e66a0cf315a6c97276cdd80ef417e91c256 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Mon, 7 Dec 2020 20:27:46 +0100 Subject: [PATCH 1/2] Change VoterResponse weight type to Option --- contracts/cw3-fixed-multisig/src/contract.rs | 6 ++---- contracts/cw3-flex-multisig/src/contract.rs | 9 +++------ packages/cw3/src/query.rs | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/contracts/cw3-fixed-multisig/src/contract.rs b/contracts/cw3-fixed-multisig/src/contract.rs index 8a6443db5..3263ee7a6 100644 --- a/contracts/cw3-fixed-multisig/src/contract.rs +++ b/contracts/cw3-fixed-multisig/src/contract.rs @@ -402,9 +402,7 @@ fn list_votes( fn query_voter(deps: Deps, voter: HumanAddr) -> StdResult { 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, @@ -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(); diff --git a/contracts/cw3-flex-multisig/src/contract.rs b/contracts/cw3-flex-multisig/src/contract.rs index 9e870b527..87f79fafa 100644 --- a/contracts/cw3-flex-multisig/src/contract.rs +++ b/contracts/cw3-flex-multisig/src/contract.rs @@ -407,10 +407,7 @@ fn list_votes( fn query_voter(deps: Deps, voter: HumanAddr) -> StdResult { 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, @@ -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 }) @@ -613,7 +610,7 @@ mod tests { voters.voters, vec![VoterResponse { addr: OWNER.into(), - weight: 1 + weight: Some(1) }] ); } diff --git a/packages/cw3/src/query.rs b/packages/cw3/src/query.rs index d6170ca21..e8277d16c 100644 --- a/packages/cw3/src/query.rs +++ b/packages/cw3/src/query.rs @@ -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, } #[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] From be20bebac0e27d566fcb11d572954ca28dc6471a Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Mon, 7 Dec 2020 20:45:08 +0100 Subject: [PATCH 2/2] Update schema --- packages/cw3/schema/voter_list_response.json | 8 +++++--- packages/cw3/schema/voter_response.json | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/cw3/schema/voter_list_response.json b/packages/cw3/schema/voter_list_response.json index 24497ce31..d3a25a1a7 100644 --- a/packages/cw3/schema/voter_list_response.json +++ b/packages/cw3/schema/voter_list_response.json @@ -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 } diff --git a/packages/cw3/schema/voter_response.json b/packages/cw3/schema/voter_response.json index 60af46c63..eeb4524ad 100644 --- a/packages/cw3/schema/voter_response.json +++ b/packages/cw3/schema/voter_response.json @@ -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 }