Skip to content

Commit

Permalink
Merge pull request #102 from neutron-org/feat/add-mco-title
Browse files Browse the repository at this point in the history
feat: added title field #NTRN-174
  • Loading branch information
pr0n00gler authored Apr 12, 2024
2 parents 9852ebc + f8701d9 commit a141684
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 14 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,8 @@
"description": "Unchecked multiple choice option",
"type": "object",
"required": [
"description"
"description",
"title"
],
"properties": {
"description": {
Expand All @@ -1509,6 +1510,9 @@
"items": {
"$ref": "#/definitions/CosmosMsg_for_NeutronMsg"
}
},
"title": {
"type": "string"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,8 @@
"description": "Unchecked multiple choice option",
"type": "object",
"required": [
"description"
"description",
"title"
],
"properties": {
"description": {
Expand All @@ -1344,6 +1345,9 @@
"items": {
"$ref": "#/definitions/CosmosMsg_for_NeutronMsg"
}
},
"title": {
"type": "string"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,8 @@
"description": "Unchecked multiple choice option",
"type": "object",
"required": [
"description"
"description",
"title"
],
"properties": {
"description": {
Expand All @@ -1850,6 +1851,9 @@
"items": {
"$ref": "#/definitions/CosmosMsg_for_NeutronMsg"
}
},
"title": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -4197,6 +4201,7 @@
"description",
"index",
"option_type",
"title",
"vote_count"
],
"properties": {
Expand All @@ -4220,6 +4225,9 @@
"option_type": {
"$ref": "#/definitions/MultipleChoiceOptionType"
},
"title": {
"type": "string"
},
"vote_count": {
"$ref": "#/definitions/Uint128"
}
Expand Down Expand Up @@ -6987,6 +6995,7 @@
"description",
"index",
"option_type",
"title",
"vote_count"
],
"properties": {
Expand All @@ -7010,6 +7019,9 @@
"option_type": {
"$ref": "#/definitions/MultipleChoiceOptionType"
},
"title": {
"type": "string"
},
"vote_count": {
"$ref": "#/definitions/Uint128"
}
Expand Down Expand Up @@ -9754,6 +9766,7 @@
"description",
"index",
"option_type",
"title",
"vote_count"
],
"properties": {
Expand All @@ -9777,6 +9790,9 @@
"option_type": {
"$ref": "#/definitions/MultipleChoiceOptionType"
},
"title": {
"type": "string"
},
"vote_count": {
"$ref": "#/definitions/Uint128"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,8 @@
"description": "Unchecked multiple choice option",
"type": "object",
"required": [
"description"
"description",
"title"
],
"properties": {
"description": {
Expand All @@ -1566,6 +1567,9 @@
"items": {
"$ref": "#/definitions/CosmosMsg_for_NeutronMsg"
}
},
"title": {
"type": "string"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
"description",
"index",
"option_type",
"title",
"vote_count"
],
"properties": {
Expand All @@ -284,6 +285,9 @@
"option_type": {
"$ref": "#/definitions/MultipleChoiceOptionType"
},
"title": {
"type": "string"
},
"vote_count": {
"$ref": "#/definitions/Uint128"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
"description",
"index",
"option_type",
"title",
"vote_count"
],
"properties": {
Expand All @@ -288,6 +289,9 @@
"option_type": {
"$ref": "#/definitions/MultipleChoiceOptionType"
},
"title": {
"type": "string"
},
"vote_count": {
"$ref": "#/definitions/Uint128"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
"description",
"index",
"option_type",
"title",
"vote_count"
],
"properties": {
Expand All @@ -284,6 +285,9 @@
"option_type": {
"$ref": "#/definitions/MultipleChoiceOptionType"
},
"title": {
"type": "string"
},
"vote_count": {
"$ref": "#/definitions/Uint128"
}
Expand Down
54 changes: 50 additions & 4 deletions contracts/dao/proposal/cwd-proposal-multiple/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cosmwasm_std::{
};

use cw2::set_contract_version;
use cw_storage_plus::Bound;
use cw_storage_plus::{Bound, Map};
use cw_utils::{parse_reply_instantiate_data, Duration};
use cwd_hooks::Hooks;
use cwd_interface::voting::IsActiveResponse;
Expand All @@ -15,7 +15,8 @@ use cwd_proposal_hooks::{new_proposal_hooks, proposal_status_changed_hooks};
use cwd_vote_hooks::new_vote_hooks;
use cwd_voting::{
multiple_choice::{
MultipleChoiceOptions, MultipleChoiceVote, MultipleChoiceVotes, VotingStrategy,
CheckedMultipleChoiceOption, MultipleChoiceOptions, MultipleChoiceVote,
MultipleChoiceVotes, VotingStrategy,
},
pre_propose::{PreProposeInfo, ProposalCreationPolicy},
proposal::{DEFAULT_LIMIT, MAX_PROPOSAL_SIZE},
Expand All @@ -30,7 +31,7 @@ use crate::state::PROPOSAL_EXECUTION_ERRORS;
use crate::{msg::MigrateMsg, state::CREATION_POLICY};
use crate::{
msg::{ExecuteMsg, InstantiateMsg, QueryMsg},
proposal::{MultipleChoiceProposal, VoteResult},
proposal::{MultipleChoiceProposal, OldMultipleChoiceProposal, VoteResult},
query::{ProposalListResponse, ProposalResponse, VoteInfo, VoteListResponse, VoteResponse},
state::{
Ballot, Config, BALLOTS, CONFIG, PROPOSALS, PROPOSAL_COUNT, PROPOSAL_HOOKS, VOTE_HOOKS,
Expand Down Expand Up @@ -918,5 +919,50 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractE
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::default())

let mut migrated_proposal_ids: Vec<String> = vec![];

// This constant is needed to access the old proposals without "title" field inside "choices".
const OLD_PROPOSALS: Map<u64, OldMultipleChoiceProposal> = Map::new("proposals");
OLD_PROPOSALS
.range(deps.storage, None, None, cosmwasm_std::Order::Ascending)
.collect::<StdResult<Vec<(u64, OldMultipleChoiceProposal)>>>()?
.into_iter()
.try_for_each(|(id, prop)| {
migrated_proposal_ids.push(id.to_string());

PROPOSALS.save(
deps.storage,
id,
&MultipleChoiceProposal {
title: prop.title,
description: prop.description,
proposer: prop.proposer,
start_height: prop.start_height,
min_voting_period: prop.min_voting_period,
expiration: prop.expiration,
choices: prop
.choices
.into_iter()
.map(|choice| CheckedMultipleChoiceOption {
index: choice.index,
option_type: choice.option_type,
title: "".to_string(),
description: choice.description,
msgs: choice.msgs,
vote_count: choice.vote_count,
})
.collect(),
status: prop.status,
voting_strategy: prop.voting_strategy,
total_power: prop.total_power,
votes: prop.votes,
allow_revoting: prop.allow_revoting,
},
)
})?;

Ok(Response::default()
.add_attribute("action", "migrate")
.add_attribute("migrated_proposal_ids", migrated_proposal_ids.join(",")))
}
23 changes: 22 additions & 1 deletion contracts/dao/proposal/cwd-proposal-multiple/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use cosmwasm_std::{Addr, BlockInfo, StdError, StdResult, Uint128};
use cw_utils::Expiration;
use cwd_voting::{
multiple_choice::{
CheckedMultipleChoiceOption, MultipleChoiceOptionType, MultipleChoiceVotes, VotingStrategy,
CheckedMultipleChoiceOption, MultipleChoiceOptionType, MultipleChoiceVotes,
OldCheckedMultipleChoiceOption, VotingStrategy,
},
proposal::Proposal,
status::Status,
Expand Down Expand Up @@ -46,6 +47,24 @@ pub struct MultipleChoiceProposal {
pub allow_revoting: bool,
}

/// Deprecated.
/// This is the old proposal version without "title" field inside "choices".
#[cw_serde]
pub struct OldMultipleChoiceProposal {
pub title: String,
pub description: String,
pub proposer: Addr,
pub start_height: u64,
pub min_voting_period: Option<Expiration>,
pub expiration: Expiration,
pub choices: Vec<OldCheckedMultipleChoiceOption>,
pub status: Status,
pub voting_strategy: VotingStrategy,
pub total_power: Uint128,
pub votes: MultipleChoiceVotes,
pub allow_revoting: bool,
}

pub enum VoteResult {
SingleWinner(CheckedMultipleChoiceOption),
Tie,
Expand Down Expand Up @@ -284,10 +303,12 @@ mod tests {
// The last option that gets added in into_checked is always the none of the above option
let options = vec![
MultipleChoiceOption {
title: "title".to_string(),
description: "multiple choice option 1".to_string(),
msgs: None,
},
MultipleChoiceOption {
title: "title".to_string(),
description: "multiple choice option 2".to_string(),
msgs: None,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ where

let options = vec![
MultipleChoiceOption {
title: "title".to_string(),
description: "multiple choice option 1".to_string(),
msgs: None,
},
MultipleChoiceOption {
title: "title".to_string(),
description: "multiple choice option 2".to_string(),
msgs: None,
},
Expand Down
Loading

0 comments on commit a141684

Please sign in to comment.