Skip to content

Commit f72d868

Browse files
authored
Merge pull request #227 from hashed-io/fruniques/update_types
add call to delete storage map
2 parents 748d5f1 + d644165 commit f72d868

File tree

12 files changed

+537
-313
lines changed

12 files changed

+537
-313
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ gcloud-md5-ingress.yml
3030

3131
.secrets
3232
collator-data
33-
relay-data
33+
relay-data
34+
.vscode/settings.json

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"cSpell.words": [
3+
"Frunique",
4+
"fruniques",
5+
"Permill"
6+
]
7+
}

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pallets/fruniques/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ sp-runtime ={ default-features = false, version = "6.0.0", git = "https://github
2626
pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" }
2727
pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" }
2828

29+
pallet-rbac = { path="../rbac/", default-features = false, version = "4.0.0-dev"}
30+
2931
[dev-dependencies]
3032
sp-core = { default-features = false, version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" }
3133
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" }

pallets/fruniques/src/functions.rs

Lines changed: 99 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
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+
9+
use pallet_rbac::types::*;
10+
711
use frame_support::pallet_prelude::*;
812
use sp_runtime::{sp_std::vec::Vec, Permill};
913

@@ -15,6 +19,13 @@ impl<T: Config> Pallet<T> {
1519
T::ItemId::from(input)
1620
}
1721

22+
pub fn u32_to_class_id(input: u32) -> T::CollectionId
23+
where
24+
<T as pallet_uniques::Config>::CollectionId: From<u32>,
25+
{
26+
T::CollectionId::from(input)
27+
}
28+
1829
pub fn bytes_to_u32(input: Vec<u8>) -> u32 {
1930
u32::from_ne_bytes(input.try_into().unwrap())
2031
}
@@ -39,7 +50,7 @@ impl<T: Config> Pallet<T> {
3950
class_id: &T::CollectionId,
4051
instance_id: &T::ItemId,
4152
key: &Vec<u8>,
42-
) -> BoundedVec<u8, T::ValueLimit> {
53+
) -> AttributeValue<T> {
4354
if let Some(a) = pallet_uniques::Pallet::<T>::attribute(class_id, instance_id, key) {
4455
return BoundedVec::<u8, T::ValueLimit>::try_from(a)
4556
.expect("Error on converting the attribute to BoundedVec");
@@ -51,12 +62,32 @@ impl<T: Config> Pallet<T> {
5162
pallet_uniques::Pallet::<T>::owner(*class_id, *instance_id)
5263
}
5364

65+
pub fn collection_exists(class_id: &T::CollectionId) -> bool {
66+
if let Some(_owner) = pallet_uniques::Pallet::<T>::collection_owner(*class_id) {
67+
return true;
68+
}
69+
false
70+
}
71+
72+
pub fn item_exists(class_id: &T::CollectionId, instance_id: &T::ItemId) -> bool {
73+
if let Some(_owner) = pallet_uniques::Pallet::<T>::owner(*class_id, *instance_id) {
74+
return true;
75+
}
76+
false
77+
}
78+
79+
pub fn do_initial_setup() -> DispatchResult {
80+
let _pallet_id = Self::pallet_id();
81+
82+
Ok(())
83+
}
84+
5485
pub fn set_attribute(
5586
origin: OriginFor<T>,
5687
class_id: &T::CollectionId,
5788
instance_id: T::ItemId,
58-
key: BoundedVec<u8, T::KeyLimit>,
59-
value: BoundedVec<u8, T::ValueLimit>,
89+
key: AttributeKey<T>,
90+
value: AttributeValue<T>,
6091
) -> DispatchResult {
6192
pallet_uniques::Pallet::<T>::set_attribute(
6293
origin,
@@ -87,8 +118,6 @@ impl<T: Config> Pallet<T> {
87118
Ok(())
88119
}
89120

90-
// TODO: add a function to get the owner of an instance
91-
// TODO: add a function to burn an instance
92121
pub fn burn(
93122
origin: OriginFor<T>,
94123
class_id: &T::CollectionId,
@@ -106,6 +135,33 @@ impl<T: Config> Pallet<T> {
106135
Ok(())
107136
}
108137

138+
139+
/// Helper function to create a new collection
140+
/// Creates a collection and updates its metadata if needed.
141+
pub fn do_create_collection(
142+
origin: OriginFor<T>,
143+
class_id: T::CollectionId,
144+
metadata: Option<StringLimit<T>>,
145+
admin: <T::Lookup as sp_runtime::traits::StaticLookup>::Source,
146+
) -> DispatchResult {
147+
pallet_uniques::Pallet::<T>::create(
148+
origin.clone(),
149+
class_id,
150+
admin,
151+
)?;
152+
153+
if let Some(metadata) = metadata {
154+
pallet_uniques::Pallet::<T>::set_collection_metadata(
155+
origin,
156+
class_id,
157+
metadata,
158+
false
159+
)?;
160+
}
161+
162+
Ok(())
163+
}
164+
109165
// TODO: add a function to transfer an instance
110166
pub fn do_create(
111167
origin: OriginFor<T>,
@@ -135,7 +191,42 @@ impl<T: Config> Pallet<T> {
135191
Ok(())
136192
}
137193

138-
pub fn do_spawn() -> DispatchResult {
194+
pub fn do_spawn(
195+
origin: OriginFor<T>,
196+
collection: T::CollectionId,
197+
item: T::ItemId,
198+
owner: <T::Lookup as sp_runtime::traits::StaticLookup>::Source,
199+
_numeric_value: Option<Permill>,
200+
attributes: Option<Vec<(BoundedVec<u8, T::KeyLimit>, BoundedVec<u8, T::ValueLimit>)>>,
201+
) -> DispatchResult {
202+
203+
ensure!(Self::collection_exists(&collection), <Error<T>>::CollectionNotFound);
204+
pallet_uniques::Pallet::<T>::mint(
205+
origin.clone(),
206+
collection,
207+
item,
208+
owner
209+
)?;
210+
211+
if let Some(attributes) = attributes {
212+
for (key, value) in attributes {
213+
pallet_uniques::Pallet::<T>::set_attribute(
214+
origin.clone(),
215+
collection,
216+
Some(item),
217+
key,
218+
value,
219+
)?;
220+
}
221+
}
222+
139223
Ok(())
140224
}
225+
226+
pub fn pallet_id()->IdOrVec{
227+
IdOrVec::Vec(
228+
Self::module_name().as_bytes().to_vec()
229+
)
230+
}
231+
141232
}

0 commit comments

Comments
 (0)