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

feat: add pallet-api/nonfungibles #432

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0ae0d7b
chore: rebase
chungquantin Jan 22, 2025
b585741
chore: rebase nonfungibles pallet to pallet-nfts
chungquantin Jan 16, 2025
5a272f9
chore: update nonfungibles tests
chungquantin Jan 16, 2025
2fccbcb
refactor: do_approve and do_cancel_approval
chungquantin Jan 16, 2025
3571709
chore: naming
chungquantin Jan 16, 2025
6777440
chore: resolve review comments
chungquantin Jan 20, 2025
9cf8502
chore: resolve review comments & update weights
chungquantin Jan 20, 2025
9f17d66
chore: add tests for nonfungibles api in runtime devnet
chungquantin Jan 20, 2025
010b9cf
fix: integration test & return post dispatch weight for transfer() on…
chungquantin Jan 21, 2025
c185d36
refactor: reorder `Read` impl in nonfungibles
chungquantin Jan 21, 2025
665feea
chore: remove unnecessary clone()
chungquantin Jan 21, 2025
f65dc98
chore: remove description for pallet configure
chungquantin Jan 21, 2025
15df8b3
refactor: approve() tests
chungquantin Jan 21, 2025
0396644
chore: resolve review comments
chungquantin Jan 21, 2025
ea59ba3
feat: add AttributeSet event
chungquantin Jan 21, 2025
728c1df
chore: comments and add test for Collection read
chungquantin Jan 22, 2025
bec6b25
chore: revert changes made to pallet nfts
chungquantin Jan 22, 2025
6a8adaa
chore: fix comment
chungquantin Jan 22, 2025
f70e005
chore: resolve review comments
chungquantin Jan 24, 2025
4bfbafe
chore: update function order
chungquantin Jan 24, 2025
ac68a1f
chore: add release conventions document and refactor CI to run node r…
Daanvdplas Jan 22, 2025
a8b2e7e
refactor: reuse `WeightInfo` in nonfungibles pallet test (#450)
chungquantin Jan 24, 2025
bbf5915
chore: update collection details field to public (#449)
chungquantin Jan 24, 2025
9604472
chore: rebase and remove local collection details type
chungquantin Jan 24, 2025
924e520
chore: remove impls.rs and update burn()
chungquantin Jan 24, 2025
5316da1
Merge branch 'main' into chungquantin/feat-main_pallet_nonfungibles
chungquantin Jan 24, 2025
e8d875b
chore: remove double-charged weights
chungquantin Jan 27, 2025
ea1b163
chore: reorder test and update comments
chungquantin Jan 27, 2025
cef9c9a
fix: test
chungquantin Jan 27, 2025
a6c586c
chore: sync spec
chungquantin Jan 27, 2025
665e9ba
chore: revert changes made to mint witness
chungquantin Jan 27, 2025
b25363b
chore: update approve() and tests
chungquantin Jan 27, 2025
7ca732d
chore: resolve review comments
chungquantin Jan 28, 2025
5955fcf
chore: add more comment to dispatchables
chungquantin Jan 28, 2025
8a3f1d3
chore: revert changes
chungquantin Jan 28, 2025
81a757b
refactor: approve weight
chungquantin Jan 28, 2025
50c6f94
chore: update approve() weight
chungquantin Jan 28, 2025
85d29ef
chore: update approve weight
chungquantin Jan 28, 2025
37cb437
refactor: weight approve (#460)
Daanvdplas Feb 3, 2025
c105ec7
feat(mainnet): add XCM APIs, config tests, refactor mod (#447)
peterwht Jan 24, 2025
9eab6e5
feat(mainnet): add pallet revive (#452)
peterwht Jan 29, 2025
b044782
feat(mainnet): Add treasury pallet and handle fees (#428)
f-gate Jan 30, 2025
8e43ad3
chore: revert pallet-nfts changes
chungquantin Feb 3, 2025
ac8b348
Merge branch 'main' into chungquantin/feat-main_pallet_nonfungibles
chungquantin Feb 3, 2025
cbca1b3
chore: update weights
chungquantin Feb 3, 2025
86892f4
chore: update index of the dispatchables
chungquantin Feb 3, 2025
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
5 changes: 3 additions & 2 deletions pallets/api/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use codec::{Decode, Encode};
use frame_support::{
derive_impl, parameter_types,
traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, Everything},
weights::constants::RocksDbWeight,
};
use frame_system::{EnsureRoot, EnsureSigned};
use pallet_nfts::PalletFeatures;
Expand Down Expand Up @@ -51,7 +52,7 @@ impl frame_system::Config for Test {
type BlockHashCount = BlockHashCount;
type BlockLength = ();
type BlockWeights = ();
type DbWeight = ();
type DbWeight = RocksDbWeight;
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
type Hash = H256;
type Hashing = BlakeTwo256;
type Lookup = IdentityLookup<Self::AccountId>;
Expand Down Expand Up @@ -157,7 +158,7 @@ impl pallet_nfts::pallet::BenchmarkHelper<u32, u32, Noop, u64, Noop> for () {
unimplemented!()
}

fn sign(signer: &Noop, message: &[u8]) -> Noop {
fn sign(_signer: &Noop, _message: &[u8]) -> Noop {
unimplemented!()
}
}
Expand Down
7 changes: 4 additions & 3 deletions pallets/api/src/nonfungibles/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ mod benchmarks {
#[extrinsic_call]
_(origin, collection_id, maybe_item, operator.clone(), approved);

assert!(
assert_eq!(
NftsOf::<T>::check_approval_permission(&collection_id, &maybe_item, &owner, &operator)
.is_ok() == approved
.is_ok(),
approved
);

if approved {
Expand Down Expand Up @@ -182,7 +183,7 @@ mod benchmarks {
Pallet::<T>::read(Read::GetAttribute {
key: BoundedVec::default(),
collection: CollectionIdOf::<T>::zero(),
item: ItemIdOf::<T>::zero(),
item: Some(ItemIdOf::<T>::zero()),
namespace: AttributeNamespace::CollectionOwner,
});
}
Expand Down
86 changes: 32 additions & 54 deletions pallets/api/src/nonfungibles/impls.rs
Original file line number Diff line number Diff line change
@@ -1,72 +1,50 @@
use frame_support::dispatch::{DispatchResultWithPostInfo, WithPostDispatchInfo};
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
use frame_support::dispatch::DispatchResult;
use frame_system::pallet_prelude::*;
use sp_runtime::traits::StaticLookup;

use super::{pallet::*, AccountIdOf, CollectionIdOf, ItemIdOf, NftsOf, WeightInfo};
use super::{pallet::*, AccountIdLookupOf, CollectionIdOf, ItemIdOf, NftsOf};

impl<T: Config> Pallet<T> {
/// Approves the transfer of a specific item or all collection items owned by the `owner` to an
/// `operator`.
// Approves the transfer of a specific item or all collection items owned by the `owner` to an
// `operator`.
///

Check warning on line 9 in pallets/api/src/nonfungibles/impls.rs

View workflow job for this annotation

GitHub Actions / clippy

empty doc comment

warning: empty doc comment --> pallets/api/src/nonfungibles/impls.rs:9:2 | 9 | /// | ^^^ | = help: consider removing or filling it = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_docs = note: `#[warn(clippy::empty_docs)]` on by default
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
/// # Parameters
/// - `owner` - The owner of the specified collection item(s).
/// - `collection` - The identifier of the collection.
/// - `maybe_item` - The optional item of the collection to be approved for delegated transfer.
/// If `None`, the approval applies to all `owner`'s collection items.
/// - `operator` - The account to delegate permission to transfer a specified collection item or
/// all collection items owned by the `owner`.
// # Parameters
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
// - `owner` - The owner of the specified collection item(s).
// - `collection` - The collection identifier.
// - `maybe_item` - The optional item of the collection to be approved for delegated transfer.
// If `None`, the approval applies to all `owner`'s collection items.
// - `operator` - The account to delegate permission to.
pub(crate) fn do_approve(
owner: OriginFor<T>,
collection: CollectionIdOf<T>,
maybe_item: Option<ItemIdOf<T>>,
operator: &AccountIdOf<T>,
) -> DispatchResultWithPostInfo {
let operator = T::Lookup::unlookup(operator.clone());
Ok(Some(match maybe_item {
Some(item) => {
NftsOf::<T>::approve_transfer(owner, collection, item, operator, None)
.map_err(|e| e.with_weight(<T as Config>::WeightInfo::approve(1, 1)))?;
<T as Config>::WeightInfo::approve(1, 1)
},
None => {
NftsOf::<T>::approve_collection_transfer(owner, collection, operator, None)
.map_err(|e| e.with_weight(<T as Config>::WeightInfo::approve(1, 0)))?;
<T as Config>::WeightInfo::approve(1, 0)
},
})
.into())
operator: AccountIdLookupOf<T>,
) -> DispatchResult {
match maybe_item {
Some(item) => NftsOf::<T>::approve_transfer(owner, collection, item, operator, None),
None => NftsOf::<T>::approve_collection_transfer(owner, collection, operator, None),
}
}

/// Cancel an approval to transfer a specific item or all items within a collection owned by
/// the `owner`.
// Cancel an approval to transfer a specific item or all items within a collection owned by
// the `owner`.
///

Check warning on line 30 in pallets/api/src/nonfungibles/impls.rs

View workflow job for this annotation

GitHub Actions / clippy

empty doc comment

warning: empty doc comment --> pallets/api/src/nonfungibles/impls.rs:30:2 | 30 | /// | ^^^ | = help: consider removing or filling it = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_docs
/// # Parameters
/// - `owner` - The owner of the specified collection item(s).
/// - `collection` - The identifier of the collection.
/// - `maybe_item` - The optional item of the collection that the operator has an approval to
/// transfer. If not provided, an approval to transfer all `owner`'s collection items will be
/// cancelled.
/// - `operator` - The account that had permission to transfer a specified collection item or
/// all collection items owned by the `owner`.
// # Parameters
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
// - `owner` - The owner of the specified collection item(s).
// - `collection` - The collection identifier.
// - `maybe_item` - The optional item of the collection that the operator has an approval to
// transfer. If not provided, an approval to transfer all `owner`'s collection items will be
// cancelled.
// - `operator` - The account that had permission to transfer a specified collection item or all
// collection items owned by the `owner`.
pub(crate) fn do_cancel_approval(
owner: OriginFor<T>,
collection: CollectionIdOf<T>,
maybe_item: Option<ItemIdOf<T>>,
operator: &AccountIdOf<T>,
) -> DispatchResultWithPostInfo {
let operator = T::Lookup::unlookup(operator.clone());
Ok(Some(match maybe_item {
Some(item) => {
NftsOf::<T>::cancel_approval(owner, collection, item, operator)
.map_err(|e| e.with_weight(<T as Config>::WeightInfo::approve(0, 1)))?;
<T as Config>::WeightInfo::approve(0, 1)
},
None => {
NftsOf::<T>::cancel_collection_approval(owner, collection, operator)
.map_err(|e| e.with_weight(<T as Config>::WeightInfo::approve(0, 0)))?;
<T as Config>::WeightInfo::approve(0, 0)
},
})
.into())
operator: AccountIdLookupOf<T>,
) -> DispatchResult {
match maybe_item {
Some(item) => NftsOf::<T>::cancel_approval(owner, collection, item, operator),
None => NftsOf::<T>::cancel_collection_approval(owner, collection, operator),
}
}
}
Loading
Loading