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(nfts): add CollectionApprovals and AccountBalance storages, and general improvements #387

Merged
merged 104 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
104 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
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
24c0c2d
chore: revert test changes
chungquantin Dec 18, 2024
cac4bed
chore: update tests
chungquantin Dec 30, 2024
4b4cd22
chore: update tests
chungquantin Dec 31, 2024
97450fa
chore: apply suggestion
chungquantin Dec 31, 2024
881a04c
refactor: tests for collection approval (#419)
Daanvdplas Jan 7, 2025
504d0f0
feat: allow admin to force cancel approvals
chungquantin Jan 9, 2025
1158143
chore: rename destroy test method
chungquantin Jan 9, 2025
05c16f7
feat: allow admin to force cancel approvals
chungquantin Jan 9, 2025
68a86c6
refactor: force_cancel_collection_approval_works_with_admin
chungquantin Jan 9, 2025
1cdad44
feat(nfts): `AccountBalance` deposit (#413)
chungquantin Jan 9, 2025
5d350b1
fix: deposit saturation
chungquantin Jan 10, 2025
3e2620a
chore: revert admin permission on collection approvals
chungquantin Jan 10, 2025
f83bdc5
feat: not require deposit for force_approve_collection_transfer
chungquantin Jan 10, 2025
e748e5e
chore: update weight
chungquantin Jan 14, 2025
8b4c4c4
chore: update weight
chungquantin Jan 14, 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
64 changes: 56 additions & 8 deletions pallets/nfts/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

//! Nfts pallet benchmarking.

#![cfg(feature = "runtime-benchmarks")]

Check warning on line 20 in pallets/nfts/src/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

duplicated attribute

warning: duplicated attribute --> pallets/nfts/src/benchmarking.rs:20:8 | 20 | #![cfg(feature = "runtime-benchmarks")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first defined here --> pallets/nfts/src/lib.rs:31:7 | 31 | #[cfg(feature = "runtime-benchmarks")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute --> pallets/nfts/src/benchmarking.rs:20:8 | 20 | #![cfg(feature = "runtime-benchmarks")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes = note: `#[warn(clippy::duplicated_attributes)]` on by default

use enumflags2::{BitFlag, BitFlags};
use frame_benchmarking::v1::{
Expand Down Expand Up @@ -64,6 +64,27 @@
(caller, caller_lookup)
}

fn approve_collection<T: Config<I>, I: 'static>(
index: u32,
) -> (T::AccountId, AccountIdLookupOf<T>) {
let caller = Collection::<T, I>::get(T::Helper::collection(0)).unwrap().owner;
if caller != whitelisted_caller() {
whitelist_account!(caller);
}
let caller_lookup = T::Lookup::unlookup(caller.clone());
let delegate: T::AccountId = account("delegate", 0, SEED + index);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let deadline = BlockNumberFor::<T>::max_value();
assert_ok!(Nfts::<T, I>::approve_transfer(
SystemOrigin::Signed(caller.clone()).into(),
T::Helper::collection(0),
None,
delegate_lookup.clone(),
Some(deadline),
));
(caller, caller_lookup)
}

fn mint_item<T: Config<I>, I: 'static>(
index: u16,
) -> (T::ItemId, T::AccountId, AccountIdLookupOf<T>) {
Expand All @@ -74,10 +95,10 @@
whitelist_account!(caller);
}
let caller_lookup = T::Lookup::unlookup(caller.clone());
let item_exists = Item::<T, I>::contains_key(&collection, &item);

Check warning on line 98 in pallets/nfts/src/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/benchmarking.rs:98:60 | 98 | let item_exists = Item::<T, I>::contains_key(&collection, &item); | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 98 in pallets/nfts/src/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/benchmarking.rs:98:47 | 98 | let item_exists = Item::<T, I>::contains_key(&collection, &item); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args = note: `#[warn(clippy::needless_borrows_for_generic_args)]` on by default
let item_config = ItemConfigOf::<T, I>::get(&collection, &item);

