From 9da759f70f2ef196ef8ab8279b6531c5f5cf00dd Mon Sep 17 00:00:00 2001 From: Jake Hartnell Date: Tue, 12 Sep 2023 21:40:38 -0700 Subject: [PATCH] Factory callback for NFT contracts --- .../dao-voting-cw721-staked/src/contract.rs | 23 ++++++++++++++----- .../voting/dao-voting-cw721-staked/src/msg.rs | 5 ++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/contracts/voting/dao-voting-cw721-staked/src/contract.rs b/contracts/voting/dao-voting-cw721-staked/src/contract.rs index e8f97ab76..4cfd0d850 100644 --- a/contracts/voting/dao-voting-cw721-staked/src/contract.rs +++ b/contracts/voting/dao-voting-cw721-staked/src/contract.rs @@ -13,7 +13,7 @@ use dao_hooks::nft_stake::{stake_nft_hook_msgs, unstake_nft_hook_msgs}; use dao_interface::voting::IsActiveResponse; use dao_voting::threshold::{ActiveThreshold, ActiveThresholdResponse}; -use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, NftContract, QueryMsg}; +use crate::msg::{ExecuteMsg, FactoryCallback, InstantiateMsg, MigrateMsg, NftContract, QueryMsg}; use crate::state::{ register_staked_nft, register_unstaked_nfts, Config, ACTIVE_THRESHOLD, CONFIG, DAO, HOOKS, INITIAL_NFTS, MAX_CLAIMS, NFT_BALANCES, NFT_CLAIMS, STAKED_NFTS_PER_OWNER, TOTAL_STAKED_NFTS, @@ -736,13 +736,24 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result { let res = parse_reply_execute_data(msg)?; - // TODO validate active threshold is set. Some contracts such as a minter, - // contract may not have any supply until tokens are minted. - match res.data { Some(data) => { - // TODO parse data and save token contract address / denom - unimplemented!() + // TODO validate active threshold is set? Some contracts such as a minter, + // contract may not have any supply until tokens are minted. + + let mut config = CONFIG.load(deps.storage)?; + + // Parse info from the callback, this will fail + // if incorrectly formatted. + let info: FactoryCallback = from_binary(&data)?; + + // TODO validate that this is an NFT with a query + + // Update NFT contract + config.nft_address = deps.api.addr_validate(&info.nft_contract)?; + CONFIG.save(deps.storage, &config)?; + + Ok(Response::new().add_attribute("nft_contract", info.nft_contract)) } // TODO better error None => return Err(ContractError::Unauthorized {}), diff --git a/contracts/voting/dao-voting-cw721-staked/src/msg.rs b/contracts/voting/dao-voting-cw721-staked/src/msg.rs index 7fb38d79d..dc1eaa22b 100644 --- a/contracts/voting/dao-voting-cw721-staked/src/msg.rs +++ b/contracts/voting/dao-voting-cw721-staked/src/msg.rs @@ -94,3 +94,8 @@ pub enum QueryMsg { #[cw_serde] pub struct MigrateMsg {} + +#[cw_serde] +pub struct FactoryCallback { + pub nft_contract: String, +}