difftreelog
Merge branch 'feature/pallet-structure-rebased' of https://github.com/UniqueNetwork/unique-chain into feature/pallet-structure-rebased
in: master
16 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -59,6 +59,7 @@
Properties,
PropertiesPermissionMap,
PropertyKey,
+ PropertyValue,
PropertyPermission,
PropertiesError,
PropertyKeyPermission,
@@ -902,6 +903,12 @@
Ok(())
}
+ pub fn get_collection_property(collection_id: CollectionId, key: &PropertyKey) -> Option<PropertyValue> {
+ Self::collection_properties(collection_id)
+ .get(key)
+ .cloned()
+ }
+
pub fn bytes_keys_to_property_keys(
keys: Vec<Vec<u8>>,
) -> Result<Vec<PropertyKey>, DispatchError> {
@@ -1240,6 +1247,7 @@
fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId>;
fn const_metadata(&self, token: TokenId) -> Vec<u8>;
+ fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue>;
fn token_properties(&self, token_id: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property>;
/// Amount of unique collection tokens
fn total_supply(&self) -> u32;
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -21,7 +21,7 @@
use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
use sp_runtime::ArithmeticError;
use sp_std::{vec::Vec, vec};
-use up_data_structs::{Property, PropertyKey, PropertyKeyPermission};
+use up_data_structs::{Property, PropertyKey, PropertyValue, PropertyKeyPermission};
use crate::{
Allowance, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf, weights::WeightInfo,
@@ -319,6 +319,10 @@
Vec::new()
}
+ fn token_property(&self, _token_id: TokenId, _key: &PropertyKey) -> Option<PropertyValue> {
+ None
+ }
+
fn token_properties(
&self,
_token_id: TokenId,
pallets/nonfungible/src/common.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use core::marker::PhantomData;1819use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight};20use up_data_structs::{21 TokenId, CreateItemExData, CollectionId, budget::Budget, Property, PropertyKey,22 PropertyKeyPermission,23};24use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};25use sp_runtime::DispatchError;26use sp_std::vec::Vec;2728use crate::{29 AccountBalance, Allowance, Config, CreateItemData, Error, NonfungibleHandle, Owned, Pallet,30 SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,31};3233pub struct CommonWeights<T: Config>(PhantomData<T>);34impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {35 fn create_item() -> Weight {36 <SelfWeightOf<T>>::create_item()37 }3839 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {40 match data {41 CreateItemExData::NFT(t) => <SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32),42 _ => 0,43 }44 }4546 fn create_multiple_items(amount: u32) -> Weight {47 <SelfWeightOf<T>>::create_multiple_items(amount)48 }4950 fn burn_item() -> Weight {51 <SelfWeightOf<T>>::burn_item()52 }5354 fn set_collection_properties(amount: u32) -> Weight {55 <SelfWeightOf<T>>::set_collection_properties(amount)56 }5758 fn delete_collection_properties(amount: u32) -> Weight {59 <SelfWeightOf<T>>::delete_collection_properties(amount)60 }6162 fn set_token_properties(amount: u32) -> Weight {63 <SelfWeightOf<T>>::set_token_properties(amount)64 }6566 fn delete_token_properties(amount: u32) -> Weight {67 <SelfWeightOf<T>>::delete_token_properties(amount)68 }6970 fn set_property_permissions(amount: u32) -> Weight {71 <SelfWeightOf<T>>::set_property_permissions(amount)72 }7374 fn transfer() -> Weight {75 <SelfWeightOf<T>>::transfer()76 }7778 fn approve() -> Weight {79 <SelfWeightOf<T>>::approve()80 }8182 fn transfer_from() -> Weight {83 <SelfWeightOf<T>>::transfer_from()84 }8586 fn burn_from() -> Weight {87 <SelfWeightOf<T>>::burn_from()88 }89}9091fn map_create_data<T: Config>(92 data: up_data_structs::CreateItemData,93 to: &T::CrossAccountId,94) -> Result<CreateItemData<T>, DispatchError> {95 match data {96 up_data_structs::CreateItemData::NFT(data) => Ok(CreateItemData::<T> {97 const_data: data.const_data,98 properties: data.properties,99 owner: to.clone(),100 }),101 _ => fail!(<Error<T>>::NotNonfungibleDataUsedToMintFungibleCollectionToken),102 }103}104105impl<T: Config> CommonCollectionOperations<T> for NonfungibleHandle<T> {106 fn create_item(107 &self,108 sender: T::CrossAccountId,109 to: T::CrossAccountId,110 data: up_data_structs::CreateItemData,111 nesting_budget: &dyn Budget,112 ) -> DispatchResultWithPostInfo {113 with_weight(114 <Pallet<T>>::create_item(115 self,116 &sender,117 map_create_data::<T>(data, &to)?,118 nesting_budget,119 ),120 <CommonWeights<T>>::create_item(),121 )122 }123124 fn create_multiple_items(125 &self,126 sender: T::CrossAccountId,127 to: T::CrossAccountId,128 data: Vec<up_data_structs::CreateItemData>,129 nesting_budget: &dyn Budget,130 ) -> DispatchResultWithPostInfo {131 let data = data132 .into_iter()133 .map(|d| map_create_data::<T>(d, &to))134 .collect::<Result<Vec<_>, DispatchError>>()?;135136 let amount = data.len();137 with_weight(138 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),139 <CommonWeights<T>>::create_multiple_items(amount as u32),140 )141 }142143 fn create_multiple_items_ex(144 &self,145 sender: <T>::CrossAccountId,146 data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,147 nesting_budget: &dyn Budget,148 ) -> DispatchResultWithPostInfo {149 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);150 let data = match data {151 up_data_structs::CreateItemExData::NFT(nft) => nft,152 _ => fail!(Error::<T>::NotNonfungibleDataUsedToMintFungibleCollectionToken),153 };154155 with_weight(156 <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner(), nesting_budget),157 weight,158 )159 }160161 fn set_collection_properties(162 &self,163 sender: T::CrossAccountId,164 properties: Vec<Property>,165 ) -> DispatchResultWithPostInfo {166 let weight = <CommonWeights<T>>::set_collection_properties(properties.len() as u32);167168 with_weight(169 <Pallet<T>>::set_collection_properties(self, &sender, properties),170 weight,171 )172 }173174 fn delete_collection_properties(175 &self,176 sender: &T::CrossAccountId,177 property_keys: Vec<PropertyKey>,178 ) -> DispatchResultWithPostInfo {179 let weight = <CommonWeights<T>>::delete_collection_properties(property_keys.len() as u32);180181 with_weight(182 <Pallet<T>>::delete_collection_properties(self, sender, property_keys),183 weight,184 )185 }186187 fn set_token_properties(188 &self,189 sender: T::CrossAccountId,190 token_id: TokenId,191 properties: Vec<Property>,192 ) -> DispatchResultWithPostInfo {193 let weight = <CommonWeights<T>>::set_token_properties(properties.len() as u32);194195 with_weight(196 <Pallet<T>>::set_token_properties(self, &sender, token_id, properties),197 weight,198 )199 }200201 fn delete_token_properties(202 &self,203 sender: T::CrossAccountId,204 token_id: TokenId,205 property_keys: Vec<PropertyKey>,206 ) -> DispatchResultWithPostInfo {207 let weight = <CommonWeights<T>>::delete_token_properties(property_keys.len() as u32);208209 with_weight(210 <Pallet<T>>::delete_token_properties(self, &sender, token_id, property_keys),211 weight,212 )213 }214215 fn set_property_permissions(216 &self,217 sender: &T::CrossAccountId,218 property_permissions: Vec<PropertyKeyPermission>,219 ) -> DispatchResultWithPostInfo {220 let weight =221 <CommonWeights<T>>::set_property_permissions(property_permissions.len() as u32);222223 with_weight(224 <Pallet<T>>::set_property_permissions(self, sender, property_permissions),225 weight,226 )227 }228229 fn burn_item(230 &self,231 sender: T::CrossAccountId,232 token: TokenId,233 amount: u128,234 ) -> DispatchResultWithPostInfo {235 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);236 if amount == 1 {237 with_weight(238 <Pallet<T>>::burn(self, &sender, token),239 <CommonWeights<T>>::burn_item(),240 )241 } else {242 Ok(().into())243 }244 }245246 fn transfer(247 &self,248 from: T::CrossAccountId,249 to: T::CrossAccountId,250 token: TokenId,251 amount: u128,252 nesting_budget: &dyn Budget,253 ) -> DispatchResultWithPostInfo {254 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);255 if amount == 1 {256 with_weight(257 <Pallet<T>>::transfer(self, &from, &to, token, nesting_budget),258 <CommonWeights<T>>::transfer(),259 )260 } else {261 Ok(().into())262 }263 }264265 fn approve(266 &self,267 sender: T::CrossAccountId,268 spender: T::CrossAccountId,269 token: TokenId,270 amount: u128,271 ) -> DispatchResultWithPostInfo {272 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);273274 with_weight(275 if amount == 1 {276 <Pallet<T>>::set_allowance(self, &sender, token, Some(&spender))277 } else {278 <Pallet<T>>::set_allowance(self, &sender, token, None)279 },280 <CommonWeights<T>>::approve(),281 )282 }283284 fn transfer_from(285 &self,286 sender: T::CrossAccountId,287 from: T::CrossAccountId,288 to: T::CrossAccountId,289 token: TokenId,290 amount: u128,291 nesting_budget: &dyn Budget,292 ) -> DispatchResultWithPostInfo {293 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);294295 if amount == 1 {296 with_weight(297 <Pallet<T>>::transfer_from(self, &sender, &from, &to, token, nesting_budget),298 <CommonWeights<T>>::transfer_from(),299 )300 } else {301 Ok(().into())302 }303 }304305 fn burn_from(306 &self,307 sender: T::CrossAccountId,308 from: T::CrossAccountId,309 token: TokenId,310 amount: u128,311 nesting_budget: &dyn Budget,312 ) -> DispatchResultWithPostInfo {313 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);314315 if amount == 1 {316 with_weight(317 <Pallet<T>>::burn_from(self, &sender, &from, token, nesting_budget),318 <CommonWeights<T>>::burn_from(),319 )320 } else {321 Ok(().into())322 }323 }324325 fn check_nesting(326 &self,327 sender: T::CrossAccountId,328 from: (CollectionId, TokenId),329 under: TokenId,330 budget: &dyn Budget,331 ) -> sp_runtime::DispatchResult {332 <Pallet<T>>::check_nesting(self, sender, from, under, budget)333 }334335 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {336 <Owned<T>>::iter_prefix((self.id, account))337 .map(|(id, _)| id)338 .collect()339 }340341 fn collection_tokens(&self) -> Vec<TokenId> {342 <TokenData<T>>::iter_prefix((self.id,))343 .map(|(id, _)| id)344 .collect()345 }346347 fn token_exists(&self, token: TokenId) -> bool {348 <Pallet<T>>::token_exists(self, token)349 }350351 fn last_token_id(&self) -> TokenId {352 TokenId(<TokensMinted<T>>::get(self.id))353 }354355 fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId> {356 <TokenData<T>>::get((self.id, token)).map(|t| t.owner)357 }358 fn const_metadata(&self, token: TokenId) -> Vec<u8> {359 <TokenData<T>>::get((self.id, token))360 .map(|t| t.const_data)361 .unwrap_or_default()362 .into_inner()363 }364365 fn token_properties(&self, token_id: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property> {366 let properties = <Pallet<T>>::token_properties((self.id, token_id));367368 keys.map(|keys| {369 keys.into_iter()370 .filter_map(|key| {371 properties.get(&key).map(|value| Property {372 key,373 value: value.clone(),374 })375 })376 .collect()377 })378 .unwrap_or_else(|| {379 properties380 .iter()381 .map(|(key, value)| Property {382 key: key.clone(),383 value: value.clone(),384 })385 .collect()386 })387 }388389 fn total_supply(&self) -> u32 {390 <Pallet<T>>::total_supply(self)391 }392393 fn account_balance(&self, account: T::CrossAccountId) -> u32 {394 <AccountBalance<T>>::get((self.id, account))395 }396397 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {398 if <TokenData<T>>::get((self.id, token))399 .map(|a| a.owner == account)400 .unwrap_or(false)401 {402 1403 } else {404 0405 }406 }407408 fn allowance(409 &self,410 sender: T::CrossAccountId,411 spender: T::CrossAccountId,412 token: TokenId,413 ) -> u128 {414 if <TokenData<T>>::get((self.id, token))415 .map(|a| a.owner != sender)416 .unwrap_or(true)417 {418 0419 } else if <Allowance<T>>::get((self.id, token)) == Some(spender) {420 1421 } else {422 0423 }424 }425}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use core::marker::PhantomData;1819use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight};20use up_data_structs::{21 TokenId, CreateItemExData, CollectionId, budget::Budget, Property, PropertyKey,22 PropertyKeyPermission, PropertyValue,23};24use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};25use sp_runtime::DispatchError;26use sp_std::vec::Vec;2728use crate::{29 AccountBalance, Allowance, Config, CreateItemData, Error, NonfungibleHandle, Owned, Pallet,30 SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,31};3233pub struct CommonWeights<T: Config>(PhantomData<T>);34impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {35 fn create_item() -> Weight {36 <SelfWeightOf<T>>::create_item()37 }3839 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {40 match data {41 CreateItemExData::NFT(t) => <SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32),42 _ => 0,43 }44 }4546 fn create_multiple_items(amount: u32) -> Weight {47 <SelfWeightOf<T>>::create_multiple_items(amount)48 }4950 fn burn_item() -> Weight {51 <SelfWeightOf<T>>::burn_item()52 }5354 fn set_collection_properties(amount: u32) -> Weight {55 <SelfWeightOf<T>>::set_collection_properties(amount)56 }5758 fn delete_collection_properties(amount: u32) -> Weight {59 <SelfWeightOf<T>>::delete_collection_properties(amount)60 }6162 fn set_token_properties(amount: u32) -> Weight {63 <SelfWeightOf<T>>::set_token_properties(amount)64 }6566 fn delete_token_properties(amount: u32) -> Weight {67 <SelfWeightOf<T>>::delete_token_properties(amount)68 }6970 fn set_property_permissions(amount: u32) -> Weight {71 <SelfWeightOf<T>>::set_property_permissions(amount)72 }7374 fn transfer() -> Weight {75 <SelfWeightOf<T>>::transfer()76 }7778 fn approve() -> Weight {79 <SelfWeightOf<T>>::approve()80 }8182 fn transfer_from() -> Weight {83 <SelfWeightOf<T>>::transfer_from()84 }8586 fn burn_from() -> Weight {87 <SelfWeightOf<T>>::burn_from()88 }89}9091fn map_create_data<T: Config>(92 data: up_data_structs::CreateItemData,93 to: &T::CrossAccountId,94) -> Result<CreateItemData<T>, DispatchError> {95 match data {96 up_data_structs::CreateItemData::NFT(data) => Ok(CreateItemData::<T> {97 const_data: data.const_data,98 properties: data.properties,99 owner: to.clone(),100 }),101 _ => fail!(<Error<T>>::NotNonfungibleDataUsedToMintFungibleCollectionToken),102 }103}104105impl<T: Config> CommonCollectionOperations<T> for NonfungibleHandle<T> {106 fn create_item(107 &self,108 sender: T::CrossAccountId,109 to: T::CrossAccountId,110 data: up_data_structs::CreateItemData,111 nesting_budget: &dyn Budget,112 ) -> DispatchResultWithPostInfo {113 with_weight(114 <Pallet<T>>::create_item(115 self,116 &sender,117 map_create_data::<T>(data, &to)?,118 nesting_budget,119 ),120 <CommonWeights<T>>::create_item(),121 )122 }123124 fn create_multiple_items(125 &self,126 sender: T::CrossAccountId,127 to: T::CrossAccountId,128 data: Vec<up_data_structs::CreateItemData>,129 nesting_budget: &dyn Budget,130 ) -> DispatchResultWithPostInfo {131 let data = data132 .into_iter()133 .map(|d| map_create_data::<T>(d, &to))134 .collect::<Result<Vec<_>, DispatchError>>()?;135136 let amount = data.len();137 with_weight(138 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),139 <CommonWeights<T>>::create_multiple_items(amount as u32),140 )141 }142143 fn create_multiple_items_ex(144 &self,145 sender: <T>::CrossAccountId,146 data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,147 nesting_budget: &dyn Budget,148 ) -> DispatchResultWithPostInfo {149 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);150 let data = match data {151 up_data_structs::CreateItemExData::NFT(nft) => nft,152 _ => fail!(Error::<T>::NotNonfungibleDataUsedToMintFungibleCollectionToken),153 };154155 with_weight(156 <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner(), nesting_budget),157 weight,158 )159 }160161 fn set_collection_properties(162 &self,163 sender: T::CrossAccountId,164 properties: Vec<Property>,165 ) -> DispatchResultWithPostInfo {166 let weight = <CommonWeights<T>>::set_collection_properties(properties.len() as u32);167168 with_weight(169 <Pallet<T>>::set_collection_properties(self, &sender, properties),170 weight,171 )172 }173174 fn delete_collection_properties(175 &self,176 sender: &T::CrossAccountId,177 property_keys: Vec<PropertyKey>,178 ) -> DispatchResultWithPostInfo {179 let weight = <CommonWeights<T>>::delete_collection_properties(property_keys.len() as u32);180181 with_weight(182 <Pallet<T>>::delete_collection_properties(self, sender, property_keys),183 weight,184 )185 }186187 fn set_token_properties(188 &self,189 sender: T::CrossAccountId,190 token_id: TokenId,191 properties: Vec<Property>,192 ) -> DispatchResultWithPostInfo {193 let weight = <CommonWeights<T>>::set_token_properties(properties.len() as u32);194195 with_weight(196 <Pallet<T>>::set_token_properties(self, &sender, token_id, properties),197 weight,198 )199 }200201 fn delete_token_properties(202 &self,203 sender: T::CrossAccountId,204 token_id: TokenId,205 property_keys: Vec<PropertyKey>,206 ) -> DispatchResultWithPostInfo {207 let weight = <CommonWeights<T>>::delete_token_properties(property_keys.len() as u32);208209 with_weight(210 <Pallet<T>>::delete_token_properties(self, &sender, token_id, property_keys),211 weight,212 )213 }214215 fn set_property_permissions(216 &self,217 sender: &T::CrossAccountId,218 property_permissions: Vec<PropertyKeyPermission>,219 ) -> DispatchResultWithPostInfo {220 let weight =221 <CommonWeights<T>>::set_property_permissions(property_permissions.len() as u32);222223 with_weight(224 <Pallet<T>>::set_property_permissions(self, sender, property_permissions),225 weight,226 )227 }228229 fn burn_item(230 &self,231 sender: T::CrossAccountId,232 token: TokenId,233 amount: u128,234 ) -> DispatchResultWithPostInfo {235 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);236 if amount == 1 {237 with_weight(238 <Pallet<T>>::burn(self, &sender, token),239 <CommonWeights<T>>::burn_item(),240 )241 } else {242 Ok(().into())243 }244 }245246 fn transfer(247 &self,248 from: T::CrossAccountId,249 to: T::CrossAccountId,250 token: TokenId,251 amount: u128,252 nesting_budget: &dyn Budget,253 ) -> DispatchResultWithPostInfo {254 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);255 if amount == 1 {256 with_weight(257 <Pallet<T>>::transfer(self, &from, &to, token, nesting_budget),258 <CommonWeights<T>>::transfer(),259 )260 } else {261 Ok(().into())262 }263 }264265 fn approve(266 &self,267 sender: T::CrossAccountId,268 spender: T::CrossAccountId,269 token: TokenId,270 amount: u128,271 ) -> DispatchResultWithPostInfo {272 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);273274 with_weight(275 if amount == 1 {276 <Pallet<T>>::set_allowance(self, &sender, token, Some(&spender))277 } else {278 <Pallet<T>>::set_allowance(self, &sender, token, None)279 },280 <CommonWeights<T>>::approve(),281 )282 }283284 fn transfer_from(285 &self,286 sender: T::CrossAccountId,287 from: T::CrossAccountId,288 to: T::CrossAccountId,289 token: TokenId,290 amount: u128,291 nesting_budget: &dyn Budget,292 ) -> DispatchResultWithPostInfo {293 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);294295 if amount == 1 {296 with_weight(297 <Pallet<T>>::transfer_from(self, &sender, &from, &to, token, nesting_budget),298 <CommonWeights<T>>::transfer_from(),299 )300 } else {301 Ok(().into())302 }303 }304305 fn burn_from(306 &self,307 sender: T::CrossAccountId,308 from: T::CrossAccountId,309 token: TokenId,310 amount: u128,311 nesting_budget: &dyn Budget,312 ) -> DispatchResultWithPostInfo {313 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);314315 if amount == 1 {316 with_weight(317 <Pallet<T>>::burn_from(self, &sender, &from, token, nesting_budget),318 <CommonWeights<T>>::burn_from(),319 )320 } else {321 Ok(().into())322 }323 }324325 fn check_nesting(326 &self,327 sender: T::CrossAccountId,328 from: (CollectionId, TokenId),329 under: TokenId,330 budget: &dyn Budget,331 ) -> sp_runtime::DispatchResult {332 <Pallet<T>>::check_nesting(self, sender, from, under, budget)333 }334335 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {336 <Owned<T>>::iter_prefix((self.id, account))337 .map(|(id, _)| id)338 .collect()339 }340341 fn collection_tokens(&self) -> Vec<TokenId> {342 <TokenData<T>>::iter_prefix((self.id,))343 .map(|(id, _)| id)344 .collect()345 }346347 fn token_exists(&self, token: TokenId) -> bool {348 <Pallet<T>>::token_exists(self, token)349 }350351 fn last_token_id(&self) -> TokenId {352 TokenId(<TokensMinted<T>>::get(self.id))353 }354355 fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId> {356 <TokenData<T>>::get((self.id, token)).map(|t| t.owner)357 }358 fn const_metadata(&self, token: TokenId) -> Vec<u8> {359 <TokenData<T>>::get((self.id, token))360 .map(|t| t.const_data)361 .unwrap_or_default()362 .into_inner()363 }364365 fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue> {366 <Pallet<T>>::token_properties((self.id, token_id))367 .get(key)368 .cloned()369 }370371 fn token_properties(&self, token_id: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property> {372 let properties = <Pallet<T>>::token_properties((self.id, token_id));373374 keys.map(|keys| {375 keys.into_iter()376 .filter_map(|key| {377 properties.get(&key).map(|value| Property {378 key,379 value: value.clone(),380 })381 })382 .collect()383 })384 .unwrap_or_else(|| {385 properties386 .iter()387 .map(|(key, value)| Property {388 key: key.clone(),389 value: value.clone(),390 })391 .collect()392 })393 }394395 fn total_supply(&self) -> u32 {396 <Pallet<T>>::total_supply(self)397 }398399 fn account_balance(&self, account: T::CrossAccountId) -> u32 {400 <AccountBalance<T>>::get((self.id, account))401 }402403 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {404 if <TokenData<T>>::get((self.id, token))405 .map(|a| a.owner == account)406 .unwrap_or(false)407 {408 1409 } else {410 0411 }412 }413414 fn allowance(415 &self,416 sender: T::CrossAccountId,417 spender: T::CrossAccountId,418 token: TokenId,419 ) -> u128 {420 if <TokenData<T>>::get((self.id, token))421 .map(|a| a.owner != sender)422 .unwrap_or(true)423 {424 0425 } else if <Allowance<T>>::get((self.id, token)) == Some(spender) {426 1427 } else {428 0429 }430 }431}pallets/proxy-rmrk-core/Cargo.tomldiffbeforeafterboth--- /dev/null
+++ b/pallets/proxy-rmrk-core/Cargo.toml
@@ -0,0 +1,49 @@
+[package]
+name = "pallet-rmrk-core"
+version = "0.1.0"
+license = "GPLv3"
+edition = "2021"
+
+[dependencies.codec]
+default-features = false
+features = ['derive']
+package = 'parity-scale-codec'
+version = '3.1.2'
+
+[dependencies]
+frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+pallet-common = { default-features = false, path = '../common' }
+pallet-nonfungible = { default-features = false, path = "../../pallets/nonfungible" }
+# pallet-structure = { default-features = false, path = '../structure' }
+up-data-structs = { default-features = false, path = '../../primitives/data-structs' }
+# evm-coder = { default-features = false, path = '../../crates/evm-coder' }
+# pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }
+pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.21-logs" }
+frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
+
+[features]
+default = ["std"]
+std = [
+ "frame-support/std",
+ "frame-system/std",
+ "sp-runtime/std",
+ "sp-std/std",
+ "up-data-structs/std",
+ "pallet-common/std",
+ "pallet-nonfungible/std",
+ "pallet-evm/std",
+ # "pallet-structure/std",
+ # "evm-coder/std",
+ # "pallet-evm-coder-substrate/std",
+ 'frame-benchmarking/std',
+]
+runtime-benchmarks = [
+ 'frame-benchmarking',
+ 'frame-support/runtime-benchmarks',
+ 'frame-system/runtime-benchmarks',
+]
pallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -0,0 +1,256 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+#![cfg_attr(not(feature = "std"), no_std)]
+
+use frame_support::{pallet_prelude::*, transactional, BoundedVec, dispatch::DispatchResult};
+use frame_system::{pallet_prelude::*, ensure_signed};
+use sp_runtime::{DispatchError, traits::StaticLookup};
+use up_data_structs::*;
+use pallet_common::{Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations};
+use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle};
+use pallet_evm::account::CrossAccountId;
+
+pub use pallet::*;
+
+pub mod misc;
+pub mod property;
+
+use misc::*;
+pub use property::*;
+
+#[frame_support::pallet]
+pub mod pallet {
+ use super::*;
+ use pallet_evm::account;
+
+ #[pallet::config]
+ pub trait Config: frame_system::Config
+ + pallet_common::Config
+ + pallet_nonfungible::Config
+ + account::Config {
+ type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
+ }
+
+ #[pallet::pallet]
+ #[pallet::generate_store(pub(super) trait Store)]
+ pub struct Pallet<T>(_);
+
+ #[pallet::event]
+ #[pallet::generate_deposit(pub(super) fn deposit_event)]
+ pub enum Event<T: Config> {
+ CollectionCreated {
+ issuer: T::AccountId,
+ collection_id: RmrkCollectionId,
+ },
+ CollectionDestroyed {
+ issuer: T::AccountId,
+ collection_id: RmrkCollectionId,
+ },
+ IssuerChanged {
+ old_issuer: T::AccountId,
+ new_issuer: T::AccountId,
+ collection_id: RmrkCollectionId,
+ },
+ CollectionLocked {
+ issuer: T::AccountId,
+ collection_id: RmrkCollectionId,
+ },
+ }
+
+ #[pallet::error]
+ pub enum Error<T> {
+ /* Unique-specific events */
+ CorruptedCollectionType,
+ NotRmrkCollection,
+ RmrkPropertyKeyIsTooLong,
+ RmrkPropertyValueIsTooLong,
+
+ /* RMRK compatible events */
+ CollectionNotEmpty,
+ NoAvailableCollectionId,
+ CollectionUnknown,
+ }
+
+ #[pallet::call]
+ impl<T: Config> Pallet<T> {
+ #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
+ #[transactional]
+ pub fn create_collection(
+ origin: OriginFor<T>,
+ metadata: RmrkString,
+ max: Option<u32>,
+ symbol: RmrkCollectionSymbol,
+ ) -> DispatchResult {
+ let sender = ensure_signed(origin)?;
+
+ let limits = max.map(|max| CollectionLimits {
+ token_limit: Some(max),
+ ..Default::default()
+ });
+
+ let data = CreateCollectionData {
+ limits,
+ token_prefix: symbol.into_inner()
+ .try_into()
+ .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,
+ ..Default::default()
+ };
+
+ let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);
+
+ if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {
+ return Err(<Error<T>>::NoAvailableCollectionId.into());
+ }
+
+ let collection_id = collection_id_res?;
+
+ let collection = Self::get_nft_collection(collection_id)?.into_inner();
+
+ <PalletCommon<T>>::set_scoped_collection_properties(
+ &collection,
+ PropertyScope::Rmrk,
+ [
+ rmrk_property!(Config=T, Metadata: metadata)?,
+ rmrk_property!(Config=T, CollectionType: CollectionType::Regular)?,
+ ].into_iter()
+ )?;
+
+ Self::deposit_event(Event::CollectionCreated {
+ issuer: sender,
+ collection_id: collection_id.0
+ });
+
+ Ok(())
+ }
+
+ #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
+ #[transactional]
+ pub fn destroy_collection(
+ origin: OriginFor<T>,
+ collection_id: RmrkCollectionId,
+ ) -> DispatchResult {
+ let sender = ensure_signed(origin)?;
+ let cross_sender = T::CrossAccountId::from_sub(sender.clone());
+
+ let unique_collection_id = collection_id.into();
+
+ let collection = Self::get_nft_collection(unique_collection_id)?;
+
+ Self::check_collection_type(unique_collection_id, CollectionType::Regular)?;
+
+ ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);
+
+ <PalletNft<T>>::destroy_collection(collection, &cross_sender)?;
+
+ Self::deposit_event(Event::CollectionDestroyed { issuer: sender, collection_id });
+
+ Ok(())
+ }
+
+ #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
+ #[transactional]
+ pub fn change_collection_issuer(
+ origin: OriginFor<T>,
+ collection_id: RmrkCollectionId,
+ new_issuer: <T::Lookup as StaticLookup>::Source,
+ ) -> DispatchResult {
+ let sender = ensure_signed(origin)?;
+
+ let new_issuer = T::Lookup::lookup(new_issuer)?;
+
+ Self::change_collection_owner(
+ collection_id.into(),
+ CollectionType::Regular,
+ sender.clone(),
+ new_issuer.clone()
+ )?;
+
+ Self::deposit_event(Event::IssuerChanged {
+ old_issuer: sender,
+ new_issuer,
+ collection_id,
+ });
+
+ Ok(())
+ }
+
+ #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
+ #[transactional]
+ pub fn lock_collection(
+ origin: OriginFor<T>,
+ collection_id: RmrkCollectionId,
+ ) -> DispatchResult {
+ let sender = ensure_signed(origin)?;
+ let cross_sender = T::CrossAccountId::from_sub(sender.clone());
+
+ let collection = Self::get_nft_collection(collection_id.into())?;
+ collection.check_is_owner(&cross_sender)?;
+
+ let token_count = collection.total_supply();
+
+ let mut collection = collection.into_inner();
+ collection.limits.token_limit = Some(token_count);
+ collection.save()?;
+
+ Self::deposit_event(Event::CollectionLocked { issuer: sender, collection_id });
+
+ Ok(())
+ }
+ }
+}
+
+impl<T: Config> Pallet<T> {
+ fn change_collection_owner(
+ collection_id: CollectionId,
+ collection_type: CollectionType,
+ sender: T::AccountId,
+ new_owner: T::AccountId,
+ ) -> DispatchResult {
+ let mut collection = Self::get_nft_collection(collection_id)?.into_inner();
+ collection.check_is_owner(&T::CrossAccountId::from_sub(sender))?;
+
+ Self::check_collection_type(collection_id, collection_type)?;
+
+ collection.owner = new_owner;
+ collection.save()
+ }
+
+ fn get_nft_collection(collection_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {
+ let collection = <CollectionHandle<T>>::try_get(collection_id)
+ .map_err(|_| <Error<T>>::CollectionUnknown)?
+ .into_nft_collection()?;
+
+ Ok(collection)
+ }
+
+ fn get_collection_type(collection_id: CollectionId) -> Result<CollectionType, DispatchError> {
+ let collection_type: CollectionType = <PalletCommon<T>>::collection_properties(collection_id)
+ .get(&rmrk_property!(Config=T, CollectionType)?)
+ .ok_or(<Error<T>>::NotRmrkCollection)?
+ .try_into()
+ .map_err(<Error<T>>::from)?;
+
+ Ok(collection_type)
+ }
+
+ fn check_collection_type(collection_id: CollectionId, collection_type: CollectionType) -> DispatchResult {
+ let actual_type = Self::get_collection_type(collection_id)?;
+ ensure!(actual_type == collection_type, <CommonError<T>>::NoPermission);
+
+ Ok(())
+ }
+}
pallets/proxy-rmrk-core/src/misc.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/proxy-rmrk-core/src/misc.rs
@@ -0,0 +1,75 @@
+use super::*;
+use codec::{Encode, Decode};
+use pallet_nonfungible::NonfungibleHandle;
+
+macro_rules! impl_rmrk_value {
+ ($enum_name:path, decode_error: $error:ident) => {
+ impl IntoPropertyValue for $enum_name {
+ fn into_property_value(self) -> Result<PropertyValue, MiscError> {
+ self.encode()
+ .try_into()
+ .map_err(|_| MiscError::RmrkPropertyValueIsTooLong)
+ }
+ }
+
+ impl TryFrom<&PropertyValue> for $enum_name {
+ type Error = MiscError;
+
+ fn try_from(value: &PropertyValue) -> Result<Self, Self::Error> {
+ let mut value = value.as_slice();
+
+ <$enum_name>::decode(&mut value)
+ .map_err(|_| MiscError::$error)
+ }
+ }
+
+ };
+}
+
+pub enum MiscError {
+ RmrkPropertyValueIsTooLong,
+ CorruptedCollectionType,
+}
+
+impl<T: Config> From<MiscError> for Error<T> {
+ fn from(error: MiscError) -> Self {
+ match error {
+ MiscError::RmrkPropertyValueIsTooLong => Self::RmrkPropertyValueIsTooLong,
+ MiscError::CorruptedCollectionType => Self::CorruptedCollectionType,
+ }
+ }
+}
+
+pub trait IntoNftCollection<T: Config> {
+ fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>>;
+}
+
+impl<T: Config> IntoNftCollection<T> for CollectionHandle<T> {
+ fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>> {
+ match self.mode {
+ CollectionMode::NFT => Ok(NonfungibleHandle::cast(self)),
+ _ => Err(<Error<T>>::NotRmrkCollection)
+ }
+ }
+}
+
+pub trait IntoPropertyValue {
+ fn into_property_value(self) -> Result<PropertyValue, MiscError>;
+}
+
+impl<L: Get<u32>> IntoPropertyValue for BoundedVec<u8, L> {
+ fn into_property_value(self) -> Result<PropertyValue, MiscError> {
+ self.into_inner()
+ .try_into()
+ .map_err(|_| MiscError::RmrkPropertyValueIsTooLong)
+ }
+}
+
+#[derive(Encode, Decode, PartialEq, Eq)]
+pub enum CollectionType {
+ Regular,
+ Resource,
+ Base,
+}
+
+impl_rmrk_value!(CollectionType, decode_error: CorruptedCollectionType);
pallets/proxy-rmrk-core/src/property.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/proxy-rmrk-core/src/property.rs
@@ -0,0 +1,98 @@
+use super::*;
+use core::convert::AsRef;
+
+pub enum RmrkProperty {
+ Metadata,
+ CollectionType,
+ Recipient,
+ Royalty,
+ Equipped,
+ Pending,
+ ResourceCollection,
+ ResourcePriorities,
+ PendingRemoval,
+ Parts,
+ Base,
+ Src,
+ Slot,
+ License,
+ Thumb,
+ EquippedNft,
+ BaseType,
+ // // RmrkPartId(/* Id type? */)
+ EquippableList,
+ ZIndex,
+ ThemeName,
+ ThemeProperty(RmrkString),
+ ThemeInherit,
+}
+
+impl RmrkProperty {
+ pub fn to_key<T: Config>(self) -> Result<PropertyKey, Error<T>> {
+ fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {
+ container.as_ref()
+ }
+
+ macro_rules! key {
+ ($($component:expr),+) => {
+ PropertyKey::try_from([$(key!(@ &$component)),+].concat())
+ .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)
+ };
+
+ (@ $key:expr) => {
+ get_bytes($key)
+ };
+ }
+
+ match self {
+ Self::Metadata => key!("metadata"),
+ Self::CollectionType => key!("collection-type"),
+ Self::Recipient => key!("recipient"),
+ Self::Royalty => key!("royalty"),
+ Self::Equipped => key!("equipped"),
+ Self::Pending => key!("pending"),
+ Self::ResourceCollection => key!("resource-collection"),
+ Self::ResourcePriorities => key!("resource-priorities"),
+ Self::PendingRemoval => key!("pending-removal"),
+ Self::Parts => key!("parts"),
+ Self::Base => key!("base"),
+ Self::Src => key!("src"),
+ Self::Slot => key!("slot"),
+ Self::License => key!("license"),
+ Self::Thumb => key!("thumb"),
+ Self::EquippedNft => key!("equipped-nft"),
+ Self::BaseType => key!("base-type"),
+ // RmrkResourceId(/* Id type? */)
+ // RmrkPartId(/* Id type? */)
+ Self::EquippableList => key!("equippable-list"),
+ Self::ZIndex => key!("z-index"),
+ Self::ThemeName => key!("theme-name"),
+ Self::ThemeProperty(name) => key!("theme-property-", name),
+ Self::ThemeInherit => key!("theme-inherit"),
+ }
+ }
+}
+
+#[macro_export]
+macro_rules! rmrk_property {
+ (Config=$cfg:ty, $key:ident $(($key_ext:expr))?: $value:expr) => {{
+ let key = rmrk_property!(@$cfg, $key $(($key_ext))?)?;
+
+ let value = $value.into_property_value()
+ .map_err(<$crate::Error<$cfg>>::from)?;
+
+ Ok::<_, $crate::Error<$cfg>>(Property {
+ key,
+ value,
+ })
+ }};
+
+ (@$cfg:ty, $key:ident $(($key_ext:expr))?) => {
+ $crate::RmrkProperty::$key $(($key_ext))?.to_key::<$cfg>()
+ };
+
+ (Config=$cfg:ty, $key:ident $(($key_ext:expr))?) => {
+ PropertyScope::Rmrk.apply(rmrk_property!(@$cfg, $key $(($key_ext))?)?)
+ .map_err(|_| <$crate::Error<$cfg>>::RmrkPropertyKeyIsTooLong)
+ };
+}
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -20,7 +20,7 @@
use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight};
use up_data_structs::{
CollectionId, TokenId, CreateItemExData, CreateRefungibleExData, budget::Budget, Property,
- PropertyKey, PropertyKeyPermission,
+ PropertyKey, PropertyValue, PropertyKeyPermission,
};
use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
use sp_runtime::DispatchError;
@@ -340,6 +340,10 @@
.into_inner()
}
+ fn token_property(&self, _token_id: TokenId, _key: &PropertyKey) -> Option<PropertyValue> {
+ None
+ }
+
fn token_properties(
&self,
_token_id: TokenId,
pallets/rmrk-proxy/Cargo.tomldiffbeforeafterboth--- a/pallets/rmrk-proxy/Cargo.toml
+++ /dev/null
@@ -1,49 +0,0 @@
-[package]
-name = "pallet-rmrk-proxy"
-version = "0.1.0"
-license = "GPLv3"
-edition = "2021"
-
-[dependencies.codec]
-default-features = false
-features = ['derive']
-package = 'parity-scale-codec'
-version = '3.1.2'
-
-[dependencies]
-frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
-frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
-sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
-sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
-sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
-pallet-common = { default-features = false, path = '../common' }
-pallet-nonfungible = { default-features = false, path = "../../pallets/nonfungible" }
-# pallet-structure = { default-features = false, path = '../structure' }
-up-data-structs = { default-features = false, path = '../../primitives/data-structs' }
-# evm-coder = { default-features = false, path = '../../crates/evm-coder' }
-# pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }
-pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.21-logs" }
-frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
-scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
-
-[features]
-default = ["std"]
-std = [
- "frame-support/std",
- "frame-system/std",
- "sp-runtime/std",
- "sp-std/std",
- "up-data-structs/std",
- "pallet-common/std",
- "pallet-nonfungible/std",
- "pallet-evm/std",
- # "pallet-structure/std",
- # "evm-coder/std",
- # "pallet-evm-coder-substrate/std",
- 'frame-benchmarking/std',
-]
-runtime-benchmarks = [
- 'frame-benchmarking',
- 'frame-support/runtime-benchmarks',
- 'frame-system/runtime-benchmarks',
-]
pallets/rmrk-proxy/src/lib.rsdiffbeforeafterboth--- a/pallets/rmrk-proxy/src/lib.rs
+++ /dev/null
@@ -1,232 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-#![cfg_attr(not(feature = "std"), no_std)]
-
-use frame_support::{pallet_prelude::*, transactional, BoundedVec, traits::ConstU32, dispatch::DispatchResult};
-use frame_system::{pallet_prelude::*, ensure_signed};
-use sp_runtime::DispatchError;
-use up_data_structs::*;
-use pallet_common::{Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations};
-use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle};
-use pallet_evm::account::CrossAccountId;
-
-pub use pallet::*;
-
-pub mod misc;
-
-use misc::*;
-
-#[frame_support::pallet]
-pub mod pallet {
- use super::*;
- use pallet_evm::account;
-
- #[pallet::config]
- pub trait Config: frame_system::Config
- + pallet_common::Config
- + pallet_nonfungible::Config
- + account::Config {
- type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
- }
-
- #[pallet::pallet]
- #[pallet::generate_store(pub(super) trait Store)]
- pub struct Pallet<T>(_);
-
- #[pallet::event]
- #[pallet::generate_deposit(pub(super) fn deposit_event)]
- pub enum Event<T: Config> {
- CollectionCreated {
- issuer: T::AccountId,
- collection_id: CollectionId,
- },
- CollectionDestroyed {
- issuer: T::AccountId,
- collection_id: CollectionId,
- },
- CollectionLocked {
- issuer: T::AccountId,
- collection_id: CollectionId,
- },
- }
-
- #[pallet::error]
- pub enum Error<T> {
- /* Unique-specific events */
- CorruptedCollectionType,
- NotRmrkCollection,
-
- /* RMRK compatible events */
- CollectionNotEmpty,
- NoAvailableCollectionId,
- CollectionUnknown,
- }
-
- #[pallet::call]
- impl<T: Config> Pallet<T> {
- #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
- #[transactional]
- pub fn create_collection(
- origin: OriginFor<T>,
- metadata: PropertyValue,
- max: Option<u32>,
- symbol: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,
- ) -> DispatchResult {
- let sender = ensure_signed(origin)?;
-
- let limits = max.map(|max| CollectionLimits {
- token_limit: Some(max),
- ..Default::default()
- });
-
- let data = CreateCollectionData {
- limits,
- token_prefix: symbol,
- ..Default::default()
- };
-
- let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);
-
- if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {
- return Err(<Error<T>>::NoAvailableCollectionId.into());
- }
-
- let collection_id = collection_id_res?;
-
- let collection = Self::get_nft_collection(collection_id)?.into_inner();
-
- <PalletCommon<T>>::set_scoped_collection_properties(
- &collection,
- PropertyScope::Rmrk,
- [
- rmrk_property!(Metadata, metadata),
- rmrk_property!(CollectionType, CollectionType::Regular),
- ].into_iter()
- )?;
-
- Self::deposit_event(Event::CollectionCreated { issuer: sender, collection_id });
-
- Ok(())
- }
-
- #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
- #[transactional]
- pub fn destroy_collection(
- origin: OriginFor<T>,
- collection_id: CollectionId,
- ) -> DispatchResult {
- let sender = ensure_signed(origin)?;
- let cross_sender = T::CrossAccountId::from_sub(sender.clone());
-
- let collection = Self::get_nft_collection(collection_id)?;
-
- Self::check_collection_type(collection_id, CollectionType::Regular)?;
-
- ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);
-
- <PalletNft<T>>::destroy_collection(collection, &cross_sender)?;
-
- Self::deposit_event(Event::CollectionDestroyed { issuer: sender, collection_id });
-
- Ok(())
- }
-
- #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
- #[transactional]
- pub fn change_collection_issuer(
- origin: OriginFor<T>,
- collection_id: CollectionId,
- new_issuer: T::AccountId,
- ) -> DispatchResult {
- let sender = ensure_signed(origin)?;
-
- Self::change_collection_owner(
- collection_id,
- CollectionType::Regular,
- sender,
- new_issuer
- )?;
-
- Ok(())
- }
-
- #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
- #[transactional]
- pub fn lock_collection(
- origin: OriginFor<T>,
- collection_id: CollectionId,
- ) -> DispatchResult {
- let sender = ensure_signed(origin)?;
- let cross_sender = T::CrossAccountId::from_sub(sender.clone());
-
- let collection = Self::get_nft_collection(collection_id)?;
- collection.check_is_owner(&cross_sender)?;
-
- let token_count = collection.total_supply();
-
- let mut collection = collection.into_inner();
- collection.limits.token_limit = Some(token_count);
- collection.save()?;
-
- Self::deposit_event(Event::CollectionLocked { issuer: sender, collection_id });
-
- Ok(())
- }
- }
-}
-
-impl<T: Config> Pallet<T> {
- fn change_collection_owner(
- collection_id: CollectionId,
- collection_type: CollectionType,
- sender: T::AccountId,
- new_owner: T::AccountId,
- ) -> DispatchResult {
- let mut collection = Self::get_nft_collection(collection_id)?.into_inner();
- collection.check_is_owner(&T::CrossAccountId::from_sub(sender))?;
-
- Self::check_collection_type(collection_id, collection_type)?;
-
- collection.owner = new_owner;
- collection.save()
- }
-
- fn get_nft_collection(collection_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {
- let collection = <CollectionHandle<T>>::try_get(collection_id)
- .map_err(|_| <Error<T>>::CollectionUnknown)?
- .into_nft_collection()?;
-
- Ok(collection)
- }
-
- fn get_collection_type(collection_id: CollectionId) -> Result<CollectionType, DispatchError> {
- let collection_type: CollectionType = <PalletCommon<T>>::collection_properties(collection_id)
- .get(&rmrk_property!(CollectionType))
- .ok_or(<Error<T>>::NotRmrkCollection)?
- .try_into()
- .map_err(<Error<T>>::from)?;
-
- Ok(collection_type)
- }
-
- fn check_collection_type(collection_id: CollectionId, collection_type: CollectionType) -> DispatchResult {
- let actual_type = Self::get_collection_type(collection_id)?;
- ensure!(actual_type == collection_type, <CommonError<T>>::NoPermission);
-
- Ok(())
- }
-}
pallets/rmrk-proxy/src/misc.rsdiffbeforeafterboth--- a/pallets/rmrk-proxy/src/misc.rs
+++ /dev/null
@@ -1,98 +0,0 @@
-use super::*;
-use codec::{Encode, Decode};
-use frame_support::dispatch::Vec;
-use pallet_nonfungible::NonfungibleHandle;
-
-#[macro_export]
-macro_rules! rmrk_property {
- ($key:ident, $value:expr) => {
- Property {
- key: rmrk_property!(@raw $key),
- value: $value.into()
- }
- };
-
- (@raw $key:ident) => {
- RmrkProperty::$key.to_key()
- };
-
- ($key:ident) => {
- PropertyScope::Rmrk.apply(rmrk_property!(@raw $key)).unwrap()
- };
-}
-
-macro_rules! impl_rmrk_value {
- ($enum_name:path, decode_error: $error:ident) => {
- impl Into<PropertyValue> for $enum_name {
- fn into(self) -> PropertyValue {
- self.encode().try_into().unwrap()
- }
- }
-
- impl TryFrom<&PropertyValue> for $enum_name {
- type Error = MiscError;
-
- fn try_from(value: &PropertyValue) -> Result<Self, Self::Error> {
- let mut value = value.as_slice();
-
- <$enum_name>::decode(&mut value)
- .map_err(|_| MiscError::$error)
- }
- }
-
- };
-}
-
-pub enum MiscError {
- CorruptedCollectionType,
-}
-
-impl<T: Config> From<MiscError> for Error<T> {
- fn from(error: MiscError) -> Self {
- match error {
- MiscError::CorruptedCollectionType => Self::CorruptedCollectionType,
- }
- }
-}
-
-pub trait IntoNftCollection<T: Config> {
- fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>>;
-}
-
-impl<T: Config> IntoNftCollection<T> for CollectionHandle<T> {
- fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>> {
- match self.mode {
- CollectionMode::NFT => Ok(NonfungibleHandle::cast(self)),
- _ => Err(<Error<T>>::NotRmrkCollection)
- }
- }
-}
-
-pub enum RmrkProperty {
- Metadata,
- CollectionType,
-}
-
-impl RmrkProperty {
- pub fn to_key(self) -> PropertyKey {
- let key = |str_key: &str| {
- PropertyKey::try_from(
- str_key.bytes().collect::<Vec<_>>()
- ).unwrap()
- };
-
- match self {
- Self::Metadata => key("metadata"),
- Self::CollectionType => key("collection-type"),
- }
- }
-}
-
-#[derive(Encode, Decode, PartialEq, Eq)]
-pub enum CollectionType {
- Regular,
- Resource,
- Base,
-}
-
-impl_rmrk_value!(CollectionType, decode_error: CorruptedCollectionType);
primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -905,8 +905,20 @@
pub const RmrkPartsLimit: u32 = 3;
}
-pub type RmrkCollectionInfo<AccountId> =
- CollectionInfo<RmrkString, BoundedVec<u8, RmrkCollectionSymbolLimit>, AccountId>;
+impl From<RmrkCollectionId> for CollectionId {
+ fn from(id: RmrkCollectionId) -> Self {
+ Self(id)
+ }
+}
+
+impl From<RmrkNftId> for TokenId {
+ fn from(id: RmrkNftId) -> Self {
+ Self(id)
+ }
+}
+
+pub type RmrkCollectionSymbol = BoundedVec<u8, RmrkCollectionSymbolLimit>;
+pub type RmrkCollectionInfo<AccountId> = CollectionInfo<RmrkString, RmrkCollectionSymbol, AccountId>;
pub type RmrkInstanceInfo<AccountId> = NftInfo<AccountId, Permill, RmrkString>;
pub type RmrkResourceInfo = ResourceInfo<
BoundedVec<u8, RmrkResourceSymbolLimit>,
@@ -924,4 +936,4 @@
pub type RmrkThemeName = RmrkRpcString;
pub type RmrkPropertyKey = RmrkRpcString;
-type RmrkString = BoundedVec<u8, RmrkStringLimit>;
+pub type RmrkString = BoundedVec<u8, RmrkStringLimit>;
runtime/opal/Cargo.tomldiffbeforeafterboth--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -33,7 +33,7 @@
'pallet-fungible/runtime-benchmarks',
'pallet-refungible/runtime-benchmarks',
'pallet-nonfungible/runtime-benchmarks',
- 'pallet-rmrk-proxy/runtime-benchmarks',
+ 'pallet-proxy-rmrk-core/runtime-benchmarks',
'pallet-unique/runtime-benchmarks',
'pallet-inflation/runtime-benchmarks',
'pallet-xcm/runtime-benchmarks',
@@ -90,7 +90,7 @@
'pallet-fungible/std',
'pallet-refungible/std',
'pallet-nonfungible/std',
- 'pallet-rmrk-proxy/std',
+ 'pallet-proxy-rmrk-core/std',
'pallet-unique/std',
'pallet-unq-scheduler/std',
'pallet-charge-transaction/std',
@@ -417,7 +417,7 @@
pallet-fungible = { default-features = false, path = "../../pallets/fungible" }
pallet-refungible = { default-features = false, path = "../../pallets/refungible" }
pallet-nonfungible = { default-features = false, path = "../../pallets/nonfungible" }
-pallet-rmrk-proxy = { default-features = false, path = "../../pallets/rmrk-proxy" }
+pallet-proxy-rmrk-core = { default-features = false, path = "../../pallets/proxy-rmrk-core", package = "pallet-rmrk-core" }
pallet-unq-scheduler = { path = '../../pallets/scheduler', default-features = false }
# pallet-contract-helpers = { path = '../pallets/contract-helpers', default-features = false, version = '0.1.0' }
pallet-charge-transaction = { git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.21", package = "pallet-template-transaction-payment", default-features = false, version = "3.0.0" }
runtime/opal/src/lib.rsdiffbeforeafterboth--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -901,7 +901,7 @@
type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;
}
-impl pallet_rmrk_proxy::Config for Runtime {
+impl pallet_proxy_rmrk_core::Config for Runtime {
type Event = Event;
}
@@ -1017,7 +1017,7 @@
Refungible: pallet_refungible::{Pallet, Storage} = 68,
Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,
Structure: pallet_structure::{Pallet, Call, Storage, Event<T>} = 70,
- RmrkProxy: pallet_rmrk_proxy::{Pallet, Call, Storage, Event<T>} = 71,
+ ProxyRmrkCore: pallet_proxy_rmrk_core::{Pallet, Call, Storage, Event<T>} = 71,
// Frontier
EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,
runtime/quartz/Cargo.tomldiffbeforeafterboth--- a/runtime/quartz/Cargo.toml
+++ b/runtime/quartz/Cargo.toml
@@ -33,6 +33,7 @@
'pallet-fungible/runtime-benchmarks',
'pallet-refungible/runtime-benchmarks',
'pallet-nonfungible/runtime-benchmarks',
+ 'pallet-proxy-rmrk-core/runtime-benchmarks',
'pallet-unique/runtime-benchmarks',
'pallet-inflation/runtime-benchmarks',
'pallet-xcm/runtime-benchmarks',
@@ -89,6 +90,7 @@
'pallet-fungible/std',
'pallet-refungible/std',
'pallet-nonfungible/std',
+ 'pallet-proxy-rmrk-core/std',
'pallet-unique/std',
'pallet-unq-scheduler/std',
'pallet-charge-transaction/std',
@@ -414,6 +416,7 @@
pallet-fungible = { default-features = false, path = "../../pallets/fungible" }
pallet-refungible = { default-features = false, path = "../../pallets/refungible" }
pallet-nonfungible = { default-features = false, path = "../../pallets/nonfungible" }
+pallet-proxy-rmrk-core = { default-features = false, path = "../../pallets/proxy-rmrk-core", package = "pallet-rmrk-core" }
pallet-unq-scheduler = { path = '../../pallets/scheduler', default-features = false }
# pallet-contract-helpers = { path = '../pallets/contract-helpers', default-features = false, version = '0.1.0' }
pallet-charge-transaction = { git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.21", package = "pallet-template-transaction-payment", default-features = false, version = "3.0.0" }
runtime/unique/Cargo.tomldiffbeforeafterboth--- a/runtime/unique/Cargo.toml
+++ b/runtime/unique/Cargo.toml
@@ -33,6 +33,7 @@
'pallet-fungible/runtime-benchmarks',
'pallet-refungible/runtime-benchmarks',
'pallet-nonfungible/runtime-benchmarks',
+ 'pallet-proxy-rmrk-core/runtime-benchmarks',
'pallet-unique/runtime-benchmarks',
'pallet-inflation/runtime-benchmarks',
'pallet-xcm/runtime-benchmarks',
@@ -89,6 +90,7 @@
'pallet-fungible/std',
'pallet-refungible/std',
'pallet-nonfungible/std',
+ 'pallet-proxy-rmrk-core/std',
'pallet-unique/std',
'pallet-unq-scheduler/std',
'pallet-charge-transaction/std',
@@ -413,6 +415,7 @@
pallet-fungible = { default-features = false, path = "../../pallets/fungible" }
pallet-refungible = { default-features = false, path = "../../pallets/refungible" }
pallet-nonfungible = { default-features = false, path = "../../pallets/nonfungible" }
+pallet-proxy-rmrk-core = { default-features = false, path = "../../pallets/proxy-rmrk-core", package = "pallet-rmrk-core" }
pallet-unq-scheduler = { path = '../../pallets/scheduler', default-features = false }
# pallet-contract-helpers = { path = '../pallets/contract-helpers', default-features = false, version = '0.1.0' }
pallet-charge-transaction = { git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.21", package = "pallet-template-transaction-payment", default-features = false, version = "3.0.0" }