Check warning on line 99 in pallets/nfts/src/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/benchmarking.rs:99:59 | 99 | let item_config = ItemConfigOf::<T, I>::get(&collection, &item); | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 99 in pallets/nfts/src/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/benchmarking.rs:99:46 | 99 | let item_config = ItemConfigOf::<T, I>::get(&collection, &item); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
if item_exists {
return (item, caller, caller_lookup)
return (item, caller, caller_lookup);
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
} else if let Some(item_config) = item_config {
assert_ok!(Nfts::<T, I>::force_mint(
SystemOrigin::Signed(caller.clone()).into(),
Expand Down Expand Up @@ -250,6 +271,8 @@
let m in 0 .. 1_000;
let c in 0 .. 1_000;
let a in 0 .. 1_000;
let h in 0 .. 1_000;
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
let l in 0 .. 1_000;

let (collection, caller, _) = create_collection::<T, I>();
add_collection_metadata::<T, I>();
Expand All @@ -267,6 +290,13 @@
for i in 0..a {
add_collection_attribute::<T, I>(i as u16);
}
for i in 0..h {
mint_item::<T, I>(i as u16);
burn_item::<T, I>(i as u16);
}
for i in 0..l {
approve_collection::<T, I>(i);
}
let witness = Collection::<T, I>::get(collection).unwrap().destroy_witness();
}: _(SystemOrigin::Signed(caller), collection, witness)
verify {
Expand Down Expand Up @@ -573,27 +603,45 @@
}

approve_transfer {
let i in 0..1;
chungquantin marked this conversation as resolved.
Show resolved Hide resolved

let (collection, caller, _) = create_collection::<T, I>();
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
let (item, ..) = mint_item::<T, I>(0);
let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let deadline = BlockNumberFor::<T>::max_value();
}: _(SystemOrigin::Signed(caller.clone()), collection, item, delegate_lookup, Some(deadline))
let maybe_deadline = if i == 0 {
None
} else {
Some(BlockNumberFor::<T>::max_value())
};
let maybe_item = if i == 0 {
None
} else {
Some(item)
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved
};
}: _(SystemOrigin::Signed(caller.clone()), collection, maybe_item, delegate_lookup, maybe_deadline)
verify {
assert_last_event::<T, I>(Event::TransferApproved { collection, item, owner: caller, delegate, deadline: Some(deadline) }.into());
assert_last_event::<T, I>(Event::TransferApproved { collection, item: maybe_item, owner: caller, delegate, deadline: maybe_deadline }.into());
}

cancel_approval {
let i in 0..1;
chungquantin marked this conversation as resolved.
Show resolved Hide resolved

let (collection, caller, _) = create_collection::<T, I>();
let (item, ..) = mint_item::<T, I>(0);
let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let origin = SystemOrigin::Signed(caller.clone()).into();
let deadline = BlockNumberFor::<T>::max_value();
Nfts::<T, I>::approve_transfer(origin, collection, item, delegate_lookup.clone(), Some(deadline))?;
}: _(SystemOrigin::Signed(caller.clone()), collection, item, delegate_lookup)
let maybe_item = if i == 0 {
None
} else {
Some(item)
};
Nfts::<T, I>::approve_transfer(origin, collection, maybe_item, delegate_lookup.clone(), Some(deadline))?;
}: _(SystemOrigin::Signed(caller.clone()), collection, maybe_item, delegate_lookup)
verify {
assert_last_event::<T, I>(Event::ApprovalCancelled { collection, item, owner: caller, delegate }.into());
assert_last_event::<T, I>(Event::ApprovalCancelled { collection, item: maybe_item, owner: caller, delegate }.into());
}

