Skip to content

Commit

Permalink
feat: save execution failure for proposal in timelock contract
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Aug 29, 2023
1 parent 6f6c914 commit 00c47df
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,30 @@
}
},
"additionalProperties": false
},
{
"description": "Returns an error of the failed proposal. Returns `Option<String>` // TODO: return custom type?",
"type": "object",
"required": [
"proposal_failed_execution_error"
],
"properties": {
"proposal_failed_execution_error": {
"type": "object",
"required": [
"proposal_id"
],
"properties": {
"proposal_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
]
},
Expand Down Expand Up @@ -5535,6 +5559,14 @@
]
}
}
},
"proposal_failed_execution_error": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Nullable_String",
"type": [
"string",
"null"
]
}
}
}
24 changes: 24 additions & 0 deletions contracts/subdaos/cwd-subdao-timelock-single/schema/raw/query.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@
}
},
"additionalProperties": false
},
{
"description": "Returns an error of the failed proposal. Returns `Option<String>` // TODO: return custom type?",
"type": "object",
"required": [
"proposal_failed_execution_error"
],
"properties": {
"proposal_failed_execution_error": {
"type": "object",
"required": [
"proposal_id"
],
"properties": {
"proposal_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Nullable_String",
"type": [
"string",
"null"
]
}
18 changes: 16 additions & 2 deletions contracts/subdaos/cwd-subdao-timelock-single/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use neutron_subdao_timelock_single::{
};

use crate::error::ContractError;
use crate::state::{CONFIG, DEFAULT_LIMIT, PROPOSALS};
use crate::state::{CONFIG, DEFAULT_LIMIT, PROPOSALS, PROPOSAL_FAILED_EXECUTION_ERRORS};

pub(crate) const CONTRACT_NAME: &str = "crates.io:cwd-subdao-timelock-single";
pub(crate) const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -248,6 +248,9 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::ListProposals { start_after, limit } => {
query_list_proposals(deps, start_after, limit)
}
QueryMsg::ProposalFailedExecutionError { proposal_id } => {
query_proposal_failed_execution_error(deps, proposal_id)
}
}
}

Expand All @@ -274,6 +277,11 @@ pub fn query_list_proposals(
to_binary(&ProposalListResponse { proposals: props })
}

fn query_proposal_failed_execution_error(deps: Deps, proposal_id: u64) -> StdResult<Binary> {
let proposal_error = PROPOSAL_FAILED_EXECUTION_ERRORS.may_load(deps.storage, proposal_id)?;
to_binary(&proposal_error)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
// Set contract to version to latest
Expand Down Expand Up @@ -315,12 +323,18 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractE
PROPOSALS.update(deps.storage, proposal_id, |prop| match prop {
Some(mut prop) => {
prop.status = ProposalStatus::ExecutionFailed;

Ok(prop)
}
None => Err(ContractError::NoSuchProposal { id: proposal_id }),
})?;

let err = msg
.result
.into_result()
.err()
.unwrap_or_else(|| "result is not error".to_string());
PROPOSAL_FAILED_EXECUTION_ERRORS.save(deps.storage, proposal_id, &err)?;

Ok(Response::new().add_attribute(
"timelocked_proposal_execution_failed",
proposal_id.to_string(),
Expand Down
1 change: 1 addition & 0 deletions contracts/subdaos/cwd-subdao-timelock-single/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pub const DEFAULT_LIMIT: u64 = 30;

pub const CONFIG: Item<Config> = Item::new("config");
pub const PROPOSALS: Map<u64, SingleChoiceProposal> = Map::new("proposals");
pub const PROPOSAL_FAILED_EXECUTION_ERRORS: Map<u64, String> = Map::new("failed_proposal_errors");
5 changes: 5 additions & 0 deletions packages/neutron-subdao-timelock-single/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ pub enum QueryMsg {
/// returned.
limit: Option<u64>,
},

/// Returns an error of the failed proposal.
/// Returns `Option<String>` // TODO: return custom type?
#[returns(Option<String>)]
ProposalFailedExecutionError { proposal_id: u64 },
}

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

0 comments on commit 00c47df

Please sign in to comment.