Skip to content

Commit

Permalink
Factory callback for NFT contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Hartnell committed Sep 13, 2023
1 parent 32d86ee commit 9da759f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
23 changes: 17 additions & 6 deletions contracts/voting/dao-voting-cw721-staked/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -736,13 +736,24 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractE
FACTORY_EXECUTE_REPLY_ID => {
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 {}),

Check failure on line 759 in contracts/voting/dao-voting-cw721-staked/src/contract.rs

View workflow job for this annotation

GitHub Actions / Lints

unneeded `return` statement

Check failure on line 759 in contracts/voting/dao-voting-cw721-staked/src/contract.rs

View workflow job for this annotation

GitHub Actions / Lints

unneeded `return` statement
Expand Down
5 changes: 5 additions & 0 deletions contracts/voting/dao-voting-cw721-staked/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,8 @@ pub enum QueryMsg {

#[cw_serde]
pub struct MigrateMsg {}

#[cw_serde]
pub struct FactoryCallback {
pub nft_contract: String,
}

0 comments on commit 9da759f

Please sign in to comment.