Skip to content

Commit

Permalink
Added message to reset approver back to DAO.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Nov 17, 2023
1 parent 1187dba commit 2a219e9
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
],
"properties": {
"msg": {
"$ref": "#/definitions/Empty"
"$ref": "#/definitions/ExecuteExt"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -298,9 +298,22 @@
}
]
},
"Empty": {
"description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)",
"type": "object"
"ExecuteExt": {
"oneOf": [
{
"type": "object",
"required": [
"reset_approver"
],
"properties": {
"reset_approver": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
}
]
},
"Status": {
"oneOf": [
Expand Down
45 changes: 43 additions & 2 deletions contracts/pre-propose/dao-pre-propose-approver/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ use dao_pre_propose_base::{error::PreProposeError, state::PreProposeContract};
use dao_voting::status::Status;

use crate::msg::{
BaseInstantiateMsg, ExecuteMsg, InstantiateMsg, ProposeMessageInternal, QueryExt, QueryMsg,
BaseInstantiateMsg, ExecuteExt, ExecuteMsg, InstantiateMsg, ProposeMessageInternal, QueryExt,
QueryMsg,
};
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");

type PrePropose = PreProposeContract<Empty, Empty, QueryExt, ApproverProposeMessage>;
type PrePropose = PreProposeContract<Empty, ExecuteExt, QueryExt, ApproverProposeMessage>;

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
Expand Down Expand Up @@ -86,6 +87,9 @@ pub fn execute(
proposal_id,
new_status,
} => execute_proposal_completed(deps, info, proposal_id, new_status),
ExecuteMsg::Extension { msg } => match msg {
ExecuteExt::ResetApprover {} => execute_reset_approver(deps, env, info),

Check warning on line 91 in contracts/pre-propose/dao-pre-propose-approver/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/pre-propose/dao-pre-propose-approver/src/contract.rs#L90-L91

Added lines #L90 - L91 were not covered by tests
},
_ => PrePropose::default().execute(deps, env, info, msg),
}
}
Expand Down Expand Up @@ -181,6 +185,43 @@ pub fn execute_proposal_completed(
}
}

pub fn execute_reset_approver(
deps: DepsMut,
env: Env,
info: MessageInfo,
) -> Result<Response, PreProposeError> {

Check warning on line 192 in contracts/pre-propose/dao-pre-propose-approver/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/pre-propose/dao-pre-propose-approver/src/contract.rs#L188-L192

Added lines #L188 - L192 were not covered by tests
// Check that this is coming from the DAO.
let dao = PrePropose::default().dao.load(deps.storage)?;
if info.sender != dao {
return Err(PreProposeError::Unauthorized {});
}

Check warning on line 197 in contracts/pre-propose/dao-pre-propose-approver/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/pre-propose/dao-pre-propose-approver/src/contract.rs#L194-L197

Added lines #L194 - L197 were not covered by tests

let pre_propose_approval_contract = PRE_PROPOSE_APPROVAL_CONTRACT.load(deps.storage)?;

Check warning on line 199 in contracts/pre-propose/dao-pre-propose-approver/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/pre-propose/dao-pre-propose-approver/src/contract.rs#L199

Added line #L199 was not covered by tests

let reset_messages = vec![
// Set pre-propose-approval approver to the DAO.
CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: pre_propose_approval_contract.to_string(),
msg: to_binary(&PreProposeApprovalExecuteMsg::Extension {
msg: ApprovalExt::UpdateApprover {
address: dao.to_string(),
},
})?,
funds: vec![],
}),
// Remove the proposal submitted hook.
CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: pre_propose_approval_contract.to_string(),
msg: to_binary(&PreProposeApprovalExecuteMsg::RemoveProposalSubmittedHook {
address: env.contract.address.to_string(),
})?,
funds: vec![],
}),
];

Ok(Response::default().add_messages(reset_messages))
}

Check warning on line 223 in contracts/pre-propose/dao-pre-propose-approver/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/pre-propose/dao-pre-propose-approver/src/contract.rs#L201-L223

Added lines #L201 - L223 were not covered by tests

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
Expand Down
9 changes: 8 additions & 1 deletion contracts/pre-propose/dao-pre-propose-approver/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ pub struct InstantiateMsg {
pub pre_propose_approval_contract: String,
}

#[cw_serde]

Check warning on line 13 in contracts/pre-propose/dao-pre-propose-approver/src/msg.rs

View check run for this annotation

Codecov / codecov/patch

contracts/pre-propose/dao-pre-propose-approver/src/msg.rs#L13

Added line #L13 was not covered by tests
pub enum ExecuteExt {
// Reset approver back to DAO that set up this approver contract. Only
// callable by the DAO.
ResetApprover {},
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryExt {
Expand All @@ -20,7 +27,7 @@ pub enum QueryExt {
}

pub type BaseInstantiateMsg = InstantiateBase<Empty>;
pub type ExecuteMsg = ExecuteBase<ApproverProposeMessage, Empty>;
pub type ExecuteMsg = ExecuteBase<ApproverProposeMessage, ExecuteExt>;
pub type QueryMsg = QueryBase<QueryExt>;

/// Internal version of the propose message that includes the
Expand Down

0 comments on commit 2a219e9

Please sign in to comment.