Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
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
7 changes: 7 additions & 0 deletions frame/nfts/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {

T::Currency::reserve(&owner, deposit)?;

let ref_id = CollectionNextId::<T, I>::get();
Collection::<T, I>::insert(
collection,
CollectionDetails {
Expand All @@ -85,11 +86,17 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
item_metadatas: 0,
attributes: 0,
is_frozen: false,
ref_id,
},
);

CollectionAccount::<T, I>::insert(&owner, &collection, ());
Self::deposit_event(event);

// update the next ref_id value
let next_ref_id = ref_id.saturating_add(1);
CollectionNextId::<T, I>::put(next_ref_id);

Ok(())
}

Expand Down
5 changes: 5 additions & 0 deletions frame/nfts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ pub mod pallet {
pub(super) type CollectionMaxSupply<T: Config<I>, I: 'static = ()> =
StorageMap<_, Blake2_128Concat, T::CollectionId, u32, OptionQuery>;

/// Stores the collection's next id.
#[pallet::storage]
pub(super) type CollectionNextId<T: Config<I>, I: 'static = ()> =
StorageValue<_, u64, ValueQuery>;

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config<I>, I: 'static = ()> {
Expand Down
2 changes: 2 additions & 0 deletions frame/nfts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ fn lifecycle_should_work() {
assert_ok!(Nfts::create(Origin::signed(1), 0, 1));
assert_eq!(Balances::reserved_balance(&1), 2);
assert_eq!(collections(), vec![(1, 0)]);
assert_eq!(CollectionNextId::<Test>::get(), 1);
assert_ok!(Nfts::set_collection_metadata(Origin::signed(1), 0, bvec![0, 0], false));
assert_eq!(Balances::reserved_balance(&1), 5);
assert!(CollectionMetadataOf::<Test>::contains_key(0));
Expand All @@ -122,6 +123,7 @@ fn lifecycle_should_work() {
assert_eq!(items(), vec![(10, 0, 42), (20, 0, 69)]);
assert_eq!(Collection::<Test>::get(0).unwrap().items, 2);
assert_eq!(Collection::<Test>::get(0).unwrap().item_metadatas, 0);
assert_eq!(Collection::<Test>::get(0).unwrap().ref_id, 0);

assert_ok!(Nfts::set_metadata(Origin::signed(1), 0, 42, bvec![42, 42], false));
assert_eq!(Balances::reserved_balance(&1), 10);
Expand Down
2 changes: 2 additions & 0 deletions frame/nfts/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub struct CollectionDetails<AccountId, DepositBalance> {
pub(super) attributes: u32,
/// Whether the collection is frozen for non-admin transfers.
pub(super) is_frozen: bool,
/// Auto-incremental reference id.
pub(super) ref_id: u64,
}

/// Witness data for the destroy transactions.
Expand Down