Skip to content

Commit

Permalink
submsg reply error fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek-1857 committed Jul 11, 2024
1 parent 52cdbe6 commit 1cd2b4e
Show file tree
Hide file tree
Showing 20 changed files with 449 additions and 505 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ overflow-checks = true

[workspace.dependencies]
anyhow = { version = "1.0",default-features = false }
anybuf = "=0.5.0"
assert_matches = {version = "1.5",default-features = false}
cosm-orc = { version = "4.0",default-features = false }
cosm-tome = {version = "0.2",default-features = false}
Expand Down
40 changes: 16 additions & 24 deletions contracts/dao-dao-core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use dao_interface::{
},
voting,
};
use dao_utils::voting_cw4_init::GroupContract;
use dao_utils::voting_snip721_roles_init::NftContract;
use dao_utils::msg::GroupContract;
use dao_utils::msg::NftRolesContract;
use secret_cw2::{get_contract_version, set_contract_version, ContractVersion};
use secret_toolkit::utils::InitCallback;
use secret_toolkit::{serialization::Json, storage::Keymap, utils::HandleCallback};
Expand Down Expand Up @@ -69,7 +69,7 @@ pub fn instantiate(
let query_auth_msg = QueryAuthInstantiateMsg {
admin_auth: Contract {
address: env.contract.address.clone(),
code_hash: env.contract.code_hash,
code_hash: env.contract.code_hash.clone(),
},
prng_seed: to_binary(&"seed".to_string())?,
};
Expand All @@ -91,9 +91,6 @@ pub fn instantiate(
reply_id,
);

let _: dao_utils::voting_cw4_init::InstantiateMsg =
from_binary(&msg.voting_module_instantiate_info.msg)?;

if let Some(initial_items) = msg.initial_items {
// O(N*N) deduplication.
let mut seen = Vec::with_capacity(initial_items.len());
Expand All @@ -111,6 +108,10 @@ pub fn instantiate(

Ok(Response::new()
.add_attribute("action", "instantiate")
.set_data(to_binary(&AnyContractInfo{
addr: env.contract.address,
code_hash: env.contract.code_hash
})?)
.add_attribute("sender", info.sender)
.add_submessage(query_auth_submsg))
}
Expand Down Expand Up @@ -1156,7 +1157,7 @@ pub(crate) fn update_query_auth(
admin: String,
) -> StdResult<CosmosMsg> {
// Voting CW4
if let Ok(mut msg) = from_binary::<dao_utils::voting_cw4_init::InstantiateMsg>(&info.msg) {
if let Ok(mut msg) = from_binary::<dao_utils::msg::VotingCW4nstantiateMsg>(&info.msg) {
if let GroupContract::New {
ref mut query_auth, ..
} = msg.group_contract
Expand All @@ -1167,34 +1168,26 @@ pub(crate) fn update_query_auth(
}

// Voting Snip20 Staked
if let Ok(mut msg) =
from_binary::<dao_utils::voting_snip20_staked_init::InstantiateMsg>(&info.msg)
{
if let Ok(mut msg) = from_binary::<dao_utils::msg::Snip20StakedInstantiateMsg>(&info.msg) {
msg.query_auth = Some(new_query_auth);
return msg.to_cosmos_msg(Some(admin), info.label, info.code_id, info.code_hash, None);
}

// Voting Token Staked
if let Ok(mut msg) =
from_binary::<dao_utils::voting_token_staked_init::InstantiateMsg>(&info.msg)
{
if let Ok(mut msg) = from_binary::<dao_utils::msg::TokenStakedInstantiateMsg>(&info.msg) {
msg.query_auth = Some(new_query_auth);
return msg.to_cosmos_msg(Some(admin), info.label, info.code_id, info.code_hash, None);
}

// Voting Snip721 Staked
if let Ok(mut msg) =
from_binary::<dao_utils::voting_snip721_staked_init::InstantiateMsg>(&info.msg)
{
if let Ok(mut msg) = from_binary::<dao_utils::msg::Snip721StakedInstantiateMsg>(&info.msg) {
msg.query_auth = Some(new_query_auth);
return msg.to_cosmos_msg(Some(admin), info.label, info.code_id, info.code_hash, None);
}

// Voting Snip721 Roles
if let Ok(mut msg) =
from_binary::<dao_utils::voting_snip721_roles_init::InstantiateMsg>(&info.msg)
{
if let NftContract::New {
if let Ok(mut msg) = from_binary::<dao_utils::msg::Snip721RolesInstantiateMsg>(&info.msg) {
if let NftRolesContract::New {
ref mut query_auth, ..
} = msg.nft_contract
{
Expand All @@ -1204,20 +1197,19 @@ pub(crate) fn update_query_auth(
}

// Proposal Single
if let Ok(mut msg) = from_binary::<dao_utils::proposal_single_init::InstantiateMsg>(&info.msg) {
if let Ok(mut msg) = from_binary::<dao_utils::msg::ProposalSingleInstantiateMsg>(&info.msg) {
msg.query_auth = Some(new_query_auth);
return msg.to_cosmos_msg(Some(admin), info.label, info.code_id, info.code_hash, None);
}

// Proposal Multiple
if let Ok(mut msg) = from_binary::<dao_utils::proposal_multiple_init::InstantiateMsg>(&info.msg)
{
if let Ok(mut msg) = from_binary::<dao_utils::msg::ProposalMultipleInstantiateMsg>(&info.msg) {
msg.query_auth = Some(new_query_auth);
return msg.to_cosmos_msg(Some(admin), info.label, info.code_id, info.code_hash, None);
}

// Proposal Condorcet
if let Ok(msg) = from_binary::<dao_utils::proposal_condorcet_init::InstantiateMsg>(&info.msg) {
if let Ok(msg) = from_binary::<dao_utils::msg::ProposalCondorcetInstantiateMsg>(&info.msg) {
return msg.to_cosmos_msg(Some(admin), info.label, info.code_id, info.code_hash, None);
}

Expand Down
5 changes: 2 additions & 3 deletions contracts/external/cw4-group/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ pub fn instantiate(
)?;
create(deps, msg.admin, msg.members, env.block.height)?;
// if this contract is being deployed from voting module
if msg.voting_code_hash.is_some(){
if msg.voting_code_hash.is_some() {
let exec_msg = voting_cw4::VotingCW4ExecuteMsg::AddGroupContract {
addr: env.contract.address,
code_hash: env.contract.code_hash,
}
.to_cosmos_msg(msg.voting_code_hash.unwrap(), info.sender.to_string(), None)?;
return Ok(Response::default().add_message(exec_msg));
}
}
Ok(Response::default())

}

// create is the instantiation logic with set_contract_version removed so it can more
Expand Down
6 changes: 5 additions & 1 deletion contracts/proposal/dao-proposal-multiple/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub const PREFIX_REVOKED_PERMITS: &str = "revoked_permits";
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_env: Env,
env: Env,
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
Expand Down Expand Up @@ -103,6 +103,10 @@ pub fn instantiate(

Ok(Response::default()
.add_submessages(pre_propose_messages)
.set_data(to_binary(&AnyContractInfo {
addr: env.contract.address,
code_hash: env.contract.code_hash,
})?)
.add_attribute("action", "instantiate")
.add_attribute("dao", info.sender.to_string()))
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/voting/dao-voting-snip721-roles/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use dao_snip721_extensions::roles::{ExecuteExt, MetadataExt, QueryExt};
use secret_cw2::set_contract_version;
use shade_protocol::basic_staking::Auth;

use crate::msg::{ExecuteMsg, InstantiateMsg, NftContract, QueryMsg};
use crate::msg::{ExecuteMsg, InstantiateMsg, NftRolesContract, QueryMsg};
use crate::state::{Config, CONFIG, DAO, INITIAL_NFTS};
use crate::{error::ContractError, snip721roles};
use secret_toolkit::utils::InitCallback;
Expand Down Expand Up @@ -39,7 +39,7 @@ pub fn instantiate(
)?;

match msg.nft_contract {
NftContract::Existing { address, code_hash } => {
NftRolesContract::Existing { address, code_hash } => {
let config = Config {
nft_address: deps.api.addr_validate(&address)?,
nft_code_hash: code_hash.clone(),
Expand All @@ -54,7 +54,7 @@ pub fn instantiate(
})?)
.add_attribute("nft_contract", address))
}
NftContract::New {
NftRolesContract::New {
snip721_roles_code_id,
snip721_roles_code_hash,
name,
Expand Down
4 changes: 2 additions & 2 deletions contracts/voting/dao-voting-snip721-roles/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct NftMintMsg {

#[allow(clippy::large_enum_variant)]
#[cw_serde]
pub enum NftContract {
pub enum NftRolesContract {
Existing {
/// Address of an already instantiated snip721-weighted-roles token contract.
address: String,
Expand Down Expand Up @@ -63,7 +63,7 @@ pub enum NftContract {
#[cw_serde]
pub struct InstantiateMsg {
/// Info about the associated NFT contract
pub nft_contract: NftContract,
pub nft_contract: NftRolesContract,
pub dao_code_hash: String,
}

Expand Down
58 changes: 1 addition & 57 deletions contracts/voting/dao-voting-token-staked/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,63 +123,7 @@ pub fn instantiate(
addr: env.contract.address,
code_hash: env.contract.code_hash,
})?))
} // TokenInfo::New(ref token) => {
// let NewTokenInfo {
// subdenom,
// token_issuer_code_id,
// token_issuer_code_hash,
// ..
// } = token;

// // Save new token info for use in reply
// TOKEN_INSTANTIATION_INFO.save(deps.storage, &msg.token_info)?;

// // Instantiate cw-token-factory-issuer contract
// // DAO (sender) is set as contract admin
// let msg = IssuerInstantiateMsg::NewToken {
// subdenom: subdenom.to_string(),
// };
// let issuer_instantiate_msg = SubMsg::reply_on_success(
// msg.to_cosmos_msg(
// Some(info.sender.to_string()),
// env.contract.address.to_string(),
// token_issuer_code_id.clone(),
// token_issuer_code_hash.clone(),
// None,
// )?,
// INSTANTIATE_TOKEN_FACTORY_ISSUER_REPLY_ID,
// );

// Ok(Response::new()
// .add_attribute("action", "instantiate")
// .add_attribute("token", "new_token")
// .add_submessage(issuer_instantiate_msg))
// }
// TokenInfo::Factory(binary) => match from_binary(&binary)? {
// WasmMsg::Execute {
// msg,
// contract_addr,
// code_hash,
// funds,
// } => {
// // Call factory contract. Use only a trusted factory contract,
// // as this is a critical security component and valdiation of
// // setup will happen in the factory.
// Ok(Response::new()
// .add_attribute("action", "intantiate")
// .add_attribute("token", "custom_factory")
// .add_submessage(SubMsg::reply_on_success(
// WasmMsg::Execute {
// contract_addr,
// code_hash,
// msg,
// funds,
// },
// FACTORY_EXECUTE_REPLY_ID,
// )))
// }
// _ => Err(ContractError::UnsupportedFactoryMsg {}),
// },
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/dao-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dao-voting ={ workspace = true }
cw4 ={ workspace = true }
dao-snip721-extensions = { workspace = true }
snip721-roles-impl ={ workspace = true }

anybuf = { workspace = true }


[dev-dependencies]
Expand Down
10 changes: 2 additions & 8 deletions packages/dao-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
pub mod proposal_condorcet_init;
pub mod proposal_multiple_init;
pub mod proposal_single_init;
pub mod voting_cw4_init;
pub mod voting_snip20_staked_init;
pub mod voting_snip721_roles_init;
pub mod voting_snip721_staked_init;
pub mod voting_token_staked_init;
pub mod msg;
pub mod query;
Loading

0 comments on commit 1cd2b4e

Please sign in to comment.