Skip to content

Commit

Permalink
set creator, name, and symbol for sg-ics721
Browse files Browse the repository at this point in the history
  • Loading branch information
taitruong committed Nov 11, 2023
1 parent 6f86af1 commit 7e1912e
Show file tree
Hide file tree
Showing 4 changed files with 502 additions and 365 deletions.
63 changes: 36 additions & 27 deletions contracts/sg-ics721/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,45 +36,54 @@ impl Ics721Execute for SgIcs721Contract {
}

fn init_msg(&self, deps: Deps, env: &Env, class: &Class) -> StdResult<Binary> {
let creator = match class.data.clone() {
None => {
// in case no class data is provided (e.g. due to nft-transfer module), ics721 creator is used.
let contract_info = deps
.querier
.query_wasm_contract_info(env.contract.address.to_string())?;
contract_info.creator
}
Some(data) => {
// class data may be any custom type. Check whether it is `ics721::state::CollectionData` or not.
let class_data_result: StdResult<CollectionData> = from_json(data);
if class_data_result.is_err() {
// this happens only for unknown class data, like source chain uses nft-transfer module
env.contract.address.to_string()
} else {
let class_data = class_data_result?;

match class_data.owner {
Some(owner) => convert_owner_chain_address(env, owner.as_str())?,
None => env.contract.address.to_string(),
}
}
}
};
to_json_binary(&sg721::InstantiateMsg {
// ics721 creator is used, in case no source owner in class data is provided (e.g. due to nft-transfer module).
let ics721_contract_info = deps
.querier
.query_wasm_contract_info(env.contract.address.to_string())?;
let mut instantiate_msg = sg721::InstantiateMsg {
// Name of the collection MUST be class_id as this is how
// we create a map entry on reply.
name: class.id.clone().into(),
symbol: class.id.clone().into(),
minter: env.contract.address.to_string(),
collection_info: sg721::CollectionInfo {
creator,
creator: ics721_contract_info.creator,
description: "".to_string(),
image: "https://arkprotocol.io".to_string(),
external_link: None,
explicit_content: None,
start_trading_time: None,
royalty_info: None,
},
})
};

// unwrapped to collection data and in case of success, set creator, name and symbol
if let Some(binary) = class.data.clone() {
let class_data_result: StdResult<CollectionData> = from_json(binary);
if class_data_result.is_ok() {
let class_data = class_data_result?;
match class_data.owner {
Some(owner) =>
// owner from source chain is used
{
instantiate_msg.collection_info.creator =
convert_owner_chain_address(env, owner.as_str())?
}
None =>
// ics721 creator is used, in case of none
{
let ics721_contract_info = deps
.querier
.query_wasm_contract_info(env.contract.address.to_string())?;
instantiate_msg.collection_info.creator = ics721_contract_info.creator;
}
}
// set name and symbol
instantiate_msg.symbol = class_data.symbol;
instantiate_msg.name = class_data.name;
}
}

to_json_binary(&instantiate_msg)
}
}
Loading

0 comments on commit 7e1912e

Please sign in to comment.