1#[cfg(not(feature = "library"))]
2use crate::error::ContractError;
3use crate::state::CONFIG;
4use cosmwasm_std::entry_point;
5use cosmwasm_std::{DepsMut, Env, Reply};
6use cw_utils::{parse_reply_instantiate_data, MsgInstantiateContractResponse, ParseReplyError};
7use sg_std::Response;
8
9const INIT_WHITELIST_REPLY_ID: u64 = 1;
10
11#[cfg_attr(not(feature = "library"), entry_point)]
12pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractError> {
13 if msg.id != INIT_WHITELIST_REPLY_ID {
14 return Err(ContractError::InvalidReplyID {});
15 }
16 let reply = parse_reply_instantiate_data(msg);
17 match_reply(deps, reply)
18}
19
20fn match_reply(
21 deps: DepsMut,
22 reply: Result<MsgInstantiateContractResponse, ParseReplyError>,
23) -> Result<Response, ContractError> {
24 match reply {
25 Ok(res) => {
26 let whitelist_address = &res.contract_address;
27 let mut config = CONFIG.load(deps.storage)?;
28 config.whitelist_address = Some(whitelist_address.to_string());
29 CONFIG.save(deps.storage, &config)?;
30
31 Ok(Response::default()
32 .add_attribute("action", "init_whitelist_reply")
33 .add_attribute("whitelist_address", whitelist_address))
34 }
35 Err(_) => Err(ContractError::ReplyOnSuccess {}),
36 }
37}