clear_all_transfer_approvals {
Expand All @@ -603,7 +651,7 @@
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let origin = SystemOrigin::Signed(caller.clone()).into();
let deadline = BlockNumberFor::<T>::max_value();
Nfts::<T, I>::approve_transfer(origin, collection, item, delegate_lookup.clone(), Some(deadline))?;
Nfts::<T, I>::approve_transfer(origin, collection, Some(item), delegate_lookup.clone(), Some(deadline))?;
}: _(SystemOrigin::Signed(caller.clone()), collection, item)
verify {
assert_last_event::<T, I>(Event::AllApprovalsCancelled {collection, item, owner: caller}.into());
Expand Down Expand Up @@ -682,7 +730,7 @@
}

pay_tips {
let n in 0 .. T::MaxTips::get() as u32;

Check warning on line 733 in pallets/nfts/src/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

casting to the same type is unnecessary (`u32` -> `u32`)

warning: casting to the same type is unnecessary (`u32` -> `u32`) --> pallets/nfts/src/benchmarking.rs:733:17 | 733 | let n in 0 .. T::MaxTips::get() as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `T::MaxTips::get()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast = note: `#[warn(clippy::unnecessary_cast)]` on by default
let amount = BalanceOf::<T, I>::from(100u32);
let caller: T::AccountId = whitelisted_caller();
let collection = T::Helper::collection(0);
Expand Down Expand Up @@ -788,7 +836,7 @@
}

