Skip to content

Commit

Permalink
Made map name more descriptive and return option instead of error on …
Browse files Browse the repository at this point in the history
…missing ID.
  • Loading branch information
NoahSaso committed Nov 14, 2023
1 parent f1b93e7 commit 21874f2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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(),
Expand All @@ -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)?;
Expand Down Expand Up @@ -189,7 +189,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
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),
Expand Down
2 changes: 1 addition & 1 deletion contracts/pre-propose/dao-pre-propose-approver/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct InstantiateMsg {
pub enum QueryExt {
#[returns(cosmwasm_std::Addr)]
PreProposeApprovalContract {},
#[returns(u64)]
#[returns(Option<u64>)]
PendingProposalIdForApprovalProposalId { id: u64 },
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Addr> = Item::new("pre_propose_approval_contract");
// Maps proposal ids to pre-propose ids
pub const PROPOSAL_IDS: Map<u64, u64> = Map::new("proposal_ids");
pub const PROPOSAL_ID_TO_PRE_PROPOSE_ID: Map<u64, u64> = Map::new("proposal_ids");

0 comments on commit 21874f2

Please sign in to comment.