-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use sg721-metadata-onchain #104
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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}; | ||
|
||
|
@@ -113,4 +115,70 @@ 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: Metadata = match data { | ||
Some(data) => { | ||
match from_json::<NftExtension>(data).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, | ||
}) { | ||
Some(extension) => extension, | ||
None => Metadata { | ||
taitruong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
animation_url: None, | ||
attributes: None, | ||
background_color: None, | ||
description: None, | ||
external_url: None, | ||
image: None, | ||
image_data: None, | ||
youtube_url: None, | ||
name: None, | ||
}, | ||
} | ||
} | ||
None => Metadata { | ||
animation_url: None, | ||
attributes: None, | ||
background_color: None, | ||
description: None, | ||
external_url: None, | ||
image: None, | ||
image_data: None, | ||
youtube_url: None, | ||
name: None, | ||
}, | ||
}; | ||
|
||
let msg = sg721_metadata_onchain::ExecuteMsg::Mint { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so my question here is, does every meta data load resolve into a metadata_onchain type message? Wondering if there is a different struct for off-chain metadata? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case of offchain metadata:
So SG NFT mint is done by this: let msg = cw721_metadata_onchain::msg::ExecuteMsg::Mint {
token_id,
token_uri, // holds off-chain metadata
owner,
extension, // holds on-chain metadata
}; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering here, if off chain metadata is minted in this way, shouldn't we not use an execute message from cw721_onchain such as to not confuse the developer? I think the data is fine just coming from the cw721_metadata_onchain directory might be a bit misleading. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh my bad (wrong example given above). This is an sg-implementation, proper code is using this: 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) Please note that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved in discord, name is coming from external repo |
||
token_id, | ||
token_uri, | ||
owner, | ||
extension, | ||
}; | ||
to_json_binary(&msg) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sg-ics721 implementation with Metadata |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since everything here is being added from .ext I wonder if we could put this mapping into a helper function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we cant, sg-ics721 requires struct of type
Metadata
, whilst ics721 requiresNftExtensionMsg
. See comments below.