difftreelog
Add properties extrinsics
in: master
10 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -736,7 +736,24 @@
) -> DispatchResult {
collection.check_is_owner_or_admin(sender)?;
- CollectionProperties::<T>::get(collection.id).try_change_property(property)?;
+ CollectionProperties::<T>::try_mutate(
+ collection.id,
+ |properties| properties.try_change_property(property.clone())
+ )?;
+
+ <Pallet<T>>::deposit_event(Event::CollectionPropertySet(collection.id, property));
+
+ Ok(())
+ }
+
+ pub fn change_collection_properties(
+ collection: &CollectionHandle<T>,
+ sender: &T::CrossAccountId,
+ properties: Vec<Property>,
+ ) -> DispatchResult {
+ for property in properties {
+ Self::change_collection_property(collection, sender, property)?;
+ }
Ok(())
}
@@ -909,7 +926,8 @@
fn create_multiple_items(amount: u32) -> Weight;
fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;
fn burn_item() -> Weight;
- fn set_property() -> Weight;
+ fn change_collection_properties(amount: u32) -> Weight;
+ fn change_token_properties(amount: u32) -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
fn transfer_from() -> Weight;
@@ -945,17 +963,17 @@
amount: u128,
) -> DispatchResultWithPostInfo;
- fn change_collection_property(
+ fn change_collection_properties(
&self,
sender: T::CrossAccountId,
- property: Property,
+ properties: Vec<Property>,
) -> DispatchResultWithPostInfo;
- fn change_token_property(
+ fn change_token_properties(
&self,
sender: T::CrossAccountId,
token_id: TokenId,
- property: Property,
+ property: Vec<Property>,
) -> DispatchResultWithPostInfo;
fn transfer(
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -50,8 +50,12 @@
<SelfWeightOf<T>>::burn_item()
}
- fn set_property() -> Weight {
- <SelfWeightOf<T>>::set_property()
+ fn change_collection_properties(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::change_collection_properties(amount)
+ }
+
+ fn change_token_properties(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::change_token_properties(amount)
}
fn transfer() -> Weight {
@@ -229,19 +233,19 @@
)
}
- fn change_collection_property(
+ fn change_collection_properties(
&self,
_sender: T::CrossAccountId,
- _property: Property,
+ _property: Vec<Property>,
) -> DispatchResultWithPostInfo {
fail!(<Error<T>>::PropertiesNotAllowed)
}
- fn change_token_property(
+ fn change_token_properties(
&self,
_sender: T::CrossAccountId,
_token_id: TokenId,
- _property: Property,
+ _property: Vec<Property>,
) -> DispatchResultWithPostInfo {
fail!(<Error<T>>::PropertiesNotAllowed)
}
pallets/fungible/src/weights.rsdiffbeforeafterboth--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -35,7 +35,8 @@
fn create_item() -> Weight;
fn create_multiple_items_ex(b: u32, ) -> Weight;
fn burn_item() -> Weight;
- fn set_property() -> Weight;
+ fn change_collection_properties(amount: u32) -> Weight;
+ fn change_token_properties(amount: u32) -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
fn transfer_from() -> Weight;
@@ -71,11 +72,16 @@
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
- fn set_property() -> Weight {
+ fn change_collection_properties(amount: u32) -> Weight {
// Error
0
}
+ fn change_token_properties(amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
// Storage: Fungible Balance (r:2 w:2)
fn transfer() -> Weight {
(17_713_000 as Weight)
@@ -134,7 +140,12 @@
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
- fn set_property() -> Weight {
+ fn change_collection_properties(amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
+ fn change_token_properties(amount: u32) -> Weight {
// Error
0
}
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -50,8 +50,12 @@
<SelfWeightOf<T>>::burn_item()
}
- fn set_property() -> Weight {
- <SelfWeightOf<T>>::set_property()
+ fn change_collection_properties(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::change_collection_properties(amount)
+ }
+
+ fn change_token_properties(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::change_token_properties(amount)
}
fn transfer() -> Weight {
@@ -145,6 +149,33 @@
)
}
+ fn change_collection_properties(
+ &self,
+ sender: T::CrossAccountId,
+ properties: Vec<Property>,
+ ) -> DispatchResultWithPostInfo {
+ let weight = <CommonWeights<T>>::change_collection_properties(properties.len() as u32);
+
+ with_weight(
+ <Pallet<T>>::change_collection_properties(self, &sender, properties),
+ weight
+ )
+ }
+
+ fn change_token_properties(
+ &self,
+ sender: T::CrossAccountId,
+ token_id: TokenId,
+ properties: Vec<Property>,
+ ) -> DispatchResultWithPostInfo {
+ let weight = <CommonWeights<T>>::change_token_properties(properties.len() as u32);
+
+ with_weight(
+ <Pallet<T>>::change_token_properties(self, &sender, token_id, properties),
+ weight
+ )
+ }
+
fn burn_item(
&self,
sender: T::CrossAccountId,
@@ -239,32 +270,6 @@
} else {
Ok(().into())
}
- }
-
- fn change_collection_property(
- &self,
- sender: T::CrossAccountId,
- property: Property,
- ) -> DispatchResultWithPostInfo {
- // let token_id = None;
- with_weight(
- // <Pallet<T>>::change_property(self, &sender, token_id, property),
- Ok(()),
- <CommonWeights<T>>::set_property(),
- )
- }
-
- fn change_token_property(
- &self,
- sender: T::CrossAccountId,
- token_id: TokenId,
- property: Property,
- ) -> DispatchResultWithPostInfo {
- with_weight(
- // <Pallet<T>>::change_property(self, &sender, Some(token_id), property),
- Ok(()),
- <CommonWeights<T>>::set_property(),
- )
}
fn set_variable_metadata(
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -265,12 +265,11 @@
.map(|p| p.clone())
.unwrap_or(PropertyPermission::None);
- let check_token_owner = || -> DispatchResult {
- let token_data = <TokenData<T>>::get((collection.id, token_id))
- .ok_or(<CommonError<T>>::TokenNotFound)?;
+ let token_data = <TokenData<T>>::get((collection.id, token_id))
+ .ok_or(<CommonError<T>>::TokenNotFound)?;
+ let check_token_owner = || -> DispatchResult {
ensure!(&token_data.owner == sender, <CommonError<T>>::NoPermission);
-
Ok(())
};
@@ -304,6 +303,27 @@
Ok(())
}
+ pub fn change_token_properties(
+ collection: &NonfungibleHandle<T>,
+ sender: &T::CrossAccountId,
+ token_id: TokenId,
+ properties: Vec<Property>,
+ ) -> DispatchResult {
+ for property in properties {
+ Self::change_token_property(collection, sender, token_id, property)?;
+ }
+
+ Ok(())
+ }
+
+ pub fn change_collection_properties(
+ collection: &NonfungibleHandle<T>,
+ sender: &T::CrossAccountId,
+ properties: Vec<Property>,
+ ) -> DispatchResult {
+ <PalletCommon<T>>::change_collection_properties(collection, sender, properties)
+ }
+
pub fn transfer(
collection: &NonfungibleHandle<T>,
from: &T::CrossAccountId,
pallets/nonfungible/src/weights.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -36,7 +36,8 @@
fn create_multiple_items(b: u32, ) -> Weight;
fn create_multiple_items_ex(b: u32, ) -> Weight;
fn burn_item() -> Weight;
- fn set_property() -> Weight;
+ fn change_collection_properties(amount: u32) -> Weight;
+ fn change_token_properties(amount: u32) -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
fn transfer_from() -> Weight;
@@ -92,11 +93,16 @@
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
- fn set_property() -> Weight {
+ fn change_collection_properties(amount: u32) -> Weight {
// TODO calculate appropriate weight
- 50_000_000 as Weight
+ (50_000_000 as Weight).saturating_mul(amount as Weight)
}
+ fn change_token_properties(amount: u32) -> Weight {
+ // TODO calculate appropriate weight
+ (50_000_000 as Weight).saturating_mul(amount as Weight)
+ }
+
// Storage: Nonfungible TokenData (r:1 w:1)
// Storage: Nonfungible AccountBalance (r:2 w:2)
// Storage: Nonfungible Allowance (r:1 w:0)
@@ -187,9 +193,14 @@
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
}
- fn set_property() -> Weight {
+ fn change_collection_properties(amount: u32) -> Weight {
+ // TODO calculate appropriate weight
+ (50_000_000 as Weight).saturating_mul(amount as Weight)
+ }
+
+ fn change_token_properties(amount: u32) -> Weight {
// TODO calculate appropriate weight
- 50_000_000 as Weight
+ (50_000_000 as Weight).saturating_mul(amount as Weight)
}
// Storage: Nonfungible TokenData (r:1 w:1)
pallets/refungible/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 sp_std::collections::btree_map::BTreeMap;20use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};21use up_data_structs::{22 CollectionId, TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData,23 budget::Budget, Property,24};25use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};26use sp_runtime::DispatchError;27use sp_std::{vec::Vec, vec};2829use crate::{30 AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,31 SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,32};3334macro_rules! max_weight_of {35 ($($method:ident ($($args:tt)*)),*) => {36 037 $(38 .max(<SelfWeightOf<T>>::$method($($args)*))39 )*40 };41}4243pub struct CommonWeights<T: Config>(PhantomData<T>);44impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {45 fn create_item() -> Weight {46 <SelfWeightOf<T>>::create_item()47 }4849 fn create_multiple_items(amount: u32) -> Weight {50 <SelfWeightOf<T>>::create_multiple_items(amount)51 }5253 fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {54 match call {55 CreateItemExData::RefungibleMultipleOwners(i) => {56 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32)57 }58 CreateItemExData::RefungibleMultipleItems(i) => {59 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)60 }61 _ => 0,62 }63 }6465 fn burn_item() -> Weight {66 max_weight_of!(burn_item_partial(), burn_item_fully())67 }6869 fn set_property() -> Weight {70 <SelfWeightOf<T>>::set_property()71 }7273 fn transfer() -> Weight {74 max_weight_of!(75 transfer_normal(),76 transfer_creating(),77 transfer_removing(),78 transfer_creating_removing()79 )80 }8182 fn approve() -> Weight {83 <SelfWeightOf<T>>::approve()84 }8586 fn transfer_from() -> Weight {87 max_weight_of!(88 transfer_from_normal(),89 transfer_from_creating(),90 transfer_from_removing(),91 transfer_from_creating_removing()92 )93 }9495 fn burn_from() -> Weight {96 <SelfWeightOf<T>>::burn_from()97 }9899 fn set_variable_metadata(bytes: u32) -> Weight {100 <SelfWeightOf<T>>::set_variable_metadata(bytes)101 }102}103104fn map_create_data<T: Config>(105 data: up_data_structs::CreateItemData,106 to: &T::CrossAccountId,107) -> Result<CreateRefungibleExData<T::CrossAccountId>, DispatchError> {108 match data {109 up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateRefungibleExData {110 const_data: data.const_data,111 variable_data: data.variable_data,112 users: {113 let mut out = BTreeMap::new();114 out.insert(to.clone(), data.pieces);115 out.try_into().expect("limit > 0")116 },117 }),118 _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),119 }120}121122impl<T: Config> CommonCollectionOperations<T> for RefungibleHandle<T> {123 fn create_item(124 &self,125 sender: T::CrossAccountId,126 to: T::CrossAccountId,127 data: up_data_structs::CreateItemData,128 nesting_budget: &dyn Budget,129 ) -> DispatchResultWithPostInfo {130 with_weight(131 <Pallet<T>>::create_item(132 self,133 &sender,134 map_create_data::<T>(data, &to)?,135 nesting_budget,136 ),137 <CommonWeights<T>>::create_item(),138 )139 }140141 fn create_multiple_items(142 &self,143 sender: T::CrossAccountId,144 to: T::CrossAccountId,145 data: Vec<up_data_structs::CreateItemData>,146 nesting_budget: &dyn Budget,147 ) -> DispatchResultWithPostInfo {148 let data = data149 .into_iter()150 .map(|d| map_create_data::<T>(d, &to))151 .collect::<Result<Vec<_>, DispatchError>>()?;152153 let amount = data.len();154 with_weight(155 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),156 <CommonWeights<T>>::create_multiple_items(amount as u32),157 )158 }159160 fn create_multiple_items_ex(161 &self,162 sender: <T>::CrossAccountId,163 data: CreateItemExData<T::CrossAccountId>,164 nesting_budget: &dyn Budget,165 ) -> DispatchResultWithPostInfo {166 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);167 let data = match data {168 CreateItemExData::RefungibleMultipleOwners(r) => vec![r],169 CreateItemExData::RefungibleMultipleItems(r)170 if r.iter().all(|i| i.users.len() == 1) =>171 {172 r.into_inner()173 }174 _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),175 };176177 with_weight(178 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),179 weight,180 )181 }182183 fn burn_item(184 &self,185 sender: T::CrossAccountId,186 token: TokenId,187 amount: u128,188 ) -> DispatchResultWithPostInfo {189 with_weight(190 <Pallet<T>>::burn(self, &sender, token, amount),191 <CommonWeights<T>>::burn_item(),192 )193 }194195 fn transfer(196 &self,197 from: T::CrossAccountId,198 to: T::CrossAccountId,199 token: TokenId,200 amount: u128,201 nesting_budget: &dyn Budget,202 ) -> DispatchResultWithPostInfo {203 with_weight(204 <Pallet<T>>::transfer(self, &from, &to, token, amount, nesting_budget),205 <CommonWeights<T>>::transfer(),206 )207 }208209 fn approve(210 &self,211 sender: T::CrossAccountId,212 spender: T::CrossAccountId,213 token: TokenId,214 amount: u128,215 ) -> DispatchResultWithPostInfo {216 with_weight(217 <Pallet<T>>::set_allowance(self, &sender, &spender, token, amount),218 <CommonWeights<T>>::approve(),219 )220 }221222 fn transfer_from(223 &self,224 sender: T::CrossAccountId,225 from: T::CrossAccountId,226 to: T::CrossAccountId,227 token: TokenId,228 amount: u128,229 nesting_budget: &dyn Budget,230 ) -> DispatchResultWithPostInfo {231 with_weight(232 <Pallet<T>>::transfer_from(self, &sender, &from, &to, token, amount, nesting_budget),233 <CommonWeights<T>>::transfer_from(),234 )235 }236237 fn burn_from(238 &self,239 sender: T::CrossAccountId,240 from: T::CrossAccountId,241 token: TokenId,242 amount: u128,243 nesting_budget: &dyn Budget,244 ) -> DispatchResultWithPostInfo {245 with_weight(246 <Pallet<T>>::burn_from(self, &sender, &from, token, amount, nesting_budget),247 <CommonWeights<T>>::burn_from(),248 )249 }250251 fn change_collection_property(252 &self,253 _sender: T::CrossAccountId,254 _property: Property,255 ) -> DispatchResultWithPostInfo {256 fail!(<Error<T>>::PropertiesNotAllowed)257 }258259 fn change_token_property(260 &self,261 _sender: T::CrossAccountId,262 _token_id: TokenId,263 _property: Property,264 ) -> DispatchResultWithPostInfo {265 fail!(<Error<T>>::PropertiesNotAllowed)266 }267268 fn set_variable_metadata(269 &self,270 sender: T::CrossAccountId,271 token: TokenId,272 data: BoundedVec<u8, CustomDataLimit>,273 ) -> DispatchResultWithPostInfo {274 let len = data.len();275 with_weight(276 <Pallet<T>>::set_variable_metadata(self, &sender, token, data),277 <CommonWeights<T>>::set_variable_metadata(len as u32),278 )279 }280281 fn check_nesting(282 &self,283 _sender: <T>::CrossAccountId,284 _from: (CollectionId, TokenId),285 _under: TokenId,286 _budget: &dyn Budget,287 ) -> sp_runtime::DispatchResult {288 fail!(<Error<T>>::RefungibleDisallowsNesting)289 }290291 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {292 <Owned<T>>::iter_prefix((self.id, account))293 .map(|(id, _)| id)294 .collect()295 }296297 fn collection_tokens(&self) -> Vec<TokenId> {298 <TokenData<T>>::iter_prefix((self.id,))299 .map(|(id, _)| id)300 .collect()301 }302303 fn token_exists(&self, token: TokenId) -> bool {304 <Pallet<T>>::token_exists(self, token)305 }306307 fn last_token_id(&self) -> TokenId {308 TokenId(<TokensMinted<T>>::get(self.id))309 }310311 fn token_owner(&self, _token: TokenId) -> Option<T::CrossAccountId> {312 None313 }314 fn const_metadata(&self, token: TokenId) -> Vec<u8> {315 <TokenData<T>>::get((self.id, token))316 .const_data317 .into_inner()318 }319 fn variable_metadata(&self, token: TokenId) -> Vec<u8> {320 <TokenData<T>>::get((self.id, token))321 .variable_data322 .into_inner()323 }324325 fn total_supply(&self) -> u32 {326 <Pallet<T>>::total_supply(self)327 }328329 fn account_balance(&self, account: T::CrossAccountId) -> u32 {330 <AccountBalance<T>>::get((self.id, account))331 }332333 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {334 <Balance<T>>::get((self.id, token, account))335 }336337 fn allowance(338 &self,339 sender: T::CrossAccountId,340 spender: T::CrossAccountId,341 token: TokenId,342 ) -> u128 {343 <Allowance<T>>::get((self.id, token, sender, spender))344 }345}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 sp_std::collections::btree_map::BTreeMap;20use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};21use up_data_structs::{22 CollectionId, TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData,23 budget::Budget, Property,24};25use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};26use sp_runtime::DispatchError;27use sp_std::{vec::Vec, vec};2829use crate::{30 AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,31 SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,32};3334macro_rules! max_weight_of {35 ($($method:ident ($($args:tt)*)),*) => {36 037 $(38 .max(<SelfWeightOf<T>>::$method($($args)*))39 )*40 };41}4243pub struct CommonWeights<T: Config>(PhantomData<T>);44impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {45 fn create_item() -> Weight {46 <SelfWeightOf<T>>::create_item()47 }4849 fn create_multiple_items(amount: u32) -> Weight {50 <SelfWeightOf<T>>::create_multiple_items(amount)51 }5253 fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {54 match call {55 CreateItemExData::RefungibleMultipleOwners(i) => {56 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32)57 }58 CreateItemExData::RefungibleMultipleItems(i) => {59 <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)60 }61 _ => 0,62 }63 }6465 fn burn_item() -> Weight {66 max_weight_of!(burn_item_partial(), burn_item_fully())67 }6869 fn change_collection_properties(amount: u32) -> Weight {70 <SelfWeightOf<T>>::change_collection_properties(amount)71 }7273 fn change_token_properties(amount: u32) -> Weight {74 <SelfWeightOf<T>>::change_token_properties(amount)75 }7677 fn transfer() -> Weight {78 max_weight_of!(79 transfer_normal(),80 transfer_creating(),81 transfer_removing(),82 transfer_creating_removing()83 )84 }8586 fn approve() -> Weight {87 <SelfWeightOf<T>>::approve()88 }8990 fn transfer_from() -> Weight {91 max_weight_of!(92 transfer_from_normal(),93 transfer_from_creating(),94 transfer_from_removing(),95 transfer_from_creating_removing()96 )97 }9899 fn burn_from() -> Weight {100 <SelfWeightOf<T>>::burn_from()101 }102103 fn set_variable_metadata(bytes: u32) -> Weight {104 <SelfWeightOf<T>>::set_variable_metadata(bytes)105 }106}107108fn map_create_data<T: Config>(109 data: up_data_structs::CreateItemData,110 to: &T::CrossAccountId,111) -> Result<CreateRefungibleExData<T::CrossAccountId>, DispatchError> {112 match data {113 up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateRefungibleExData {114 const_data: data.const_data,115 variable_data: data.variable_data,116 users: {117 let mut out = BTreeMap::new();118 out.insert(to.clone(), data.pieces);119 out.try_into().expect("limit > 0")120 },121 }),122 _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),123 }124}125126impl<T: Config> CommonCollectionOperations<T> for RefungibleHandle<T> {127 fn create_item(128 &self,129 sender: T::CrossAccountId,130 to: T::CrossAccountId,131 data: up_data_structs::CreateItemData,132 nesting_budget: &dyn Budget,133 ) -> DispatchResultWithPostInfo {134 with_weight(135 <Pallet<T>>::create_item(136 self,137 &sender,138 map_create_data::<T>(data, &to)?,139 nesting_budget,140 ),141 <CommonWeights<T>>::create_item(),142 )143 }144145 fn create_multiple_items(146 &self,147 sender: T::CrossAccountId,148 to: T::CrossAccountId,149 data: Vec<up_data_structs::CreateItemData>,150 nesting_budget: &dyn Budget,151 ) -> DispatchResultWithPostInfo {152 let data = data153 .into_iter()154 .map(|d| map_create_data::<T>(d, &to))155 .collect::<Result<Vec<_>, DispatchError>>()?;156157 let amount = data.len();158 with_weight(159 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),160 <CommonWeights<T>>::create_multiple_items(amount as u32),161 )162 }163164 fn create_multiple_items_ex(165 &self,166 sender: <T>::CrossAccountId,167 data: CreateItemExData<T::CrossAccountId>,168 nesting_budget: &dyn Budget,169 ) -> DispatchResultWithPostInfo {170 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);171 let data = match data {172 CreateItemExData::RefungibleMultipleOwners(r) => vec![r],173 CreateItemExData::RefungibleMultipleItems(r)174 if r.iter().all(|i| i.users.len() == 1) =>175 {176 r.into_inner()177 }178 _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),179 };180181 with_weight(182 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),183 weight,184 )185 }186187 fn burn_item(188 &self,189 sender: T::CrossAccountId,190 token: TokenId,191 amount: u128,192 ) -> DispatchResultWithPostInfo {193 with_weight(194 <Pallet<T>>::burn(self, &sender, token, amount),195 <CommonWeights<T>>::burn_item(),196 )197 }198199 fn transfer(200 &self,201 from: T::CrossAccountId,202 to: T::CrossAccountId,203 token: TokenId,204 amount: u128,205 nesting_budget: &dyn Budget,206 ) -> DispatchResultWithPostInfo {207 with_weight(208 <Pallet<T>>::transfer(self, &from, &to, token, amount, nesting_budget),209 <CommonWeights<T>>::transfer(),210 )211 }212213 fn approve(214 &self,215 sender: T::CrossAccountId,216 spender: T::CrossAccountId,217 token: TokenId,218 amount: u128,219 ) -> DispatchResultWithPostInfo {220 with_weight(221 <Pallet<T>>::set_allowance(self, &sender, &spender, token, amount),222 <CommonWeights<T>>::approve(),223 )224 }225226 fn transfer_from(227 &self,228 sender: T::CrossAccountId,229 from: T::CrossAccountId,230 to: T::CrossAccountId,231 token: TokenId,232 amount: u128,233 nesting_budget: &dyn Budget,234 ) -> DispatchResultWithPostInfo {235 with_weight(236 <Pallet<T>>::transfer_from(self, &sender, &from, &to, token, amount, nesting_budget),237 <CommonWeights<T>>::transfer_from(),238 )239 }240241 fn burn_from(242 &self,243 sender: T::CrossAccountId,244 from: T::CrossAccountId,245 token: TokenId,246 amount: u128,247 nesting_budget: &dyn Budget,248 ) -> DispatchResultWithPostInfo {249 with_weight(250 <Pallet<T>>::burn_from(self, &sender, &from, token, amount, nesting_budget),251 <CommonWeights<T>>::burn_from(),252 )253 }254255 fn change_collection_properties(256 &self,257 _sender: T::CrossAccountId,258 _property: Vec<Property>,259 ) -> DispatchResultWithPostInfo {260 fail!(<Error<T>>::PropertiesNotAllowed)261 }262263 fn change_token_properties(264 &self,265 _sender: T::CrossAccountId,266 _token_id: TokenId,267 _property: Vec<Property>,268 ) -> DispatchResultWithPostInfo {269 fail!(<Error<T>>::PropertiesNotAllowed)270 }271272 fn set_variable_metadata(273 &self,274 sender: T::CrossAccountId,275 token: TokenId,276 data: BoundedVec<u8, CustomDataLimit>,277 ) -> DispatchResultWithPostInfo {278 let len = data.len();279 with_weight(280 <Pallet<T>>::set_variable_metadata(self, &sender, token, data),281 <CommonWeights<T>>::set_variable_metadata(len as u32),282 )283 }284285 fn check_nesting(286 &self,287 _sender: <T>::CrossAccountId,288 _from: (CollectionId, TokenId),289 _under: TokenId,290 _budget: &dyn Budget,291 ) -> sp_runtime::DispatchResult {292 fail!(<Error<T>>::RefungibleDisallowsNesting)293 }294295 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {296 <Owned<T>>::iter_prefix((self.id, account))297 .map(|(id, _)| id)298 .collect()299 }300301 fn collection_tokens(&self) -> Vec<TokenId> {302 <TokenData<T>>::iter_prefix((self.id,))303 .map(|(id, _)| id)304 .collect()305 }306307 fn token_exists(&self, token: TokenId) -> bool {308 <Pallet<T>>::token_exists(self, token)309 }310311 fn last_token_id(&self) -> TokenId {312 TokenId(<TokensMinted<T>>::get(self.id))313 }314315 fn token_owner(&self, _token: TokenId) -> Option<T::CrossAccountId> {316 None317 }318 fn const_metadata(&self, token: TokenId) -> Vec<u8> {319 <TokenData<T>>::get((self.id, token))320 .const_data321 .into_inner()322 }323 fn variable_metadata(&self, token: TokenId) -> Vec<u8> {324 <TokenData<T>>::get((self.id, token))325 .variable_data326 .into_inner()327 }328329 fn total_supply(&self) -> u32 {330 <Pallet<T>>::total_supply(self)331 }332333 fn account_balance(&self, account: T::CrossAccountId) -> u32 {334 <AccountBalance<T>>::get((self.id, account))335 }336337 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {338 <Balance<T>>::get((self.id, token, account))339 }340341 fn allowance(342 &self,343 sender: T::CrossAccountId,344 spender: T::CrossAccountId,345 token: TokenId,346 ) -> u128 {347 <Allowance<T>>::get((self.id, token, sender, spender))348 }349}pallets/refungible/src/weights.rsdiffbeforeafterboth--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -38,7 +38,8 @@
fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight;
fn burn_item_partial() -> Weight;
fn burn_item_fully() -> Weight;
- fn set_property() -> Weight;
+ fn change_collection_properties(amount: u32) -> Weight;
+ fn change_token_properties(amount: u32) -> Weight;
fn transfer_normal() -> Weight;
fn transfer_creating() -> Weight;
fn transfer_removing() -> Weight;
@@ -131,11 +132,16 @@
.saturating_add(T::DbWeight::get().writes(6 as Weight))
}
- fn set_property() -> Weight {
+ fn change_collection_properties(amount: u32) -> Weight {
// Error
0
}
+ fn change_token_properties(amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
// Storage: Refungible Balance (r:2 w:2)
fn transfer_normal() -> Weight {
(19_766_000 as Weight)
@@ -305,7 +311,12 @@
.saturating_add(RocksDbWeight::get().writes(6 as Weight))
}
- fn set_property() -> Weight {
+ fn change_collection_properties(amount: u32) -> Weight {
+ // Error
+ 0
+ }
+
+ fn change_token_properties(amount: u32) -> Weight {
// Error
0
}
pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -694,6 +694,35 @@
dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))
}
+ #[weight = T::CommonWeightInfo::change_collection_properties(properties.len() as u32)]
+ #[transactional]
+ pub fn change_collection_properties(
+ origin,
+ collection_id: CollectionId,
+ properties: Vec<Property>
+ ) -> DispatchResultWithPostInfo {
+ ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);
+
+ let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+
+ dispatch_call::<T, _>(collection_id, |d| d.change_collection_properties(sender, properties))
+ }
+
+ #[weight = T::CommonWeightInfo::change_token_properties(properties.len() as u32)]
+ #[transactional]
+ pub fn change_token_properties(
+ origin,
+ collection_id: CollectionId,
+ token_id: TokenId,
+ properties: Vec<Property>
+ ) -> DispatchResultWithPostInfo {
+ ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);
+
+ let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+
+ dispatch_call::<T, _>(collection_id, |d| d.change_token_properties(sender, token_id, properties))
+ }
+
#[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]
#[transactional]
pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {
runtime/common/src/weights.rsdiffbeforeafterboth--- a/runtime/common/src/weights.rs
+++ b/runtime/common/src/weights.rs
@@ -54,8 +54,12 @@
dispatch_weight::<T>() + max_weight_of!(burn_item())
}
- fn set_property() -> Weight {
- dispatch_weight::<T>() + max_weight_of!(set_property())
+ fn change_collection_properties(amount: u32) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(change_collection_properties(amount))
+ }
+
+ fn change_token_properties(amount: u32) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(change_token_properties(amount))
}
fn transfer() -> Weight {