sg721_nt/
lib.rs

1#[cfg(not(feature = "library"))]
2use cosmwasm_std::entry_point;
3
4pub mod msg;
5use cw721_base::Extension;
6use sg721::InstantiateMsg;
7use sg721_base::Sg721Contract;
8pub type QueryMsg = sg721_base::msg::QueryMsg;
9pub type Sg721NonTransferableContract<'a> = Sg721Contract<'a, Extension>;
10use sg721_base::msg::NftParams;
11
12// version info for migration info
13// version info for migration info
14const CONTRACT_NAME: &str = "crates.io:sg721-nt";
15const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
16pub const EARLIEST_VERSION: &str = "0.16.0";
17pub const TO_VERSION: &str = "3.0.0";
18
19#[cfg(not(feature = "library"))]
20pub mod entry {
21    use super::*;
22
23    use crate::msg::ExecuteMsg;
24    use cosmwasm_std::{Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdError, StdResult};
25    use cw721::Cw721Execute;
26    use sg721_base::ContractError;
27    use sg_std::Response;
28
29    #[entry_point]
30    pub fn instantiate(
31        deps: DepsMut,
32        env: Env,
33        info: MessageInfo,
34        msg: InstantiateMsg,
35    ) -> Result<Response, ContractError> {
36        cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
37
38        let res = Sg721NonTransferableContract::default().instantiate(deps, env, info, msg)?;
39
40        Ok(res
41            .add_attribute("contract_name", CONTRACT_NAME)
42            .add_attribute("contract_version", CONTRACT_VERSION))
43    }
44
45    #[entry_point]
46    pub fn execute(
47        deps: DepsMut,
48        env: Env,
49        info: MessageInfo,
50        msg: ExecuteMsg<Extension>,
51    ) -> Result<Response, sg721_base::ContractError> {
52        match msg {
53            ExecuteMsg::Burn { token_id } => Sg721NonTransferableContract::default()
54                .parent
55                .burn(deps, env, info, token_id)
56                .map_err(|e| e.into()),
57            ExecuteMsg::Mint {
58                token_id,
59                token_uri,
60                owner,
61                extension,
62            } => Sg721NonTransferableContract::default().mint(
63                deps,
64                env,
65                info,
66                NftParams::NftData {
67                    token_id,
68                    owner,
69                    token_uri,
70                    extension,
71                },
72            ),
73            ExecuteMsg::UpdateCollectionInfo {
74                new_collection_info,
75            } => Sg721NonTransferableContract::default().update_collection_info(
76                deps,
77                env,
78                info,
79                new_collection_info,
80            ),
81            ExecuteMsg::FreezeCollectionInfo {} => {
82                Sg721NonTransferableContract::default().freeze_collection_info(deps, env, info)
83            }
84        }
85    }
86
87    #[entry_point]
88    pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
89        Sg721NonTransferableContract::default().query(deps, env, msg)
90    }
91
92    #[entry_point]
93    pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
94        // make sure the correct contract is being upgraded, and it's being
95        // upgraded from the correct version.
96        if CONTRACT_VERSION < EARLIEST_VERSION {
97            return Err(
98                StdError::generic_err("Cannot upgrade to a previous contract version").into(),
99            );
100        }
101        if CONTRACT_VERSION > TO_VERSION {
102            return Err(
103                StdError::generic_err("Cannot upgrade to a previous contract version").into(),
104            );
105        }
106        // if same version return
107        if CONTRACT_VERSION == TO_VERSION {
108            return Ok(Response::new());
109        }
110
111        // update contract version
112        cw2::set_contract_version(deps.storage, CONTRACT_NAME, TO_VERSION)?;
113
114        // perform the upgrade
115        let cw17_res = cw721_base::upgrades::v0_17::migrate::<Extension, Empty, Empty, Empty>(deps)
116            .map_err(|e| sg721_base::ContractError::MigrationError(e.to_string()))?;
117        let mut sgz_res = Response::new();
118        sgz_res.attributes = cw17_res.attributes;
119        Ok(sgz_res)
120    }
121}