Skip to content

Commit

Permalink
NTRN-290 refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
quasisamurai committed Dec 6, 2022
1 parent 43224d3 commit 2abc781
Show file tree
Hide file tree
Showing 30 changed files with 1,141 additions and 1,469 deletions.
4 changes: 2 additions & 2 deletions contracts/cwd-core/.cargo/schema/instantiate_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"description",
"name",
"proposal_modules_instantiate_info",
"voting_module_instantiate_info"
"voting_registry_module_instantiate_info"
],
"properties": {
"admin": {
Expand Down Expand Up @@ -65,7 +65,7 @@
"$ref": "#/definitions/ModuleInstantiateInfo"
}
},
"voting_module_instantiate_info": {
"voting_registry_module_instantiate_info": {
"description": "Instantiate information for the core contract's voting power module.",
"allOf": [
{
Expand Down
4 changes: 2 additions & 2 deletions contracts/cwd-core/examples/schema/instantiate_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"description",
"name",
"proposal_modules_instantiate_info",
"voting_module_instantiate_info"
"voting_registry_module_instantiate_info"
],
"properties": {
"admin": {
Expand Down Expand Up @@ -65,7 +65,7 @@
"$ref": "#/definitions/ModuleInstantiateInfo"
}
},
"voting_module_instantiate_info": {
"voting_registry_module_instantiate_info": {
"description": "Instantiate information for the core contract's voting power module.",
"allOf": [
{
Expand Down
4 changes: 2 additions & 2 deletions contracts/cwd-core/schema/instantiate_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"description",
"name",
"proposal_modules_instantiate_info",
"voting_module_instantiate_info"
"voting_registry_module_instantiate_info"
],
"properties": {
"admin": {
Expand Down Expand Up @@ -65,7 +65,7 @@
"$ref": "#/definitions/ModuleInstantiateInfo"
}
},
"voting_module_instantiate_info": {
"voting_registry_module_instantiate_info": {
"description": "Instantiate information for the core contract's voting power module.",
"allOf": [
{
Expand Down
4 changes: 2 additions & 2 deletions contracts/cwd-core/schema/schema/instantiate_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"description",
"name",
"proposal_modules_instantiate_info",
"voting_module_instantiate_info"
"voting_registry_module_instantiate_info"
],
"properties": {
"admin": {
Expand Down Expand Up @@ -65,7 +65,7 @@
"$ref": "#/definitions/ModuleInstantiateInfo"
}
},
"voting_module_instantiate_info": {
"voting_registry_module_instantiate_info": {
"description": "Instantiate information for the core contract's voting power module.",
"allOf": [
{
Expand Down
37 changes: 19 additions & 18 deletions contracts/cwd-core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::query::{
use crate::state::{
Config, ProposalModule, ProposalModuleStatus, ACTIVE_PROPOSAL_MODULE_COUNT, ADMIN, CONFIG,
CW20_LIST, CW721_LIST, ITEMS, NOMINATED_ADMIN, PAUSED, PROPOSAL_MODULES, SUBDAO_LIST,
TOTAL_PROPOSAL_MODULE_COUNT, VOTING_MODULE,
TOTAL_PROPOSAL_MODULE_COUNT, VOTING_REGISTRY_MODULE,
};

pub(crate) const CONTRACT_NAME: &str = "crates.io:cwd-core";
Expand Down Expand Up @@ -59,7 +59,7 @@ pub fn instantiate(
ADMIN.save(deps.storage, &admin)?;

let vote_module_msg = msg
.voting_module_instantiate_info
.voting_registry_module_instantiate_info
.into_wasm_msg(env.contract.address.clone());
let vote_module_msg: SubMsg<Empty> =
SubMsg::reply_on_success(vote_module_msg, VOTE_MODULE_INSTANTIATE_REPLY_ID);
Expand Down Expand Up @@ -587,7 +587,7 @@ pub fn query_config(deps: Deps) -> StdResult<Binary> {
}

pub fn query_voting_module(deps: Deps) -> StdResult<Binary> {
let voting_module = VOTING_MODULE.load(deps.storage)?;
let voting_module = VOTING_REGISTRY_MODULE.load(deps.storage)?;
to_binary(&voting_module)
}

Expand Down Expand Up @@ -668,7 +668,7 @@ pub fn query_paused(deps: Deps, env: Env) -> StdResult<Binary> {
pub fn query_dump_state(deps: Deps, env: Env) -> StdResult<Binary> {
let admin = ADMIN.load(deps.storage)?;
let config = CONFIG.load(deps.storage)?;
let voting_module = VOTING_MODULE.load(deps.storage)?;
let voting_registry_module = VOTING_REGISTRY_MODULE.load(deps.storage)?;
let proposal_modules = PROPOSAL_MODULES
.range(deps.storage, None, None, cosmwasm_std::Order::Ascending)
.map(|kv| Ok(kv?.1))
Expand All @@ -683,7 +683,7 @@ pub fn query_dump_state(deps: Deps, env: Env) -> StdResult<Binary> {
version,
pause_info,
proposal_modules,
voting_module,
voting_module: voting_registry_module,
active_proposal_module_count,
total_proposal_module_count,
})
Expand All @@ -694,19 +694,20 @@ pub fn query_voting_power_at_height(
address: String,
height: Option<u64>,
) -> StdResult<Binary> {
let voting_module = VOTING_MODULE.load(deps.storage)?;
let voting_registry_module = VOTING_REGISTRY_MODULE.load(deps.storage)?;
let voting_power: voting::VotingPowerAtHeightResponse = deps.querier.query_wasm_smart(
voting_module,
voting_registry_module,
&voting::Query::VotingPowerAtHeight { height, address },
)?;
to_binary(&voting_power)
}

pub fn query_total_power_at_height(deps: Deps, height: Option<u64>) -> StdResult<Binary> {
let voting_module = VOTING_MODULE.load(deps.storage)?;
let total_power: voting::TotalPowerAtHeightResponse = deps
.querier
.query_wasm_smart(voting_module, &voting::Query::TotalPowerAtHeight { height })?;
let voting_registry_module = VOTING_REGISTRY_MODULE.load(deps.storage)?;
let total_power: voting::TotalPowerAtHeightResponse = deps.querier.query_wasm_smart(
voting_registry_module,
&voting::Query::TotalPowerAtHeight { height },
)?;
to_binary(&total_power)
}

Expand Down Expand Up @@ -910,26 +911,26 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractE

VOTE_MODULE_INSTANTIATE_REPLY_ID => {
let res = parse_reply_instantiate_data(msg)?;
let vote_module_addr = deps.api.addr_validate(&res.contract_address)?;
let current = VOTING_MODULE.may_load(deps.storage)?;
let voting_registry_addr = deps.api.addr_validate(&res.contract_address)?;
let current = VOTING_REGISTRY_MODULE.may_load(deps.storage)?;

// Make sure a bug in instantiation isn't causing us to
// make more than one voting module.
if current.is_some() {
return Err(ContractError::MultipleVotingModules {});
}

VOTING_MODULE.save(deps.storage, &vote_module_addr)?;
VOTING_REGISTRY_MODULE.save(deps.storage, &voting_registry_addr)?;

Ok(Response::default().add_attribute("voting_module", vote_module_addr))
Ok(Response::default().add_attribute("voting_regsitry_module", voting_registry_addr))
}
VOTE_MODULE_UPDATE_REPLY_ID => {
let res = parse_reply_instantiate_data(msg)?;
let vote_module_addr = deps.api.addr_validate(&res.contract_address)?;
let voting_registry_addr = deps.api.addr_validate(&res.contract_address)?;

VOTING_MODULE.save(deps.storage, &vote_module_addr)?;
VOTING_REGISTRY_MODULE.save(deps.storage, &voting_registry_addr)?;

Ok(Response::default().add_attribute("voting_module", vote_module_addr))
Ok(Response::default().add_attribute("voting_registry_module", voting_registry_addr))
}
_ => Err(ContractError::UnknownReplyID {}),
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/cwd-core/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct InstantiateMsg {

/// Instantiate information for the core contract's voting
/// power module.
pub voting_module_instantiate_info: ModuleInstantiateInfo,
pub voting_registry_module_instantiate_info: ModuleInstantiateInfo,
/// Instantiate information for the core contract's
/// proposal modules.
// NOTE: the pre-propose-base package depends on it being the case
Expand Down
4 changes: 2 additions & 2 deletions contracts/cwd-core/src/schema/instantiate_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"description",
"name",
"proposal_modules_instantiate_info",
"voting_module_instantiate_info"
"voting_registry_module_instantiate_info"
],
"properties": {
"admin": {
Expand Down Expand Up @@ -65,7 +65,7 @@
"$ref": "#/definitions/ModuleInstantiateInfo"
}
},
"voting_module_instantiate_info": {
"voting_registry_module_instantiate_info": {
"description": "Instantiate information for the core contract's voting power module.",
"allOf": [
{
Expand Down
2 changes: 1 addition & 1 deletion contracts/cwd-core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub const CONFIG: Item<Config> = Item::new("config_v2");
pub const PAUSED: Item<Expiration> = Item::new("paused");

/// The voting module associated with this contract.
pub const VOTING_MODULE: Item<Addr> = Item::new("voting_module");
pub const VOTING_REGISTRY_MODULE: Item<Addr> = Item::new("voting_module");

/// The proposal modules associated with this contract.
/// When we change the data format of this map, we update the key (previously "proposal_modules")
Expand Down
48 changes: 1 addition & 47 deletions contracts/proposal/cwd-proposal-single/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -841,27 +841,7 @@
"description": "A number of Custom messages that can call into the Neutron bindings",
"oneOf": [
{
"description": "AddAdmin registers an interchain account on remote chain",
"type": "object",
"required": [
"add_admin"
],
"properties": {
"add_admin": {
"type": "object",
"required": [
"admin"
],
"properties": {
"admin": {
"type": "string"
}
}
}
},
"additionalProperties": false
},
{
"description": "TODO: add anotation TODO: move this to neutron sdk; bring neutron-sdk instead to this project This message can be sent only by neutron dao (cuz only neutron dao has admin rights)",
"type": "object",
"required": [
"submit_proposal"
Expand Down Expand Up @@ -1005,16 +985,6 @@
"type": "null"
}
]
},
"text_proposal": {
"anyOf": [
{
"$ref": "#/definitions/TextProposal"
},
{
"type": "null"
}
]
}
}
},
Expand Down Expand Up @@ -1102,22 +1072,6 @@
}
]
},
"TextProposal": {
"description": "MsgTextPoposal defines a SDK message for submission of text proposal",
"type": "object",
"required": [
"description",
"title"
],
"properties": {
"description": {
"type": "string"
},
"title": {
"type": "string"
}
}
},
"Threshold": {
"description": "The ways a proposal may reach its passing / failing threshold.",
"oneOf": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,27 +495,7 @@
"description": "A number of Custom messages that can call into the Neutron bindings",
"oneOf": [
{
"description": "AddAdmin registers an interchain account on remote chain",
"type": "object",
"required": [
"add_admin"
],
"properties": {
"add_admin": {
"type": "object",
"required": [
"admin"
],
"properties": {
"admin": {
"type": "string"
}
}
}
},
"additionalProperties": false
},
{
"description": "TODO: add anotation TODO: move this to neutron sdk; bring neutron-sdk instead to this project This message can be sent only by neutron dao (cuz only neutron dao has admin rights)",
"type": "object",
"required": [
"submit_proposal"
Expand Down Expand Up @@ -640,16 +620,6 @@
"type": "null"
}
]
},
"text_proposal": {
"anyOf": [
{
"$ref": "#/definitions/TextProposal"
},
{
"type": "null"
}
]
}
}
},
Expand Down Expand Up @@ -872,22 +842,6 @@
}
]
},
"TextProposal": {
"description": "MsgTextPoposal defines a SDK message for submission of text proposal",
"type": "object",
"required": [
"description",
"title"
],
"properties": {
"description": {
"type": "string"
},
"title": {
"type": "string"
}
}
},
"Threshold": {
"description": "The ways a proposal may reach its passing / failing threshold.",
"oneOf": [
Expand Down
Loading

0 comments on commit 2abc781

Please sign in to comment.