Skip to content

Commit 711e290

Browse files
committed
🚀 chore(Cargo.toml): update dependencies versions to improve compatibility and performance
🐛 fix(functions.rs): fix cloning of class_id variable to prevent ownership issues ✨ feat(functions.rs): add support for creating frunique collections with configurable owner and admin roles 🐛 fix(functions.rs): fix cloning of collection variable to prevent ownership issues
1 parent 5e443de commit 711e290

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

pallets/fruniques/Cargo.toml

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ repository = "https://github.com/hashed-io/hashed-pallets"
1313
targets = ["x86_64-unknown-linux-gnu"]
1414

1515
[dependencies]
16-
log = "0.4"
16+
log = { version = "0.4.17", default-features = false }
1717
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false }
18-
scale-info = { default-features = false, version = "2.0.1", features = [
18+
scale-info = { default-features = false, version = "2.5.0", features = [
1919
"derive"
2020
] }
21-
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
22-
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
23-
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0", optional = true }
24-
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
25-
pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
21+
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
22+
frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
23+
frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0", optional = true }
24+
sp-runtime = { version = "24.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
25+
pallet-uniques = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
2626
pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
2727
pallet-rbac = { path = "../rbac/", default-features = false, version = "4.0.0-dev" }
2828

2929
[dev-dependencies]
30-
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
31-
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
30+
sp-core = { version = "21.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
31+
sp-io = { version = "23.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
3232

3333
[features]
3434
default = ["std"]

pallets/fruniques/src/functions.rs

+25-16
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<T: Config> Pallet<T> {
164164
) -> DispatchResult {
165165
pallet_uniques::Pallet::<T>::set_attribute(
166166
origin,
167-
*class_id,
167+
*class_id.clone(),
168168
Some(instance_id),
169169
key,
170170
value,
@@ -182,15 +182,15 @@ impl<T: Config> Pallet<T> {
182182
where
183183
<T as pallet_uniques::Config>::ItemId: From<u32>,
184184
{
185-
let nex_item: ItemId = <NextFrunique<T>>::try_get(collection).unwrap_or(0);
186-
<NextFrunique<T>>::insert(collection, nex_item + 1);
185+
let nex_item: ItemId = <NextFrunique<T>>::try_get(collection.clone()).unwrap_or(0);
186+
<NextFrunique<T>>::insert(collection.clone(), nex_item + 1);
187187

188188
let item = Self::u32_to_instance_id(nex_item);
189-
pallet_uniques::Pallet::<T>::do_mint(collection, item, owner, |_| Ok(()))?;
189+
pallet_uniques::Pallet::<T>::do_mint(collection.clone(), item, owner, |_| Ok(()))?;
190190

191191
pallet_uniques::Pallet::<T>::set_metadata(
192192
frame_system::RawOrigin::Root.into(),
193-
collection,
193+
collection.clone(),
194194
item.clone(),
195195
metadata,
196196
false,
@@ -200,7 +200,7 @@ impl<T: Config> Pallet<T> {
200200
for (key, value) in attributes {
201201
pallet_uniques::Pallet::<T>::set_attribute(
202202
frame_system::RawOrigin::Root.into(),
203-
collection,
203+
collection.clone(),
204204
Some(item),
205205
key,
206206
value,
@@ -272,15 +272,23 @@ impl<T: Config> Pallet<T> {
272272
let scope_id = class_id.using_encoded(blake2_256);
273273
T::Rbac::create_scope(Self::pallet_id(), scope_id)?;
274274

275-
Self::insert_auth_in_frunique_collection(owner.clone(), class_id, FruniqueRole::Owner)?;
275+
Self::insert_auth_in_frunique_collection(
276+
owner.clone(),
277+
class_id.clone(),
278+
FruniqueRole::Owner,
279+
)?;
276280

277281
pallet_uniques::Pallet::<T>::do_create_collection(
278-
class_id,
282+
class_id.clone(),
279283
owner.clone(),
280284
admin.clone(),
281285
T::CollectionDeposit::get(),
282286
false,
283-
pallet_uniques::Event::Created { collection: class_id, creator: admin.clone(), owner },
287+
pallet_uniques::Event::Created {
288+
collection: class_id.clone(),
289+
creator: admin.clone(),
290+
owner,
291+
},
284292
)?;
285293

286294
pallet_uniques::Pallet::<T>::set_collection_metadata(
@@ -308,13 +316,13 @@ impl<T: Config> Pallet<T> {
308316
{
309317
ensure!(Self::collection_exists(&collection), Error::<T>::CollectionNotFound);
310318

311-
let nex_item: ItemId = <NextFrunique<T>>::try_get(collection).unwrap_or(0);
319+
let nex_item: ItemId = <NextFrunique<T>>::try_get(collection.clone()).unwrap_or(0);
312320
let item = Self::u32_to_instance_id(nex_item);
313321

314-
Self::do_mint(collection, owner.clone(), metadata.clone(), attributes)?;
322+
Self::do_mint(collection.clone(), owner.clone(), metadata.clone(), attributes)?;
315323

316324
if let Some(ref parent_info) = parent_info {
317-
return Self::do_nft_division(collection, item, metadata, parent_info, owner)
325+
return Self::do_nft_division(collection.clone(), item, metadata, parent_info, owner)
318326
}
319327

320328
let frunique_data = FruniqueData {
@@ -329,7 +337,7 @@ impl<T: Config> Pallet<T> {
329337
verified_by: None,
330338
};
331339

332-
<FruniqueInfo<T>>::insert(collection, item, frunique_data);
340+
<FruniqueInfo<T>>::insert(collection.clone(), item, frunique_data);
333341
<FruniqueRoots<T>>::insert(collection, item, true);
334342

335343
Ok(())
@@ -382,7 +390,7 @@ impl<T: Config> Pallet<T> {
382390
verified_by: None,
383391
};
384392

385-
<FruniqueInfo<T>>::insert(collection, item, frunique_data);
393+
<FruniqueInfo<T>>::insert(collection.clone(), item, frunique_data);
386394

387395
let frunique_child: ChildInfo<T> = ChildInfo {
388396
collection_id: collection,
@@ -422,13 +430,14 @@ impl<T: Config> Pallet<T> {
422430
ensure!(Self::collection_exists(&collection), Error::<T>::CollectionNotFound);
423431
ensure!(Self::instance_exists(&collection, &item), Error::<T>::FruniqueNotFound);
424432

425-
let frunique_data: FruniqueData<T> = <FruniqueInfo<T>>::try_get(collection, item).unwrap();
433+
let frunique_data: FruniqueData<T> =
434+
<FruniqueInfo<T>>::try_get(collection.clone(), item).unwrap();
426435

427436
ensure!(!frunique_data.frozen, Error::<T>::FruniqueFrozen);
428437
ensure!(!frunique_data.redeemed, Error::<T>::FruniqueAlreadyRedeemed);
429438

430439
<FruniqueInfo<T>>::try_mutate::<_, _, _, DispatchError, _>(
431-
collection,
440+
collection.clone(),
432441
item,
433442
|frunique_data| -> DispatchResult {
434443
let frunique = frunique_data.as_mut().ok_or(Error::<T>::FruniqueNotFound)?;

0 commit comments

Comments
 (0)