mint_pre_signed {
let n in 0 .. T::MaxAttributesPerCall::get() as u32;

Check warning on line 839 in pallets/nfts/src/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

casting to the same type is unnecessary (`u32` -> `u32`)

warning: casting to the same type is unnecessary (`u32` -> `u32`) --> pallets/nfts/src/benchmarking.rs:839:17 | 839 | let n in 0 .. T::MaxAttributesPerCall::get() as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `T::MaxAttributesPerCall::get()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
let (caller_public, caller) = T::Helper::signer();
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());
let caller_lookup = T::Lookup::unlookup(caller.clone());
Expand Down Expand Up @@ -823,14 +871,14 @@
let target: T::AccountId = account("target", 0, SEED);
T::Currency::make_free_balance_be(&target, DepositBalanceOf::<T, I>::max_value());
frame_system::Pallet::<T>::set_block_number(One::one());
}: _(SystemOrigin::Signed(target.clone()), Box::new(mint_data), signature.into(), caller)

Check warning on line 874 in pallets/nfts/src/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

useless conversion to the same type: `<T as pallet::Config<I>>::OffchainSignature`

warning: useless conversion to the same type: `<T as pallet::Config<I>>::OffchainSignature` --> pallets/nfts/src/benchmarking.rs:874:66 | 874 | }: _(SystemOrigin::Signed(target.clone()), Box::new(mint_data), signature.into(), caller) | ^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `signature` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `#[warn(clippy::useless_conversion)]` on by default
verify {
let metadata: BoundedVec<_, _> = metadata.try_into().unwrap();
assert_last_event::<T, I>(Event::ItemMetadataSet { collection, item, data: metadata }.into());
}

set_attributes_pre_signed {
let n in 0 .. T::MaxAttributesPerCall::get() as u32;

Check warning on line 881 in pallets/nfts/src/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

casting to the same type is unnecessary (`u32` -> `u32`)

warning: casting to the same type is unnecessary (`u32` -> `u32`) --> pallets/nfts/src/benchmarking.rs:881:17 | 881 | let n in 0 .. T::MaxAttributesPerCall::get() as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `T::MaxAttributesPerCall::get()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
let (collection, _, _) = create_collection::<T, I>();

let item_owner: T::AccountId = account("item_owner", 0, SEED);
Expand Down Expand Up @@ -866,7 +914,7 @@
let signature = T::Helper::sign(&signer_public, &message);

frame_system::Pallet::<T>::set_block_number(One::one());
}: _(SystemOrigin::Signed(item_owner.clone()), pre_signed_data, signature.into(), signer.clone())

Check warning on line 917 in pallets/nfts/src/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

useless conversion to the same type: `<T as pallet::Config<I>>::OffchainSignature`

warning: useless conversion to the same type: `<T as pallet::Config<I>>::OffchainSignature` --> pallets/nfts/src/benchmarking.rs:917:66 | 917 | }: _(SystemOrigin::Signed(item_owner.clone()), pre_signed_data, signature.into(), signer.clone()) | ^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `signature` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
verify {
assert_last_event::<T, I>(
Event::PreSignedAttributesSet {
Expand Down
20 changes: 19 additions & 1 deletion pallets/nfts/src/common_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@
Collection::<T, I>::get(collection).map(|i| i.owner)
}

/// Get the total number of items in the collection, if the collection exists.
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
pub fn collection_items(collection: T::CollectionId) -> Option<u32> {
Collection::<T, I>::get(collection).map(|i| i.items)
}

/// Get the allowances to spend items within the collection.
pub fn collection_allowances(collection: T::CollectionId) -> Option<u32> {
Collection::<T, I>::get(collection).map(|i| i.allowances)
}

/// Get the metadata of the collection item.
pub fn item_metadata(
collection: T::CollectionId,
item: T::ItemId,
) -> Option<BoundedVec<u8, T::StringLimit>> {
ItemMetadataOf::<T, I>::get(collection, item).map(|metadata| metadata.data)
}

/// Validates the signature of the given data with the provided signer's account ID.
///
/// # Errors
Expand All @@ -45,8 +63,8 @@
signature: &T::OffchainSignature,
signer: &T::AccountId,
) -> DispatchResult {
if signature.verify(&**data, &signer) {

Check warning on line 66 in pallets/nfts/src/common_functions.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> pallets/nfts/src/common_functions.rs:66:32 | 66 | if signature.verify(&**data, &signer) { | ^^^^^^^ help: change this to: `signer` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default
return Ok(())
return Ok(());
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
}

// NOTE: for security reasons modern UIs implicitly wrap the data requested to sign into
Expand All @@ -58,7 +76,7 @@
wrapped.extend(data);
wrapped.extend(suffix);

ensure!(signature.verify(&*wrapped, &signer), Error::<T, I>::WrongSignature);

Check warning on line 79 in pallets/nfts/src/common_functions.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> pallets/nfts/src/common_functions.rs:79:39 | 79 | ensure!(signature.verify(&*wrapped, &signer), Error::<T, I>::WrongSignature); | ^^^^^^^ help: change this to: `signer` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

Ok(())
}
Expand All @@ -70,7 +88,7 @@
}

#[cfg(any(test, feature = "runtime-benchmarks"))]
pub fn set_next_id(id: T::CollectionId) {

Check warning on line 91 in pallets/nfts/src/common_functions.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for an associated function

warning: missing documentation for an associated function --> pallets/nfts/src/common_functions.rs:91:2 | 91 | pub fn set_next_id(id: T::CollectionId) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
NextCollectionId::<T, I>::set(Some(id));
}

Expand Down
105 changes: 100 additions & 5 deletions pallets/nfts/src/features/approvals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
Error::<T, I>::MethodDisabled
);
let mut details =
Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?;

Check warning on line 57 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:57:35 | 57 | Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?; | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 57 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:57:22 | 57 | Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?; | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

let collection_config = Self::get_collection_config(&collection)?;
ensure!(
Expand All @@ -65,7 +65,6 @@
if let Some(check_origin) = maybe_check_origin {
ensure!(check_origin == details.owner, Error::<T, I>::NoPermission);
}

let now = frame_system::Pallet::<T>::block_number();
let deadline = maybe_deadline.map(|d| d.saturating_add(now));

Expand All @@ -73,16 +72,14 @@
.approvals
.try_insert(delegate.clone(), deadline)
.map_err(|_| Error::<T, I>::ReachedApprovalLimit)?;
Item::<T, I>::insert(&collection, &item, &details);

Check warning on line 75 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:75:37 | 75 | Item::<T, I>::insert(&collection, &item, &details); | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 75 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:75:24 | 75 | Item::<T, I>::insert(&collection, &item, &details); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Self::deposit_event(Event::TransferApproved {
collection,
item,
item: Some(item),
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
owner: details.owner,
delegate,
deadline,
});

Ok(())
}

Expand All @@ -107,7 +104,7 @@
delegate: T::AccountId,
) -> DispatchResult {
let mut details =
Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?;

Check warning on line 107 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:107:35 | 107 | Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?; | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 107 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:107:22 | 107 | Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?; | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

let maybe_deadline = details.approvals.get(&delegate).ok_or(Error::<T, I>::NotDelegate)?;

Expand All @@ -125,11 +122,11 @@
}

details.approvals.remove(&delegate);
Item::<T, I>::insert(&collection, &item, &details);

Check warning on line 125 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:125:37 | 125 | Item::<T, I>::insert(&collection, &item, &details); | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 125 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:125:24 | 125 | Item::<T, I>::insert(&collection, &item, &details); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

chungquantin marked this conversation as resolved.
Show resolved Hide resolved
Self::deposit_event(Event::ApprovalCancelled {
collection,
item,
item: Some(item),
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
owner: details.owner,
delegate,
});
Expand All @@ -156,14 +153,14 @@
item: T::ItemId,
) -> DispatchResult {
let mut details =
Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownCollection)?;

Check warning on line 156 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:156:35 | 156 | Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownCollection)?; | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 156 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:156:22 | 156 | Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownCollection)?; | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

if let Some(check_origin) = maybe_check_origin {
ensure!(check_origin == details.owner, Error::<T, I>::NoPermission);
}

details.approvals.clear();
Item::<T, I>::insert(&collection, &item, &details);

Check warning on line 163 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:163:37 | 163 | Item::<T, I>::insert(&collection, &item, &details); | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 163 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:163:24 | 163 | Item::<T, I>::insert(&collection, &item, &details); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Self::deposit_event(Event::AllApprovalsCancelled {
collection,
Expand All @@ -173,4 +170,102 @@

Ok(())
}

pub(crate) fn do_approve_collection(
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
maybe_check_origin: Option<T::AccountId>,
collection: T::CollectionId,
delegate: T::AccountId,
) -> DispatchResult {
ensure!(
Self::is_pallet_feature_enabled(PalletFeature::Approvals),
Error::<T, I>::MethodDisabled
);
let owner = Self::collection_owner(collection).ok_or(Error::<T, I>::UnknownCollection)?;
chungquantin marked this conversation as resolved.
Show resolved Hide resolved

let collection_config = Self::get_collection_config(&collection)?;
ensure!(
collection_config.is_setting_enabled(CollectionSetting::TransferableItems),
Error::<T, I>::ItemsNonTransferable
);

if let Some(check_origin) = maybe_check_origin {
ensure!(check_origin == owner, Error::<T, I>::NoPermission);
}

Allowances::<T, I>::mutate((&collection, &owner, &delegate), |allowance| {
*allowance = true;
});
Collection::<T, I>::try_mutate(
&collection,

Check warning on line 199 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:199:4 | 199 | &collection, | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
|maybe_collection_details| -> Result<(), DispatchError> {
let collection_details =
maybe_collection_details.as_mut().ok_or(Error::<T, I>::UnknownCollection)?;
collection_details.allowances.saturating_inc();
Ok(())
},
)?;

Self::deposit_event(Event::TransferApproved {
collection,
item: None,
owner,
delegate,
deadline: None,
});
Ok(())
}

pub(crate) fn do_cancel_collection(
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
maybe_check_origin: Option<T::AccountId>,
collection: T::CollectionId,
delegate: T::AccountId,
) -> DispatchResult {
let owner = Self::collection_owner(collection).ok_or(Error::<T, I>::UnknownCollection)?;

if let Some(check_origin) = maybe_check_origin {
ensure!(check_origin == owner, Error::<T, I>::NoPermission);
}
Allowances::<T, I>::remove((&collection, &owner, &delegate));
Collection::<T, I>::try_mutate(
&collection,

Check warning on line 230 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:230:4 | 230 | &collection, | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
|maybe_collection_details| -> Result<(), DispatchError> {
let collection_details =
maybe_collection_details.as_mut().ok_or(Error::<T, I>::UnknownCollection)?;
collection_details.allowances.saturating_dec();
Ok(())
},
)?;

Self::deposit_event(Event::ApprovalCancelled { collection, owner, item: None, delegate });

Ok(())
}

pub fn check_allowance(
collection: &T::CollectionId,
item: &Option<T::ItemId>,
owner: &T::AccountId,
delegate: &T::AccountId,
) -> Result<(), DispatchError> {

Check warning on line 249 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for an associated function

warning: missing documentation for an associated function --> pallets/nfts/src/features/approvals.rs:244:2 | 244 | / pub fn check_allowance( 245 | | collection: &T::CollectionId, 246 | | item: &Option<T::ItemId>, 247 | | owner: &T::AccountId, 248 | | delegate: &T::AccountId, 249 | | ) -> Result<(), DispatchError> { | |__________________________________^
// Check if a `delegate` has a permission to spend the collection.
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
if Allowances::<T, I>::get((&collection, &owner, &delegate)) {
if let Some(item) = item {
Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?;

Check warning on line 253 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:253:36 | 253 | Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?; | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 253 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:253:23 | 253 | Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?; | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
};
return Ok(());
}
// Check if a `delegate` has a permission to spend the collection item.
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
if let Some(item) = item {
let details =
Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?;

Check warning on line 260 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:260:36 | 260 | Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?; | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 260 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/approvals.rs:260:23 | 260 | Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?; | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

let deadline = details.approvals.get(&delegate).ok_or(Error::<T, I>::NoPermission)?;

Check warning on line 262 in pallets/nfts/src/features/approvals.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> pallets/nfts/src/features/approvals.rs:262:41 | 262 | let deadline = details.approvals.get(&delegate).ok_or(Error::<T, I>::NoPermission)?; | ^^^^^^^^^ help: change this to: `delegate` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
if let Some(d) = deadline {
let block_number = frame_system::Pallet::<T>::block_number();
ensure!(block_number <= *d, Error::<T, I>::ApprovalExpired);
}
return Ok(());
};
Err(Error::<T, I>::NoPermission.into())
}
}
12 changes: 12 additions & 0 deletions pallets/nfts/src/features/create_delete_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
items: 0,
item_metadatas: 0,
item_configs: 0,
item_holders: 0,
attributes: 0,
allowances: 0,
},
);
CollectionRoleOf::<T, I>::insert(
Expand All @@ -65,8 +67,8 @@
),
);

CollectionConfigOf::<T, I>::insert(&collection, config);

Check warning on line 70 in pallets/nfts/src/features/create_delete_collection.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_collection.rs:70:38 | 70 | CollectionConfigOf::<T, I>::insert(&collection, config); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
CollectionAccount::<T, I>::insert(&owner, &collection, ());

Check warning on line 71 in pallets/nfts/src/features/create_delete_collection.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_collection.rs:71:45 | 71 | CollectionAccount::<T, I>::insert(&owner, &collection, ()); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Self::deposit_event(event);

Expand Down Expand Up @@ -119,14 +121,19 @@
collection_details.item_configs == witness.item_configs,
Error::<T, I>::BadWitness
);
ensure!(
collection_details.item_holders == witness.item_holders,
Error::<T, I>::BadWitness
);
ensure!(collection_details.allowances == witness.allowances, Error::<T, I>::BadWitness);

for (_, metadata) in ItemMetadataOf::<T, I>::drain_prefix(&collection) {

Check warning on line 130 in pallets/nfts/src/features/create_delete_collection.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_collection.rs:130:62 | 130 | for (_, metadata) in ItemMetadataOf::<T, I>::drain_prefix(&collection) { | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
if let Some(depositor) = metadata.deposit.account {
T::Currency::unreserve(&depositor, metadata.deposit.amount);
}
}

CollectionMetadataOf::<T, I>::remove(&collection);

Check warning on line 136 in pallets/nfts/src/features/create_delete_collection.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_collection.rs:136:41 | 136 | CollectionMetadataOf::<T, I>::remove(&collection); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
Self::clear_roles(&collection)?;

for (_, (_, deposit)) in Attribute::<T, I>::drain_prefix((&collection,)) {
Expand All @@ -137,17 +144,22 @@
}
}

let _ =
AccountBalance::<T, I>::clear_prefix(collection, collection_details.items, None);
let _ = Allowances::<T, I>::clear_prefix((collection,), collection_details.items, None);
CollectionAccount::<T, I>::remove(&collection_details.owner, &collection);

Check warning on line 150 in pallets/nfts/src/features/create_delete_collection.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_collection.rs:150:65 | 150 | CollectionAccount::<T, I>::remove(&collection_details.owner, &collection); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
T::Currency::unreserve(&collection_details.owner, collection_details.owner_deposit);
CollectionConfigOf::<T, I>::remove(&collection);

Check warning on line 152 in pallets/nfts/src/features/create_delete_collection.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_collection.rs:152:39 | 152 | CollectionConfigOf::<T, I>::remove(&collection); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
let _ = ItemConfigOf::<T, I>::clear_prefix(&collection, witness.item_configs, None);

Check warning on line 153 in pallets/nfts/src/features/create_delete_collection.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_collection.rs:153:47 | 153 | let _ = ItemConfigOf::<T, I>::clear_prefix(&collection, witness.item_configs, None); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Self::deposit_event(Event::Destroyed { collection });

Ok(DestroyWitness {
item_metadatas: collection_details.item_metadatas,
item_configs: collection_details.item_configs,
item_holders: collection_details.item_holders,
attributes: collection_details.attributes,
allowances: collection_details.allowances,
})
})
}
Expand Down
16 changes: 16 additions & 0 deletions pallets/nfts/src/features/create_delete_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
ensure!(!Item::<T, I>::contains_key(collection, item), Error::<T, I>::AlreadyExists);

Collection::<T, I>::try_mutate(
&collection,

Check warning on line 59 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:59:4 | 59 | &collection, | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
|maybe_collection_details| -> DispatchResult {
let collection_details =
maybe_collection_details.as_mut().ok_or(Error::<T, I>::UnknownCollection)?;
Expand All @@ -70,6 +70,15 @@

collection_details.items.saturating_inc();

let account_balance =
AccountBalance::<T, I>::mutate(collection, &mint_to, |balance| -> u32 {
balance.saturating_inc();
*balance
});
if account_balance == 1 {
collection_details.item_holders.saturating_inc();
}

let collection_config = Self::get_collection_config(&collection)?;
let deposit_amount = match collection_config
.is_setting_enabled(CollectionSetting::DepositRequired)
Expand All @@ -85,10 +94,10 @@
let item_owner = mint_to.clone();
Account::<T, I>::insert((&item_owner, &collection, &item), ());

if let Ok(existing_config) = ItemConfigOf::<T, I>::try_get(&collection, &item) {

Check warning on line 97 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:97:77 | 97 | if let Ok(existing_config) = ItemConfigOf::<T, I>::try_get(&collection, &item) { | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 97 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:97:64 | 97 | if let Ok(existing_config) = ItemConfigOf::<T, I>::try_get(&collection, &item) { | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
ensure!(existing_config == item_config, Error::<T, I>::InconsistentItemConfig);
} else {
ItemConfigOf::<T, I>::insert(&collection, &item, item_config);

Check warning on line 100 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:100:48 | 100 | ItemConfigOf::<T, I>::insert(&collection, &item, item_config); | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 100 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:100:35 | 100 | ItemConfigOf::<T, I>::insert(&collection, &item, item_config); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
collection_details.item_configs.saturating_inc();
}

Expand All @@ -100,7 +109,7 @@
approvals: ApprovalsOf::<T, I>::default(),
deposit,
};
Item::<T, I>::insert(&collection, &item, details);

Check warning on line 112 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:112:39 | 112 | Item::<T, I>::insert(&collection, &item, details); | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 112 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:112:26 | 112 | Item::<T, I>::insert(&collection, &item, details); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
Ok(())
},
)?;
Expand Down Expand Up @@ -221,11 +230,11 @@
// then we keep the config record and don't remove it
let remove_config = !item_config.has_disabled_settings();
let owner = Collection::<T, I>::try_mutate(
&collection,

Check warning on line 233 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:233:4 | 233 | &collection, | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
|maybe_collection_details| -> Result<T::AccountId, DispatchError> {
let collection_details =
maybe_collection_details.as_mut().ok_or(Error::<T, I>::UnknownCollection)?;
let details = Item::<T, I>::get(&collection, &item)

Check warning on line 237 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:237:50 | 237 | let details = Item::<T, I>::get(&collection, &item) | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 237 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:237:37 | 237 | let details = Item::<T, I>::get(&collection, &item) | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
.ok_or(Error::<T, I>::UnknownCollection)?;
with_details(&details)?;

Expand All @@ -239,7 +248,7 @@

// Clear the metadata if it's not locked.
if item_config.is_setting_enabled(ItemSetting::UnlockedMetadata) {
if let Some(metadata) = ItemMetadataOf::<T, I>::take(&collection, &item) {

Check warning on line 251 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:251:72 | 251 | if let Some(metadata) = ItemMetadataOf::<T, I>::take(&collection, &item) { | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 251 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:251:59 | 251 | if let Some(metadata) = ItemMetadataOf::<T, I>::take(&collection, &item) { | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
let depositor_account =
metadata.deposit.account.unwrap_or(collection_details.owner.clone());

Expand All @@ -254,18 +263,25 @@
}
}

if AccountBalance::<T, I>::get(collection, &details.owner) == 1 {
collection_details.item_holders.saturating_dec();
}

Ok(details.owner)
},
)?;

Item::<T, I>::remove(&collection, &item);

Check warning on line 274 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:274:37 | 274 | Item::<T, I>::remove(&collection, &item); | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 274 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:274:24 | 274 | Item::<T, I>::remove(&collection, &item); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
Account::<T, I>::remove((&owner, &collection, &item));
ItemPriceOf::<T, I>::remove(&collection, &item);

Check warning on line 276 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:276:44 | 276 | ItemPriceOf::<T, I>::remove(&collection, &item); | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 276 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:276:31 | 276 | ItemPriceOf::<T, I>::remove(&collection, &item); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
PendingSwapOf::<T, I>::remove(&collection, &item);

Check warning on line 277 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:277:46 | 277 | PendingSwapOf::<T, I>::remove(&collection, &item); | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 277 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:277:33 | 277 | PendingSwapOf::<T, I>::remove(&collection, &item); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
ItemAttributesApprovalsOf::<T, I>::remove(&collection, &item);

Check warning on line 278 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:278:58 | 278 | ItemAttributesApprovalsOf::<T, I>::remove(&collection, &item); | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 278 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:278:45 | 278 | ItemAttributesApprovalsOf::<T, I>::remove(&collection, &item); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
AccountBalance::<T, I>::mutate(collection, &owner, |balance| {
balance.saturating_dec();
});

if remove_config {
ItemConfigOf::<T, I>::remove(&collection, &item);

Check warning on line 284 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:284:46 | 284 | ItemConfigOf::<T, I>::remove(&collection, &item); | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Check warning on line 284 in pallets/nfts/src/features/create_delete_item.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/nfts/src/features/create_delete_item.rs:284:33 | 284 | ItemConfigOf::<T, I>::remove(&collection, &item); | ^^^^^^^^^^^ help: change this to: `collection` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
}

Self::deposit_event(Event::Burned { collection, item, owner });
Expand Down
Loading
Loading