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 to runtime devnet #389

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
166 commits
Select commit Hold shift + click to select a range
c503f86
chore: fork pallet nfts
chungquantin Nov 13, 2024
b9fe4d8
chore: resolve feedback
chungquantin Nov 16, 2024
b63eda9
feat: nfts pallet optimization
chungquantin Nov 19, 2024
2c1fe5b
chore: fork pallet nfts (#382)
chungquantin Nov 18, 2024
b0fbeb3
chore: fork pallet nfts
chungquantin Nov 13, 2024
98217ae
chore: resolve feedback
chungquantin Nov 16, 2024
d954c70
feat: nfts pallet optimization
chungquantin Nov 19, 2024
b76dc4d
chore: fork pallet nfts (#382)
chungquantin Nov 18, 2024
aa829a7
Merge remote-tracking branch 'refs/remotes/origin/chungquantin/feat-n…
chungquantin Nov 19, 2024
9d1658e
feat: add new storage items and optimize
chungquantin Nov 19, 2024
69dd5f8
chore: resolve feedback
chungquantin Nov 19, 2024
4a5f17c
fix(nfts): clippy warnings
chungquantin Nov 21, 2024
37ec9ab
fix: clippy warnings
chungquantin Nov 21, 2024
3e886a9
fix: warnings
chungquantin Nov 22, 2024
8170b26
fix(nfts): rebase `feat-nfts` branch to fix clippy warnings (#392)
chungquantin Nov 22, 2024
363d06f
Merge branch 'chungquantin/fix-nfts_clippy' into chungquantin/feat-nfts
chungquantin Nov 22, 2024
f815bf2
fix: reformatting
chungquantin Nov 22, 2024
51bc52f
fix: remove unused storage fields from CollectionDetails (#393)
chungquantin Nov 22, 2024
8479203
Merge branch 'main' into chungquantin/feat-nfts
chungquantin Nov 22, 2024
d145029
fix: add comment & refactor cancel_collection
chungquantin Nov 22, 2024
0e1c2ab
chore: remove newline changes
chungquantin Nov 22, 2024
73f04da
chore: add comment for check allowance
chungquantin Nov 22, 2024
e8c5685
chore: register pallet_nfts benchmark
chungquantin Nov 22, 2024
a66ea2a
refactor(nfts): mapping with `ApprovalsOf` in the `Allowances` storag…
chungquantin Nov 26, 2024
cee5933
fix: weight path
chungquantin Nov 26, 2024
c7314c5
test: update pallet tests
chungquantin Nov 26, 2024
4b19ab5
test: expand cancel_approval test
chungquantin Nov 26, 2024
da2dc1c
refactor: do_approve_collection
chungquantin Nov 26, 2024
9dfe652
refactor: storate item names
chungquantin Nov 26, 2024
b39f1a1
refactor: allowances to approvals
chungquantin Nov 26, 2024
37b869a
refactor: approval methods
chungquantin Nov 26, 2024
a96a1f5
refactor: benchmarking
chungquantin Nov 26, 2024
5615f1b
chore: update weight file
chungquantin Nov 26, 2024
b7d620e
fix: resolve comments & collection approvals logic (#395)
chungquantin Nov 27, 2024
7b5e201
feat(nfts): collection approval deposit
chungquantin Nov 27, 2024
6cb7f05
refactor: update account balance in do_transfer()
chungquantin Nov 27, 2024
056ebc3
fix: clippy warnings
chungquantin Nov 27, 2024
0cba5fc
chore: update weights
chungquantin Nov 28, 2024
096e09c
fix: comments
chungquantin Nov 28, 2024
6ef07eb
chore: test no_account constant
chungquantin Nov 28, 2024
7f7a40f
refactor: remove `CollectionApprovalCount` storage item (#396)
chungquantin Nov 29, 2024
71d9d5c
fix: comments & test
chungquantin Nov 29, 2024
fe924ee
chore: check bad witness
chungquantin Nov 29, 2024
fa360a8
fix: test
chungquantin Nov 29, 2024
8d5155b
chore: resolve review comments (#398)
chungquantin Dec 2, 2024
9f6e159
fix: comments
chungquantin Dec 2, 2024
924d2d3
chore: update weights
chungquantin Dec 2, 2024
a9c2014
chore: comments & tests
chungquantin Dec 2, 2024
4404716
refactor: force origin
chungquantin Dec 3, 2024
0f1d960
chore: update weights
chungquantin Dec 4, 2024
e1226d6
chore: comments
chungquantin Dec 4, 2024
67f422a
chore: add integrity test
chungquantin Dec 4, 2024
60122d9
chore: update comment
chungquantin Dec 4, 2024
7d9c48f
chore: update comments
chungquantin Dec 4, 2024
e1b2b62
chore: update comments
chungquantin Dec 4, 2024
0656b4e
chore: resolve comments
chungquantin Dec 4, 2024
92d98ec
chore: add variables to tests
chungquantin Dec 5, 2024
b40d585
fix: tests
chungquantin Dec 5, 2024
86fcfa3
refactor: check_approval test
chungquantin Dec 5, 2024
62cd8fa
refactor: benchmarking code
chungquantin Dec 5, 2024
2acb01b
fix: tests
chungquantin Dec 5, 2024
ba33b7c
chore: revert clear_collection_approvals
chungquantin Dec 6, 2024
824978d
docs: pallet-nfts (#399)
chungquantin Dec 6, 2024
9b42bb7
refactor: approve_collection deposit
chungquantin Dec 6, 2024
f68a28e
chore: resolve review comments
chungquantin Dec 6, 2024
1da978d
refactor: clear_collection_approvals
chungquantin Dec 6, 2024
5b639f7
fix: comments
chungquantin Dec 6, 2024
1afd4ba
fix: comment
chungquantin Dec 6, 2024
672ceae
refactor: transfer_should_workd
chungquantin Dec 6, 2024
c62dd83
Revert "refactor: transfer_should_workd"
chungquantin Dec 6, 2024
c76f66b
chore: comments
chungquantin Dec 9, 2024
8f1c56d
chore: resolve review comments
chungquantin Dec 9, 2024
627a0e6
chore: update README
chungquantin Dec 10, 2024
4535a52
chore: comments
chungquantin Dec 10, 2024
6eb8928
refactor: test check_approval (#403)
Daanvdplas Dec 11, 2024
25e58d3
chore: resolve feedback comments (#404)
chungquantin Dec 11, 2024
ca27938
chore: fix comment
chungquantin Dec 11, 2024
fafb988
chore: update weight and test
chungquantin Dec 12, 2024
e88b6ad
chore: remove TODO
chungquantin Dec 12, 2024
abc54e8
chore: resolve comments
chungquantin Dec 12, 2024
6ef9b32
chore: verify benchmarks with storage checks
chungquantin Dec 13, 2024
0076a3b
refactor: tests (#405)
Daanvdplas Dec 13, 2024
4cd8dd5
chore: revert formatting
chungquantin Dec 13, 2024
2ea60c0
chore: revert unnecessary change
chungquantin Dec 16, 2024
829b433
refactor: dispatchables & events
chungquantin Dec 16, 2024
9af5e24
chore: add new field in ApprovalsCancelled and refactored events
chungquantin Dec 16, 2024
6cf5ca5
feat: add pallet-api/nonfungibles
chungquantin Nov 19, 2024
e6515ec
chore: rebase
chungquantin Nov 27, 2024
29af424
chore: rebase pallet-nfts
chungquantin Dec 4, 2024
9d9868e
feat: add pallet-api/nonfungibles
chungquantin Nov 19, 2024
28e55cb
chore: rebase
chungquantin Nov 27, 2024
e2c4721
chore: comments
chungquantin Dec 9, 2024
6d12fc8
feat: add pallet-api/nonfungibles
chungquantin Nov 19, 2024
49b6e9d
chore: rebase
chungquantin Nov 27, 2024
0bcc6f3
chore: rebase
chungquantin Dec 9, 2024
6f8aa13
fix: test and balance_of implementation
chungquantin Dec 13, 2024
240d0a4
chore: rebase
chungquantin Nov 27, 2024
fad85e8
chore: update comment
chungquantin Dec 4, 2024
43e78b8
chore: update comments
chungquantin Dec 4, 2024
091ed9a
chore: resolve comments
chungquantin Dec 4, 2024
b564622
chore: add variables to tests
chungquantin Dec 5, 2024
511bc3d
fix: tests
chungquantin Dec 5, 2024
6dccfce
refactor: check_approval test
chungquantin Dec 5, 2024
aa5cab6
refactor: benchmarking code
chungquantin Dec 5, 2024
bef6bbe
fix: tests
chungquantin Dec 5, 2024
43f4c28
chore: revert clear_collection_approvals
chungquantin Dec 6, 2024
20e016e
docs: pallet-nfts (#399)
chungquantin Dec 6, 2024
e3514fe
chore: resolve review comments
chungquantin Dec 6, 2024
56630a3
refactor: clear_collection_approvals
chungquantin Dec 6, 2024
c6e84fb
fix: comments
chungquantin Dec 6, 2024
78961d4
fix: comment
chungquantin Dec 6, 2024
f2cb42e
refactor: transfer_should_workd
chungquantin Dec 6, 2024
9dce44b
Revert "refactor: transfer_should_workd"
chungquantin Dec 6, 2024
9ef03e3
chore: comments
chungquantin Dec 9, 2024
31579c3
feat: add pallet-api/nonfungibles
chungquantin Nov 19, 2024
b377088
chore: rebase
chungquantin Dec 9, 2024
d2d311d
chore: rebase
chungquantin Dec 13, 2024
f039429
chore: revert changes
chungquantin Dec 16, 2024
87aa08e
chore: comments
chungquantin Dec 16, 2024
c1b46c1
chore: remove zero collection approvals
chungquantin Dec 16, 2024
11d60a1
chore: resolve comments
chungquantin Dec 17, 2024
7492b81
chore: rewrite test (#410)
chungquantin Dec 18, 2024
7b62a84
Merge branch 'chungquantin/feat-nfts' into chungquantin/feat-pallet_n…
chungquantin Dec 18, 2024
8a341d9
refactor: account balance deposit
evilrobot-01 Dec 18, 2024
24c0c2d
chore: revert test changes
chungquantin Dec 18, 2024
e391888
chore: revert test changes
chungquantin Dec 18, 2024
31368ca
refactor: account balance deposit & tests
chungquantin Dec 19, 2024
3f9e07e
refactor: account balance deposit & tests
chungquantin Dec 19, 2024
99b31d8
Merge branch 'chungquantin/feat-nfts' into frank/nfts-balance-deposit
chungquantin Dec 19, 2024
5ecb661
chore: benchmarking
chungquantin Dec 19, 2024
ee364fb
fix: clippy warning
chungquantin Dec 19, 2024
5015e90
chore: comments
chungquantin Dec 19, 2024
79244c4
chore: minor refactor
chungquantin Dec 20, 2024
04c69d7
feat: add pallet-api/nonfungibles to runtime devnet
chungquantin Nov 19, 2024
8d4ae0d
feat: add pallet-api/nonfungibles
chungquantin Nov 19, 2024
435d469
Revert "feat: add pallet-api/nonfungibles"
chungquantin Dec 20, 2024
28f5cc6
chore: fix runtime tests
chungquantin Dec 20, 2024
15fd656
chore: fix clippy
chungquantin Dec 20, 2024
8d674be
chore: fix nonfungible test
chungquantin Dec 20, 2024
94f0c74
chore: resolve comments (exclude weights)
chungquantin Dec 21, 2024
d3ae740
chore: resolve review comments
chungquantin Dec 22, 2024
ed6d6a2
fix: deposit bytes
chungquantin Dec 22, 2024
bda3e47
chore: update test & weights
chungquantin Dec 22, 2024
460859f
chore: benchmarking
chungquantin Dec 23, 2024
663066e
chore: update comments
chungquantin Dec 23, 2024
46887f8
Merge branch 'frank/nfts-balance-deposit' into chungquantin/feat-pall…
chungquantin Dec 23, 2024
80fe5f3
chore: rebase account balance deposit branch
chungquantin Dec 23, 2024
f07cf79
chore: fix nonfungible test
chungquantin Dec 20, 2024
eadffa5
refactor: account balance deposit
evilrobot-01 Dec 18, 2024
028ca4a
chore: revert test changes
chungquantin Dec 18, 2024
3cc9d11
refactor: account balance deposit & tests
chungquantin Dec 19, 2024
6eab674
refactor: account balance deposit & tests
chungquantin Dec 19, 2024
268e164
chore: benchmarking
chungquantin Dec 19, 2024
8d74907
fix: clippy warning
chungquantin Dec 19, 2024
9e6a460
chore: comments
chungquantin Dec 19, 2024
bc1b2b4
chore: resolve comments (exclude weights)
chungquantin Dec 21, 2024
9d18096
chore: resolve review comments
chungquantin Dec 22, 2024
f2fed98
fix: deposit bytes
chungquantin Dec 22, 2024
6046357
chore: update test & weights
chungquantin Dec 22, 2024
e16406c
chore: benchmarking
chungquantin Dec 23, 2024
717bd25
chore: update comments
chungquantin Dec 23, 2024
6b3bbab
chore: rebase account balance deposit branch
chungquantin Dec 23, 2024
cbc477e
feat: add pallet-api/nonfungibles
chungquantin Nov 19, 2024
2dd9a8c
Revert "feat: add pallet-api/nonfungibles"
chungquantin Dec 20, 2024
feac843
Merge branch 'chungquantin/feat-pallet_nonfungibles' into chungquanti…
chungquantin Dec 27, 2024
5075c02
chore: rebase
chungquantin Dec 27, 2024
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: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pallets/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ frame-benchmarking.workspace = true
frame-support.workspace = true
frame-system.workspace = true
pallet-assets.workspace = true
pallet-nfts.workspace = true
sp-runtime.workspace = true
sp-std.workspace = true

Expand All @@ -37,6 +38,7 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-nfts/runtime-benchmarks",
"pop-chain-extension/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
Expand All @@ -47,6 +49,7 @@ std = [
"frame-system/std",
"pallet-assets/std",
"pallet-balances/std",
"pallet-nfts/std",
"pop-chain-extension/std",
"scale-info/std",
"sp-core/std",
Expand All @@ -57,5 +60,6 @@ std = [
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-nfts/try-runtime",
"sp-runtime/try-runtime",
]
1 change: 1 addition & 0 deletions pallets/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub use extension::Extension;
use frame_support::pallet_prelude::Weight;

pub mod extension;

Check warning on line 6 in pallets/api/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a module

warning: missing documentation for a module --> pallets/api/src/lib.rs:6:1 | 6 | pub mod extension; | ^^^^^^^^^^^^^^^^^
pub mod fungibles;
#[cfg(test)]
mod mock;
pub mod nonfungibles;

/// Trait for performing reads of runtime state.
pub trait Read {
Expand Down
95 changes: 92 additions & 3 deletions pallets/api/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use codec::{Decode, Encode};
use frame_support::{
derive_impl, parameter_types,
traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, Everything},
traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, Everything},
};
use frame_system::{EnsureRoot, EnsureSigned};
use pallet_nfts::PalletFeatures;
use scale_info::TypeInfo;
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Lazy, Verify},
BuildStorage,
};

Expand All @@ -29,6 +32,8 @@ frame_support::construct_runtime!(
Assets: pallet_assets::<Instance1>,
Balances: pallet_balances,
Fungibles: crate::fungibles,
Nfts: pallet_nfts::<Instance1>,
NonFungibles: crate::nonfungibles
}
);

Expand Down Expand Up @@ -91,7 +96,7 @@ impl pallet_assets::Config<AssetsInstance> for Test {
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type CallbackHandle = ();
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<u64>>;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<Self::AccountId>>;
type Currency = Balances;
type Extra = ();
type ForceOrigin = EnsureRoot<u64>;
Expand All @@ -110,6 +115,90 @@ impl crate::fungibles::Config for Test {
type WeightInfo = ();
}

parameter_types! {
pub storage Features: PalletFeatures = PalletFeatures::all_enabled();
}

#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, TypeInfo)]
pub struct Noop;

impl IdentifyAccount for Noop {
type AccountId = AccountId;

fn into_account(self) -> Self::AccountId {
0
}
}

impl Verify for Noop {
type Signer = Noop;

fn verify<L: Lazy<[u8]>>(
&self,
_msg: L,
_signer: &<Self::Signer as IdentifyAccount>::AccountId,
) -> bool {
false
}
}

#[cfg(feature = "runtime-benchmarks")]
impl pallet_nfts::pallet::BenchmarkHelper<u32, u32, Noop, u64, Noop> for () {
fn collection(i: u16) -> u32 {
i.into()
}

fn item(i: u16) -> u32 {
i.into()
}

fn signer() -> (Noop, u64) {
unimplemented!()
}

fn sign(signer: &Noop, message: &[u8]) -> Noop {
unimplemented!()
}
}

type NftsInstance = pallet_nfts::Instance1;
impl pallet_nfts::Config<NftsInstance> for Test {
type ApprovalsLimit = ConstU32<10>;
type AttributeDepositBase = ConstU128<1>;
type BalanceDeposit = ConstU128<1>;
type CollectionApprovalDeposit = ConstU128<1>;
type CollectionDeposit = ConstU128<2>;
type CollectionId = u32;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<u64>>;
type Currency = Balances;
type DepositPerByte = ConstU128<1>;
type Features = Features;
type ForceOrigin = frame_system::EnsureRoot<Self::AccountId>;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
type ItemAttributesApprovalsLimit = ConstU32<2>;
type ItemDeposit = ConstU128<1>;
type ItemId = u32;
type KeyLimit = ConstU32<50>;
type Locker = ();
type MaxAttributesPerCall = ConstU32<2>;
type MaxDeadlineDuration = ConstU64<10000>;
type MaxTips = ConstU32<10>;
type MetadataDepositBase = ConstU128<1>;
type OffchainPublic = Noop;
type OffchainSignature = Noop;
type RuntimeEvent = RuntimeEvent;
type StringLimit = ConstU32<50>;
type ValueLimit = ConstU32<50>;
type WeightInfo = ();
}

impl crate::nonfungibles::Config for Test {
type NftsInstance = NftsInstance;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}

pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
Expand Down
110 changes: 110 additions & 0 deletions pallets/api/src/nonfungibles/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//! Benchmarking setup for pallet_api::nonfungibles

use frame_benchmarking::{account, v2::*};
use frame_support::{traits::nonfungibles_v2::Inspect, BoundedVec};
use sp_runtime::traits::Zero;

use super::{AttributeNamespace, CollectionIdOf, Config, ItemIdOf, NftsInstanceOf, Pallet, Read};
use crate::Read as _;

const SEED: u32 = 1;

#[benchmarks(
where
<pallet_nfts::Pallet<T, NftsInstanceOf<T>> as Inspect<<T as frame_system::Config>::AccountId>>::ItemId: Zero,
<pallet_nfts::Pallet<T, NftsInstanceOf<T>> as Inspect<<T as frame_system::Config>::AccountId>>::CollectionId: Zero,
)]
mod benchmarks {
use super::*;

#[benchmark]
// Storage: `Collection`
fn total_supply() {
#[block]
{
Pallet::<T>::read(Read::TotalSupply(CollectionIdOf::<T>::zero()));
}
}

#[benchmark]
// Storage: `AccountBalance`
fn balance_of() {
#[block]
{
Pallet::<T>::read(Read::BalanceOf {
collection: CollectionIdOf::<T>::zero(),
owner: account("Alice", 0, SEED),
});
}
}

#[benchmark]
// Storage: `Allowances`, `Item`
fn allowance() {
#[block]
{
Pallet::<T>::read(Read::Allowance {
collection: CollectionIdOf::<T>::zero(),
owner: account("Alice", 0, SEED),
operator: account("Bob", 0, SEED),
item: Some(ItemIdOf::<T>::zero()),
});
}
}

#[benchmark]
// Storage: `Item`
fn owner_of() {
#[block]
{
Pallet::<T>::read(Read::OwnerOf {
collection: CollectionIdOf::<T>::zero(),
item: ItemIdOf::<T>::zero(),
});
}
}

#[benchmark]
// Storage: `Attribute`
fn get_attribute() {
#[block]
{
Pallet::<T>::read(Read::GetAttribute {
key: BoundedVec::default(),
collection: CollectionIdOf::<T>::zero(),
item: ItemIdOf::<T>::zero(),
namespace: AttributeNamespace::CollectionOwner,
});
}
}

#[benchmark]
// Storage: `Collection`
fn collection() {
#[block]
{
Pallet::<T>::read(Read::Collection(CollectionIdOf::<T>::zero()));
}
}

#[benchmark]
// Storage: `NextCollectionId`
fn next_collection_id() {
#[block]
{
Pallet::<T>::read(Read::NextCollectionId);
}
}

#[benchmark]
// Storage: `ItemMetadata`
fn item_metadata() {
#[block]
{
Pallet::<T>::read(Read::ItemMetadata {
collection: CollectionIdOf::<T>::zero(),
item: ItemIdOf::<T>::zero(),
});
}
}
}
91 changes: 91 additions & 0 deletions pallets/api/src/nonfungibles/impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
use frame_support::dispatch::{DispatchResultWithPostInfo, WithPostDispatchInfo};
use frame_system::pallet_prelude::*;
use pallet_nfts::WeightInfo as NftsWeightInfoTrait;
use sp_runtime::traits::StaticLookup;

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

impl<T: Config> Pallet<T> {
/// Approves the transfer of a specific item or all collection items owned by the origin to
/// an operator.
///
/// # 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 that will be allowed to take control of the specified item or all
/// owner's collection items.
pub(crate) fn do_approve(
owner: OriginFor<T>,
collection: CollectionIdOf<T>,
maybe_item: Option<ItemIdOf<T>>,
operator: &AccountIdOf<T>,
) -> DispatchResultWithPostInfo {
Ok(Some(match maybe_item {
Some(item) => {
NftsOf::<T>::approve_transfer(
owner,
collection,
item,
T::Lookup::unlookup(operator.clone()),
None,
)
.map_err(|e| e.with_weight(NftsWeightInfoOf::<T>::approve_transfer()))?;
NftsWeightInfoOf::<T>::approve_transfer()
},
None => {
NftsOf::<T>::approve_collection_transfer(
owner,
collection,
T::Lookup::unlookup(operator.clone()),
None,
)
.map_err(|e| e.with_weight(NftsWeightInfoOf::<T>::approve_collection_transfer()))?;
NftsWeightInfoOf::<T>::approve_collection_transfer()
},
})
.into())
}

/// Cancel an approval to transfer a specific item or all items within a collection owned by
/// the origin.
///
/// # 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 the sepcified item or all owner's
/// collection items.
pub(crate) fn do_cancel_approval(
owner: OriginFor<T>,
collection: CollectionIdOf<T>,
maybe_item: Option<ItemIdOf<T>>,
operator: &AccountIdOf<T>,
) -> DispatchResultWithPostInfo {
Ok(Some(match maybe_item {
Some(item) => {
NftsOf::<T>::cancel_approval(
owner,
collection,
item,
T::Lookup::unlookup(operator.clone()),
)
.map_err(|e| e.with_weight(NftsWeightInfoOf::<T>::cancel_approval()))?;
NftsWeightInfoOf::<T>::cancel_approval()
},
None => {
NftsOf::<T>::cancel_collection_approval(
owner,
collection,
T::Lookup::unlookup(operator.clone()),
)
.map_err(|e| e.with_weight(NftsWeightInfoOf::<T>::cancel_collection_approval()))?;
NftsWeightInfoOf::<T>::cancel_collection_approval()
},
})
.into())
}
}
Loading
Loading