Skip to content

Commit

Permalink
Merge pull request #104 from public-awesome/sg_ics721_with_onchain_me…
Browse files Browse the repository at this point in the history
…tadata

use sg721-metadata-onchain
  • Loading branch information
taitruong authored Sep 4, 2024
2 parents d182e22 + 21888fc commit eb47798
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 65 deletions.
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ sha2 = "^0.10"
serde = "^1.0"
thiserror = "^1.0"
# Stargaze libs
sg-metadata = "^3.14"
sg-std = "^3.2"
sg-multi-test = "^3.1"
sg721 = "^3.3"
sg721-base = "^3.3"
sg721-base = "^3.14"
sg721-metadata-onchain = "^3.14"
# packages and contracts
cw-cii = { path = "./packages/cw-cii" }
cw-pause-once = { path = "./packages/cw-pause-once" }
Expand Down
2 changes: 2 additions & 0 deletions contracts/sg-ics721/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ cw2 = { workspace = true }
cw721 = { workspace = true }
ics721 = { workspace = true }
ics721-types = { workspace = true }
sg-metadata = { workspace = true}
sg-std = { workspace = true}
sg721 = { workspace = true }
sg721-base = { workspace = true, features = ["library"] }
sg721-metadata-onchain = { workspace = true, features = ["library"] }

[dev-dependencies]
anyhow = { workspace = true }
Expand Down
51 changes: 49 additions & 2 deletions contracts/sg-ics721/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use cosmwasm_std::{
from_json, to_json_binary, Addr, Binary, ContractInfoResponse, Deps, DepsMut, Env, StdResult,
};
use cw721::{CollectionExtension, RoyaltyInfo};
use cw721::{CollectionExtension, NftExtension, RoyaltyInfo};
use ics721::{execute::Ics721Execute, state::CollectionData, utils::get_collection_data};
use ics721_types::token_types::Class;

use sg721::RoyaltyInfoResponse;
use sg721_base::msg::{CollectionInfoResponse, QueryMsg};
use sg721_base::msg::CollectionInfoResponse;
use sg721_metadata_onchain::QueryMsg;
use sg_metadata::{Metadata, Trait};

use crate::state::{SgIcs721Contract, STARGAZE_ICON_PLACEHOLDER};

Expand Down Expand Up @@ -113,4 +115,49 @@ impl Ics721Execute for SgIcs721Contract {

to_json_binary(&instantiate_msg)
}

fn mint_msg(
&self,
token_id: String,
token_uri: Option<String>,
owner: String,
data: Option<Binary>,
) -> StdResult<Binary> {
// parse token data and check whether it is of type NftExtension
let extension = data
.and_then(|binary| {
from_json::<NftExtension>(binary).ok().map(|ext| Metadata {
animation_url: ext.animation_url,
attributes: ext.attributes.map(|traits| {
traits
.into_iter()
.map(|t| Trait {
trait_type: t.trait_type,
value: t.value,
display_type: t.display_type,
})
.collect()
}),
background_color: ext.background_color,
description: ext.description,
external_url: ext.external_url,
image: ext.image,
image_data: ext.image_data,
youtube_url: ext.youtube_url,
name: ext.name,
})
})
.unwrap_or(Metadata {
// no onchain metadata (only offchain), in this case empty metadata is created
..Default::default()
});

let msg = sg721_metadata_onchain::ExecuteMsg::Mint {
token_id,
token_uri, // holds off-chain metadata
owner,
extension, // holds on-chain metadata
};
to_json_binary(&msg)
}
}
Loading

0 comments on commit eb47798

Please sign in to comment.