Skip to content

Commit ce6abd1

Browse files
committed
develop storage maps to Fix #8
Update information to sign transactions as sudo Also develop a new spawn method in order to Fix #93 udpate some warning errors update new storage maps to Fix #128 Still missing some division algothims to define different ways to store the value of a NFT and adding RBAC pallet to allow the admin of a collection to let users mint on his collection
1 parent a92225b commit ce6abd1

File tree

9 files changed

+444
-256
lines changed

9 files changed

+444
-256
lines changed

pallets/fruniques/src/functions.rs

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use super::*;
22

3-
use frame_support::traits::tokens::nonfungibles::Inspect;
43
use frame_system::pallet_prelude::*;
4+
use crate::types::*;
5+
6+
use frame_support::traits::tokens::nonfungibles::Inspect;
57
use scale_info::prelude::string::String;
6-
// use crate::types::*;
8+
79
use frame_support::pallet_prelude::*;
810
use sp_runtime::{sp_std::vec::Vec, Permill};
911

@@ -15,6 +17,13 @@ impl<T: Config> Pallet<T> {
1517
T::ItemId::from(input)
1618
}
1719

20+
pub fn u32_to_class_id(input: u32) -> T::CollectionId
21+
where
22+
<T as pallet_uniques::Config>::CollectionId: From<u32>,
23+
{
24+
T::CollectionId::from(input)
25+
}
26+
1827
pub fn bytes_to_u32(input: Vec<u8>) -> u32 {
1928
u32::from_ne_bytes(input.try_into().unwrap())
2029
}
@@ -87,8 +96,6 @@ impl<T: Config> Pallet<T> {
8796
Ok(())
8897
}
8998

90-
// TODO: add a function to get the owner of an instance
91-
// TODO: add a function to burn an instance
9299
pub fn burn(
93100
origin: OriginFor<T>,
94101
class_id: &T::CollectionId,
@@ -106,10 +113,13 @@ impl<T: Config> Pallet<T> {
106113
Ok(())
107114
}
108115

116+
117+
/// Helper function to create a new collection
118+
/// Creates a collection and updates its metadata if needed.
109119
pub fn do_create_collection(
110120
origin: OriginFor<T>,
111121
class_id: T::CollectionId,
112-
metadata: BoundedVec<u8, T::StringLimit>,
122+
metadata: Option<StringLimit<T>>,
113123
admin: <T::Lookup as sp_runtime::traits::StaticLookup>::Source,
114124
) -> DispatchResult {
115125
pallet_uniques::Pallet::<T>::create(
@@ -118,12 +128,14 @@ impl<T: Config> Pallet<T> {
118128
admin,
119129
)?;
120130

121-
pallet_uniques::Pallet::<T>::set_collection_metadata(
131+
if let Some(metadata) = metadata {
132+
pallet_uniques::Pallet::<T>::set_collection_metadata(
122133
origin,
123134
class_id,
124135
metadata,
125136
false
126-
)?;
137+
)?;
138+
}
127139

128140
Ok(())
129141
}
@@ -157,7 +169,40 @@ impl<T: Config> Pallet<T> {
157169
Ok(())
158170
}
159171

160-
pub fn do_spawn() -> DispatchResult {
172+
pub fn do_spawn(
173+
origin: OriginFor<T>,
174+
collection: T::CollectionId,
175+
item: T::ItemId,
176+
owner: <T::Lookup as sp_runtime::traits::StaticLookup>::Source,
177+
_numeric_value: Option<Permill>,
178+
attributes: Option<Vec<(BoundedVec<u8, T::KeyLimit>, BoundedVec<u8, T::ValueLimit>)>>,
179+
) -> DispatchResult {
180+
181+
pallet_uniques::Pallet::<T>::mint(
182+
origin.clone(),
183+
collection,
184+
item,
185+
owner
186+
)?;
187+
188+
if let Some(attributes) = attributes {
189+
for (key, value) in attributes {
190+
pallet_uniques::Pallet::<T>::set_attribute(
191+
origin.clone(),
192+
collection,
193+
Some(item),
194+
key,
195+
value,
196+
)?;
197+
}
198+
}
199+
// let instance_id: T::ItemId = Self::u32_to_instance_id(input);
200+
201+
// pallet_uniques::Pallet::<T>::mint(origin,
202+
// Self::u32_to_class_id(class_id),
203+
// Self::u32_to_instance_id(instance_id),
204+
// owner)?;
205+
161206
Ok(())
162207
}
163208
}

0 commit comments

Comments
 (0)