Skip to content
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

Add optional catalog field to Asset #73

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#![feature(min_specialization)]
#![allow(clippy::inline_fn_without_body)]

pub mod counter;
pub mod errors;
pub mod roles;
pub mod types;
pub mod utils;
pub mod counter;
3 changes: 3 additions & 0 deletions crates/common/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub struct Asset {

/// list of parts for this asset
pub part_ids: Vec<PartId>,

/// The catalog to which the asset belongs to.
pub catalog: Option<AccountId>,
}

/// Part's details
Expand Down
7 changes: 1 addition & 6 deletions crates/equippable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,7 @@ where
)?;

// Check from base perspective. If catalog for this asset is None, then it is not equippable.
match self
.data::<MultiAssetData>()
.asset_catalog_address
.get(asset_id)
.ok_or(RmrkError::CatalogNotFoundForAsset)?
{
match self.get_asset_catalog_address(asset_id) {
Some(catalog_address) => {
CatalogRef::ensure_equippable(&catalog_address, slot_part_id, child_nft.0)?;
}
Expand Down
1 change: 1 addition & 0 deletions crates/equippable/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub trait Equippable {
/// # Returns:
/// * asset_id metadataURI,
/// * EquippableAsset
/// * catalog address
#[ink(message)]
fn get_asset_and_equippable_data(&self, token_id: Id, asset_id: AssetId) -> Result<Asset>;

Expand Down
5 changes: 1 addition & 4 deletions crates/minting/tests/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,7 @@ pub mod rmrk_contract_minting {
assert_eq!(2, ink::env::test::recorded_events().count());

// token_uri for rmrk mint works
assert_eq!(
rmrk.token_uri(2),
Ok(RMRK_METADATA.to_owned())
);
assert_eq!(rmrk.token_uri(2), Ok(RMRK_METADATA.to_owned()));
}

#[ink::test]
Expand Down
14 changes: 2 additions & 12 deletions crates/multiasset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub mod extensions {
pub mod autoindex;
}


use internal::Internal;

use rmrk_common::{
Expand Down Expand Up @@ -61,10 +60,6 @@ pub struct MultiAssetData {

/// Mapping of tokenId to an array of pending assets
pub pending_assets: Mapping<Id, Vec<AssetId>>,

/// Catalog assigned to assetId. Added with add_asset_entry
/// An asset can also have None as a catalog, hence the Option
pub asset_catalog_address: Mapping<AssetId, Option<AccountId>>,
}

impl<T> MultiAsset for T
Expand Down Expand Up @@ -93,14 +88,12 @@ where
equippable_group_id,
asset_uri,
part_ids: part_ids.clone(),
catalog: catalog_address.clone(),
},
);
self.data::<MultiAssetData>()
.collection_asset_ids
.push(asset_id);
self.data::<MultiAssetData>()
.asset_catalog_address
.insert(asset_id, &catalog_address);
self._emit_asset_set_event(&asset_id);

Ok(())
Expand Down Expand Up @@ -278,10 +271,7 @@ where

/// Fetch asset's catalog
fn get_asset_catalog_address(&self, asset_id: AssetId) -> Option<AccountId> {
self.data::<MultiAssetData>()
.asset_catalog_address
.get(asset_id)
.unwrap_or_default()
self.get_asset(asset_id).unwrap_or_default().catalog
}
}

Expand Down
1 change: 0 additions & 1 deletion examples/catalog/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ pub mod catalog_example {
CatalogAutoIndex::add_part_list(&mut catalog, vec![]),
Err(RmrkError::BadConfig.into())
);

}

#[ink::test]
Expand Down
13 changes: 13 additions & 0 deletions tests/equip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ describe("RMRK Merged Equippable", () => {
[4]
);
emit(addAssetResult, "AssetSet", { asset: 1 });
expect(
(await avatar.withSigner(deployer).query.getAssetAndEquippableData({ u64: 1 }, defaultAssetId))?.value.unwrap().ok.catalog
).to.be.equal(catalog.address);

console.log(" Added an asset to avatar");

Expand Down Expand Up @@ -283,6 +286,16 @@ describe("RMRK Merged Equippable", () => {
expect(
(await sword.withSigner(deployer).query.totalAssets())?.value.unwrap().toString()
).to.be.equal("3");

expect(
(await sword.withSigner(deployer).query.getAssetAndEquippableData({ u64: 1 }, equippableWoodenSword))?.value.unwrap().ok.catalog
).to.be.equal(catalog.address);
expect(
(await sword.withSigner(deployer).query.getAssetAndEquippableData({ u64: 1 }, equippableCopperSword))?.value.unwrap().ok.catalog
).to.be.equal(catalog.address);
expect(
(await sword.withSigner(deployer).query.getAssetAndEquippableData({ u64: 1 }, equippableKatanaSword))?.value.unwrap().ok.catalog
).to.be.equal(catalog.address);
console.log(" Added 3 sword assets");

console.log("Setting valid parent reference ID");
Expand Down