From 21874f2f2ece662b6f1344a79f5bfb32d6c5ef9e Mon Sep 17 00:00:00 2001 From: Noah Saso Date: Tue, 14 Nov 2023 11:06:26 -0800 Subject: [PATCH] Made map name more descriptive and return option instead of error on missing ID. --- .../pre-propose/dao-pre-propose-approver/src/contract.rs | 8 ++++---- contracts/pre-propose/dao-pre-propose-approver/src/msg.rs | 2 +- .../pre-propose/dao-pre-propose-approver/src/state.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contracts/pre-propose/dao-pre-propose-approver/src/contract.rs b/contracts/pre-propose/dao-pre-propose-approver/src/contract.rs index 58133965b..764978f26 100644 --- a/contracts/pre-propose/dao-pre-propose-approver/src/contract.rs +++ b/contracts/pre-propose/dao-pre-propose-approver/src/contract.rs @@ -16,7 +16,7 @@ use dao_voting::status::Status; use crate::msg::{ BaseInstantiateMsg, ExecuteMsg, InstantiateMsg, ProposeMessageInternal, QueryExt, QueryMsg, }; -use crate::state::{PRE_PROPOSE_APPROVAL_CONTRACT, PROPOSAL_IDS}; +use crate::state::{PRE_PROPOSE_APPROVAL_CONTRACT, PROPOSAL_ID_TO_PRE_PROPOSE_ID}; pub(crate) const CONTRACT_NAME: &str = "crates.io:dao-pre-propose-approver"; pub(crate) const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -124,7 +124,7 @@ pub fn execute_propose( &proposal_module, &dao_interface::proposal::Query::NextProposalId {}, )?; - PROPOSAL_IDS.save(deps.storage, proposal_id, &pre_propose_id)?; + PROPOSAL_ID_TO_PRE_PROPOSE_ID.save(deps.storage, proposal_id, &pre_propose_id)?; let propose_messsage = WasmMsg::Execute { contract_addr: proposal_module.into_string(), @@ -147,7 +147,7 @@ pub fn execute_proposal_completed( } // Get approval pre-propose id - let pre_propose_id = PROPOSAL_IDS.load(deps.storage, proposal_id)?; + let pre_propose_id = PROPOSAL_ID_TO_PRE_PROPOSE_ID.load(deps.storage, proposal_id)?; // Get approval contract address let approval_contract = PRE_PROPOSE_APPROVAL_CONTRACT.load(deps.storage)?; @@ -189,7 +189,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { to_binary(&PRE_PROPOSE_APPROVAL_CONTRACT.load(deps.storage)?) } QueryExt::PendingProposalIdForApprovalProposalId { id } => { - to_binary(&PROPOSAL_IDS.load(deps.storage, id)?) + to_binary(&PROPOSAL_ID_TO_PRE_PROPOSE_ID.may_load(deps.storage, id)?) } }, _ => PrePropose::default().query(deps, env, msg), diff --git a/contracts/pre-propose/dao-pre-propose-approver/src/msg.rs b/contracts/pre-propose/dao-pre-propose-approver/src/msg.rs index 7b66a1d46..e535dc9f2 100644 --- a/contracts/pre-propose/dao-pre-propose-approver/src/msg.rs +++ b/contracts/pre-propose/dao-pre-propose-approver/src/msg.rs @@ -15,7 +15,7 @@ pub struct InstantiateMsg { pub enum QueryExt { #[returns(cosmwasm_std::Addr)] PreProposeApprovalContract {}, - #[returns(u64)] + #[returns(Option)] PendingProposalIdForApprovalProposalId { id: u64 }, } diff --git a/contracts/pre-propose/dao-pre-propose-approver/src/state.rs b/contracts/pre-propose/dao-pre-propose-approver/src/state.rs index b39187bf6..9bc724c9c 100644 --- a/contracts/pre-propose/dao-pre-propose-approver/src/state.rs +++ b/contracts/pre-propose/dao-pre-propose-approver/src/state.rs @@ -4,4 +4,4 @@ use cw_storage_plus::{Item, Map}; // Stores the address of the pre-propose approval contract pub const PRE_PROPOSE_APPROVAL_CONTRACT: Item = Item::new("pre_propose_approval_contract"); // Maps proposal ids to pre-propose ids -pub const PROPOSAL_IDS: Map = Map::new("proposal_ids"); +pub const PROPOSAL_ID_TO_PRE_PROPOSE_ID: Map = Map::new("proposal_ids");