Skip to content

Commit 2ae1086

Browse files
committed
update types, add a new action for permissions, update comments and delete rebundant ones
1 parent 2869c3f commit 2ae1086

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

pallets/fruniques/src/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<T: Config> Pallet<T> {
7777
}
7878

7979
pub fn do_initial_setup() -> DispatchResult {
80-
let pallet_id = Self::pallet_id();
80+
let _pallet_id = Self::pallet_id();
8181

8282
Ok(())
8383
}

pallets/fruniques/src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ pub mod pallet {
116116
pub(super) type FruniqueChild<T: Config> = StorageDoubleMap<
117117
_,
118118
Blake2_128Concat,
119-
CollectionId,
119+
CollectionId, // Parent collection id
120120
Blake2_128Concat,
121-
ItemId, // FruniqueId
122-
Option<HierarchicalInfo>, // ParentId and flag if it inherit attributes
121+
ItemId, // Parent item id
122+
Option<ChildInfo>, // ParentId and flag if it inherit attributes
123123
ValueQuery,
124124
>;
125125

@@ -257,14 +257,20 @@ pub mod pallet {
257257
instance_id,
258258
));
259259

260+
260261
if let Some(parent_info) = parent_info {
261-
// ! check if parent exists
262262
ensure!(
263263
Self::item_exists(&class_id, &parent_info.0),
264264
<Error<T>>::CollectionNotFound
265265
);
266266
<FruniqueParent<T>>::insert(class_id, instance_id, Some(parent_info));
267-
// Self::do_hierarchical_division(origin.clone(), class_id, instance_id, parent_info)?;
267+
268+
// let child_info = ChildInfo {
269+
// collection_id: class_id,
270+
// child_id: instance_id,
271+
// is_hierarchical: parent_info.1,
272+
// weight: numeric_value.unwrap()
273+
// }
268274
}
269275

270276
Ok(())

pallets/fruniques/src/types.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ use super::*;
33
use frame_support::pallet_prelude::*;
44

55
use frame_support::sp_io::hashing::blake2_256;
6+
use sp_runtime::Permill;
67
use sp_runtime::sp_std::vec::Vec;
78

89
pub type AttributeKey<T> = BoundedVec<u8, <T as pallet_uniques::Config>::KeyLimit>;
910
pub type AttributeValue<T> = BoundedVec<u8, <T as pallet_uniques::Config>::ValueLimit>;
1011
pub type Attributes<T> = Vec<(AttributeKey<T>, AttributeValue<T>)>;
1112

12-
pub type CollectionDescription = [u8;32];
13+
pub type CollectionDescription = [u8; 32];
1314
pub type StringLimit<T> = BoundedVec<u8, <T as pallet_uniques::Config>::StringLimit>;
1415

1516
pub type CollectionId = u32;
@@ -18,21 +19,19 @@ pub type ItemId = u32;
1819
pub type HierarchicalInfo = (ItemId, bool);
1920

2021
#[derive(CloneNoBound, Encode, Decode, RuntimeDebugNoBound, Default, TypeInfo, MaxEncodedLen)]
21-
pub struct FruniqueChild {
22-
pub child_id: ItemId,
22+
pub struct ChildInfo {
2323
pub collection_id: CollectionId,
24+
pub child_id: ItemId,
2425
pub is_hierarchical: bool,
25-
pub weight: u32,
26+
pub weight: Permill,
2627
}
2728

28-
pub type ChildrenInfo = BoundedVec<FruniqueChild, T::ChildMaxLen>;
29-
3029
#[derive(CloneNoBound, Encode, Decode, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)]
3130
#[scale_info(skip_type_params(T))]
3231
#[codec(mel_bound())]
33-
pub struct FruniqueInheritance {
32+
pub struct FruniqueInheritance<T: Config> {
3433
pub parent: (CollectionId, ItemId),
35-
pub children: ChildrenInfo,
34+
pub children: BoundedVec<ChildInfo, T::ChildMaxLen>,
3635
}
3736

3837
#[derive(
@@ -84,6 +83,8 @@ pub enum Permission {
8483
Mint,
8584
/// Authorization required and must be approved by a holder / collector
8685
Transfer,
86+
/// Allow a user to collaborate on a collection
87+
Collaborate,
8788
}
8889

8990
impl Permission {
@@ -93,33 +94,40 @@ impl Permission {
9394
Self::Required => "Required".as_bytes().to_vec(),
9495
Self::Mint => "Mint".as_bytes().to_vec(),
9596
Self::Transfer => "Transfer".as_bytes().to_vec(),
97+
Self::Collaborate => "Collaborate".as_bytes().to_vec(),
9698
}
9799
}
98100

99101
pub fn id(&self) -> [u8; 32] {
100102
self.to_vec().using_encoded(blake2_256)
101103
}
102104

105+
pub fn owner_permissions() -> Vec<Vec<u8>> {
106+
use crate::types::Permission::*;
107+
[None.to_vec(), Required.to_vec(), Mint.to_vec(), Transfer.to_vec()].to_vec()
108+
}
109+
103110
pub fn admin_permissions() -> Vec<Vec<u8>> {
104111
use crate::types::Permission::*;
105112
let mut admin_permissions = [
106113
None.to_vec(),
107114
Required.to_vec(),
108115
Mint.to_vec(),
109116
Transfer.to_vec(),
117+
Collaborate.to_vec(),
110118
]
111119
.to_vec();
112120
admin_permissions.append(&mut Permission::holder_permissions());
113121
admin_permissions
114122
}
115123

124+
pub fn collaborator_permissions() -> Vec<Vec<u8>> {
125+
use crate::types::Permission::*;
126+
[Mint.to_vec()].to_vec()
127+
}
128+
116129
pub fn holder_permissions() -> Vec<Vec<u8>> {
117130
use crate::types::Permission::*;
118-
[
119-
None.to_vec(),
120-
Required.to_vec(),
121-
Transfer.to_vec(),
122-
]
123-
.to_vec()
131+
[None.to_vec(), Required.to_vec(), Transfer.to_vec()].to_vec()
124132
}
125133
}

0 commit comments

Comments
 (0)