Skip to content

Commit

Permalink
Merge pull request #105 from public-awesome/release/v0.1.13
Browse files Browse the repository at this point in the history
new UniversalNftExtension
  • Loading branch information
jhernandezb authored Sep 28, 2024
2 parents eb47798 + e943d01 commit 5793545
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 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
7 changes: 2 additions & 5 deletions packages/ics721/src/ibc_packet_receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ pub(crate) fn receive_ibc_packet(
load_nft_contract_for_class_id(deps.storage, local_class_id.to_string())
.map_err(|_| ContractError::NoNftContractForClassId(local_class_id.to_string()))
} else {
let nft_contract =
match query_nft_contract_for_class_id(deps.storage, local_class_id.clone()) {
Ok(nft_contract) => nft_contract,
Err(_) => None, // not found, occurs on initial transfer when we don't have the contract address
};
let nft_contract = query_nft_contract_for_class_id(deps.storage, local_class_id.clone())
.unwrap_or_default();
match nft_contract {
Some(nft_contract) => Ok(nft_contract),
None => {
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 5793545

Please sign in to comment.