Skip to content

Commit

Permalink
new UniversalNftExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
taitruong committed Sep 27, 2024
1 parent eb47798 commit c769c0a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
7 changes: 4 additions & 3 deletions contracts/ics721-base-tester/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ pub fn execute(

mod receive_callbacks {
use cosmwasm_std::{ensure_eq, from_json, DepsMut, Empty, MessageInfo, Response};
use cw721::{DefaultOptionalCollectionExtension, DefaultOptionalNftExtension};
use cw721::DefaultOptionalCollectionExtension;
use ics721::state::UniversalDefaultOptionalNftExtension;
use ics721_types::{
ibc_types::NonFungibleTokenPacketData,
types::{Ics721AckCallbackMsg, Ics721ReceiveCallbackMsg, Ics721Status},
Expand Down Expand Up @@ -135,7 +136,7 @@ mod receive_callbacks {
.query_wasm_smart::<cw721::msg::OwnerOfResponse>(
nft_contract,
&cw721::msg::Cw721QueryMsg::<
DefaultOptionalNftExtension,
UniversalDefaultOptionalNftExtension,
DefaultOptionalCollectionExtension,
Empty,
>::OwnerOf {
Expand Down Expand Up @@ -182,7 +183,7 @@ mod receive_callbacks {
.query_wasm_smart::<cw721::msg::OwnerOfResponse>(
nft_contract,
&cw721::msg::Cw721QueryMsg::<
DefaultOptionalNftExtension,
UniversalDefaultOptionalNftExtension,
DefaultOptionalCollectionExtension,
Empty,
>::OwnerOf {
Expand Down
28 changes: 22 additions & 6 deletions packages/ics721/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_schema::{cw_serde, schemars::JsonSchema};
use cosmwasm_std::{Addr, Binary, ContractInfoResponse, Empty, Timestamp};
use cw721::{DefaultOptionalCollectionExtension, DefaultOptionalNftExtension};
use cw721::{state::Trait, DefaultOptionalCollectionExtension};
use cw_pause_once::PauseOrchestrator;
use cw_storage_plus::{Index, IndexList, IndexedMap, Item, Map, UniqueIndex};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -79,7 +79,22 @@ pub struct UniversalCollectionInfoResponse {
pub struct UniversalNftInfoResponse {
pub token_uri: Option<String>,

pub extension: DefaultOptionalNftExtension,
pub extension: UniversalDefaultOptionalNftExtension,
}

pub type UniversalDefaultOptionalNftExtension = Option<UniversalNftExtension>;

#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
pub struct UniversalNftExtension {
pub image: Option<String>,
pub image_data: Option<String>,
pub external_url: Option<String>,
pub description: Option<String>,
pub name: Option<String>,
pub attributes: Option<Vec<Trait>>,
pub background_color: Option<String>,
pub animation_url: Option<String>,
pub youtube_url: Option<String>,
}

/// Collection data send by ICS721 on source chain. It is an optional class data for interchain transfer to target chain.
Expand Down Expand Up @@ -133,20 +148,21 @@ impl<'a> IndexList<ClassIdInfo> for ClassIdInfoIndexes<'a> {
#[cfg(test)]
mod tests {
use cosmwasm_std::{from_json, to_json_binary};
use cw721::{DefaultOptionalNftExtension, NftExtension};

use crate::state::{UniversalDefaultOptionalNftExtension, UniversalNftExtension};

use super::UniversalAllNftInfoResponse;

#[test]
fn test_universal_deserialize() {
let start = cw721::msg::AllNftInfoResponse::<DefaultOptionalNftExtension> {
let start = cw721::msg::AllNftInfoResponse::<UniversalDefaultOptionalNftExtension> {
access: cw721::msg::OwnerOfResponse {
owner: "foo".to_string(),
approvals: vec![],
},
info: cw721::msg::NftInfoResponse {
token_uri: None,
extension: Some(NftExtension {
extension: Some(UniversalNftExtension {
..Default::default()
}),
},
Expand All @@ -158,7 +174,7 @@ mod tests {
assert_eq!(end.info.token_uri, None);
assert_eq!(
end.info.extension,
Some(NftExtension {
Some(UniversalNftExtension {
..Default::default()
})
)
Expand Down

0 comments on commit c769c0a

Please sign in to comment.