difftreelog
Rename property change to set
in: master
11 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -731,7 +731,7 @@
Ok(())
}
- pub fn change_collection_property(
+ pub fn set_collection_property(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
property: Property,
@@ -740,7 +740,7 @@
CollectionProperties::<T>::try_mutate(
collection.id,
- |properties| properties.try_change_property(property.clone())
+ |properties| properties.try_set_property(property.clone())
)?;
Self::deposit_event(Event::CollectionPropertySet(collection.id, property));
@@ -748,19 +748,19 @@
Ok(())
}
- pub fn change_collection_properties(
+ pub fn set_collection_properties(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
properties: Vec<Property>,
) -> DispatchResult {
for property in properties {
- Self::change_collection_property(collection, sender, property)?;
+ Self::set_collection_property(collection, sender, property)?;
}
Ok(())
}
- pub fn change_property_permission(
+ pub fn set_property_permission(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
property_permission: PropertyKeyPermission
@@ -784,13 +784,13 @@
Ok(())
}
- pub fn change_property_permissions(
+ pub fn set_property_permissions(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
property_permissions: Vec<PropertyKeyPermission>
) -> DispatchResult {
for prop_pemission in property_permissions {
- Self::change_property_permission(collection, sender, prop_pemission)?;
+ Self::set_property_permission(collection, sender, prop_pemission)?;
}
Ok(())
@@ -948,9 +948,9 @@
fn create_multiple_items(amount: u32) -> Weight;
fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;
fn burn_item() -> Weight;
- fn change_collection_properties(amount: u32) -> Weight;
- fn change_token_properties(amount: u32) -> Weight;
- fn change_property_permissions(amount: u32) -> Weight;
+ fn set_collection_properties(amount: u32) -> Weight;
+ fn set_token_properties(amount: u32) -> Weight;
+ fn set_property_permissions(amount: u32) -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
fn transfer_from() -> Weight;
@@ -985,18 +985,18 @@
token: TokenId,
amount: u128,
) -> DispatchResultWithPostInfo;
- fn change_collection_properties(
+ fn set_collection_properties(
&self,
sender: T::CrossAccountId,
properties: Vec<Property>,
) -> DispatchResultWithPostInfo;
- fn change_token_properties(
+ fn set_token_properties(
&self,
sender: T::CrossAccountId,
token_id: TokenId,
property: Vec<Property>,
) -> DispatchResultWithPostInfo;
- fn change_property_permissions(
+ fn set_property_permissions(
&self,
sender: &T::CrossAccountId,
property_permissions: Vec<PropertyKeyPermission>,
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -50,16 +50,16 @@
<SelfWeightOf<T>>::burn_item()
}
- fn change_collection_properties(amount: u32) -> Weight {
- <SelfWeightOf<T>>::change_collection_properties(amount)
+ fn set_collection_properties(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::set_collection_properties(amount)
}
- fn change_token_properties(amount: u32) -> Weight {
- <SelfWeightOf<T>>::change_token_properties(amount)
+ fn set_token_properties(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::set_token_properties(amount)
}
- fn change_property_permissions(amount: u32) -> Weight {
- <SelfWeightOf<T>>::change_property_permissions(amount)
+ fn set_property_permissions(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::set_property_permissions(amount)
}
fn transfer() -> Weight {
@@ -237,7 +237,7 @@
)
}
- fn change_collection_properties(
+ fn set_collection_properties(
&self,
_sender: T::CrossAccountId,
_property: Vec<Property>,
@@ -245,7 +245,7 @@
fail!(<Error<T>>::PropertiesNotAllowed)
}
- fn change_token_properties(
+ fn set_token_properties(
&self,
_sender: T::CrossAccountId,
_token_id: TokenId,
@@ -254,7 +254,7 @@
fail!(<Error<T>>::PropertiesNotAllowed)
}
- fn change_property_permissions(
+ fn set_property_permissions(
&self,
_sender: &T::CrossAccountId,
_property_permissions: Vec<PropertyKeyPermission>,
pallets/fungible/src/weights.rsdiffbeforeafterboth--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -35,9 +35,9 @@
fn create_item() -> Weight;
fn create_multiple_items_ex(b: u32, ) -> Weight;
fn burn_item() -> Weight;
- fn change_collection_properties(amount: u32) -> Weight;
- fn change_token_properties(amount: u32) -> Weight;
- fn change_property_permissions(amount: u32) -> Weight;
+ fn set_collection_properties(amount: u32) -> Weight;
+ fn set_token_properties(amount: u32) -> Weight;
+ fn set_property_permissions(amount: u32) -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
fn transfer_from() -> Weight;
@@ -73,17 +73,17 @@
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
- fn change_collection_properties(amount: u32) -> Weight {
+ fn set_collection_properties(amount: u32) -> Weight {
// Error
0
}
- fn change_token_properties(amount: u32) -> Weight {
+ fn set_token_properties(amount: u32) -> Weight {
// Error
0
}
- fn change_property_permissions(amount: u32) -> Weight {
+ fn set_property_permissions(amount: u32) -> Weight {
// Error
0
}
@@ -146,17 +146,17 @@
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
- fn change_collection_properties(amount: u32) -> Weight {
+ fn set_collection_properties(amount: u32) -> Weight {
// Error
0
}
- fn change_token_properties(amount: u32) -> Weight {
+ fn set_token_properties(amount: u32) -> Weight {
// Error
0
}
- fn change_property_permissions(amount: u32) -> Weight {
+ fn set_property_permissions(amount: u32) -> Weight {
// Error
0
}
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -50,16 +50,16 @@
<SelfWeightOf<T>>::burn_item()
}
- fn change_collection_properties(amount: u32) -> Weight {
- <SelfWeightOf<T>>::change_collection_properties(amount)
+ fn set_collection_properties(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::set_collection_properties(amount)
}
- fn change_token_properties(amount: u32) -> Weight {
- <SelfWeightOf<T>>::change_token_properties(amount)
+ fn set_token_properties(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::set_token_properties(amount)
}
- fn change_property_permissions(amount: u32) -> Weight {
- <SelfWeightOf<T>>::change_property_permissions(amount)
+ fn set_property_permissions(amount: u32) -> Weight {
+ <SelfWeightOf<T>>::set_property_permissions(amount)
}
fn transfer() -> Weight {
@@ -153,42 +153,42 @@
)
}
- fn change_collection_properties(
+ fn set_collection_properties(
&self,
sender: T::CrossAccountId,
properties: Vec<Property>,
) -> DispatchResultWithPostInfo {
- let weight = <CommonWeights<T>>::change_collection_properties(properties.len() as u32);
+ let weight = <CommonWeights<T>>::set_collection_properties(properties.len() as u32);
with_weight(
- <Pallet<T>>::change_collection_properties(self, &sender, properties),
+ <Pallet<T>>::set_collection_properties(self, &sender, properties),
weight
)
}
- fn change_token_properties(
+ fn set_token_properties(
&self,
sender: T::CrossAccountId,
token_id: TokenId,
properties: Vec<Property>,
) -> DispatchResultWithPostInfo {
- let weight = <CommonWeights<T>>::change_token_properties(properties.len() as u32);
+ let weight = <CommonWeights<T>>::set_token_properties(properties.len() as u32);
with_weight(
- <Pallet<T>>::change_token_properties(self, &sender, token_id, properties),
+ <Pallet<T>>::set_token_properties(self, &sender, token_id, properties),
weight
)
}
- fn change_property_permissions(
+ fn set_property_permissions(
&self,
sender: &T::CrossAccountId,
property_permissions: Vec<PropertyKeyPermission>,
) -> DispatchResultWithPostInfo {
- let weight = <CommonWeights<T>>::change_property_permissions(property_permissions.len() as u32);
+ let weight = <CommonWeights<T>>::set_property_permissions(property_permissions.len() as u32);
with_weight(
- <Pallet<T>>::change_property_permissions(self, sender, property_permissions),
+ <Pallet<T>>::set_property_permissions(self, sender, property_permissions),
weight
)
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -255,7 +255,7 @@
Ok(())
}
- pub fn change_token_property(
+ pub fn set_token_property(
collection: &NonfungibleHandle<T>,
sender: &T::CrossAccountId,
token_id: TokenId,
@@ -292,7 +292,7 @@
}
<TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
- properties.try_change_property(property.clone())
+ properties.try_set_property(property.clone())
})?;
<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(
@@ -304,33 +304,33 @@
Ok(())
}
- pub fn change_token_properties(
+ pub fn set_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)?;
+ Self::set_token_property(collection, sender, token_id, property)?;
}
Ok(())
}
- pub fn change_collection_properties(
+ pub fn set_collection_properties(
collection: &NonfungibleHandle<T>,
sender: &T::CrossAccountId,
properties: Vec<Property>,
) -> DispatchResult {
- <PalletCommon<T>>::change_collection_properties(collection, sender, properties)
+ <PalletCommon<T>>::set_collection_properties(collection, sender, properties)
}
- pub fn change_property_permissions(
+ pub fn set_property_permissions(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
property_permissions: Vec<PropertyKeyPermission>
) -> DispatchResult {
- <PalletCommon<T>>::change_property_permissions(
+ <PalletCommon<T>>::set_property_permissions(
collection,
sender,
property_permissions,
pallets/nonfungible/src/weights.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -36,9 +36,9 @@
fn create_multiple_items(b: u32, ) -> Weight;
fn create_multiple_items_ex(b: u32, ) -> Weight;
fn burn_item() -> Weight;
- fn change_collection_properties(amount: u32) -> Weight;
- fn change_token_properties(amount: u32) -> Weight;
- fn change_property_permissions(amount: u32) -> Weight;
+ fn set_collection_properties(amount: u32) -> Weight;
+ fn set_token_properties(amount: u32) -> Weight;
+ fn set_property_permissions(amount: u32) -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
fn transfer_from() -> Weight;
@@ -94,17 +94,17 @@
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
- fn change_collection_properties(amount: u32) -> Weight {
+ fn set_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 {
+ fn set_token_properties(amount: u32) -> Weight {
// TODO calculate appropriate weight
(50_000_000 as Weight).saturating_mul(amount as Weight)
}
- fn change_property_permissions(amount: u32) -> Weight {
+ fn set_property_permissions(amount: u32) -> Weight {
// TODO calculate appropriate weight
(50_000_000 as Weight).saturating_mul(amount as Weight)
}
@@ -199,17 +199,17 @@
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
}
- fn change_collection_properties(amount: u32) -> Weight {
+ fn set_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 {
+ fn set_token_properties(amount: u32) -> Weight {
// TODO calculate appropriate weight
(50_000_000 as Weight).saturating_mul(amount as Weight)
}
- fn change_property_permissions(amount: u32) -> Weight {
+ fn set_property_permissions(amount: u32) -> Weight {
// TODO calculate appropriate weight
(50_000_000 as Weight).saturating_mul(amount as Weight)
}
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, PropertyKeyPermission,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 change_property_permissions(amount: u32) -> Weight {78 <SelfWeightOf<T>>::change_property_permissions(amount)79 }8081 fn transfer() -> Weight {82 max_weight_of!(83 transfer_normal(),84 transfer_creating(),85 transfer_removing(),86 transfer_creating_removing()87 )88 }8990 fn approve() -> Weight {91 <SelfWeightOf<T>>::approve()92 }9394 fn transfer_from() -> Weight {95 max_weight_of!(96 transfer_from_normal(),97 transfer_from_creating(),98 transfer_from_removing(),99 transfer_from_creating_removing()100 )101 }102103 fn burn_from() -> Weight {104 <SelfWeightOf<T>>::burn_from()105 }106107 fn set_variable_metadata(bytes: u32) -> Weight {108 <SelfWeightOf<T>>::set_variable_metadata(bytes)109 }110}111112fn map_create_data<T: Config>(113 data: up_data_structs::CreateItemData,114 to: &T::CrossAccountId,115) -> Result<CreateRefungibleExData<T::CrossAccountId>, DispatchError> {116 match data {117 up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateRefungibleExData {118 const_data: data.const_data,119 variable_data: data.variable_data,120 users: {121 let mut out = BTreeMap::new();122 out.insert(to.clone(), data.pieces);123 out.try_into().expect("limit > 0")124 },125 }),126 _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),127 }128}129130impl<T: Config> CommonCollectionOperations<T> for RefungibleHandle<T> {131 fn create_item(132 &self,133 sender: T::CrossAccountId,134 to: T::CrossAccountId,135 data: up_data_structs::CreateItemData,136 nesting_budget: &dyn Budget,137 ) -> DispatchResultWithPostInfo {138 with_weight(139 <Pallet<T>>::create_item(140 self,141 &sender,142 map_create_data::<T>(data, &to)?,143 nesting_budget,144 ),145 <CommonWeights<T>>::create_item(),146 )147 }148149 fn create_multiple_items(150 &self,151 sender: T::CrossAccountId,152 to: T::CrossAccountId,153 data: Vec<up_data_structs::CreateItemData>,154 nesting_budget: &dyn Budget,155 ) -> DispatchResultWithPostInfo {156 let data = data157 .into_iter()158 .map(|d| map_create_data::<T>(d, &to))159 .collect::<Result<Vec<_>, DispatchError>>()?;160161 let amount = data.len();162 with_weight(163 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),164 <CommonWeights<T>>::create_multiple_items(amount as u32),165 )166 }167168 fn create_multiple_items_ex(169 &self,170 sender: <T>::CrossAccountId,171 data: CreateItemExData<T::CrossAccountId>,172 nesting_budget: &dyn Budget,173 ) -> DispatchResultWithPostInfo {174 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);175 let data = match data {176 CreateItemExData::RefungibleMultipleOwners(r) => vec![r],177 CreateItemExData::RefungibleMultipleItems(r)178 if r.iter().all(|i| i.users.len() == 1) =>179 {180 r.into_inner()181 }182 _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),183 };184185 with_weight(186 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),187 weight,188 )189 }190191 fn burn_item(192 &self,193 sender: T::CrossAccountId,194 token: TokenId,195 amount: u128,196 ) -> DispatchResultWithPostInfo {197 with_weight(198 <Pallet<T>>::burn(self, &sender, token, amount),199 <CommonWeights<T>>::burn_item(),200 )201 }202203 fn transfer(204 &self,205 from: T::CrossAccountId,206 to: T::CrossAccountId,207 token: TokenId,208 amount: u128,209 nesting_budget: &dyn Budget,210 ) -> DispatchResultWithPostInfo {211 with_weight(212 <Pallet<T>>::transfer(self, &from, &to, token, amount, nesting_budget),213 <CommonWeights<T>>::transfer(),214 )215 }216217 fn approve(218 &self,219 sender: T::CrossAccountId,220 spender: T::CrossAccountId,221 token: TokenId,222 amount: u128,223 ) -> DispatchResultWithPostInfo {224 with_weight(225 <Pallet<T>>::set_allowance(self, &sender, &spender, token, amount),226 <CommonWeights<T>>::approve(),227 )228 }229230 fn transfer_from(231 &self,232 sender: T::CrossAccountId,233 from: T::CrossAccountId,234 to: T::CrossAccountId,235 token: TokenId,236 amount: u128,237 nesting_budget: &dyn Budget,238 ) -> DispatchResultWithPostInfo {239 with_weight(240 <Pallet<T>>::transfer_from(self, &sender, &from, &to, token, amount, nesting_budget),241 <CommonWeights<T>>::transfer_from(),242 )243 }244245 fn burn_from(246 &self,247 sender: T::CrossAccountId,248 from: T::CrossAccountId,249 token: TokenId,250 amount: u128,251 nesting_budget: &dyn Budget,252 ) -> DispatchResultWithPostInfo {253 with_weight(254 <Pallet<T>>::burn_from(self, &sender, &from, token, amount, nesting_budget),255 <CommonWeights<T>>::burn_from(),256 )257 }258259 fn change_collection_properties(260 &self,261 _sender: T::CrossAccountId,262 _property: Vec<Property>,263 ) -> DispatchResultWithPostInfo {264 fail!(<Error<T>>::PropertiesNotAllowed)265 }266267 fn change_token_properties(268 &self,269 _sender: T::CrossAccountId,270 _token_id: TokenId,271 _property: Vec<Property>,272 ) -> DispatchResultWithPostInfo {273 fail!(<Error<T>>::PropertiesNotAllowed)274 }275276 fn change_property_permissions(277 &self,278 _sender: &T::CrossAccountId,279 _property_permissions: Vec<PropertyKeyPermission>,280 ) -> DispatchResultWithPostInfo {281 fail!(<Error<T>>::PropertiesNotAllowed)282 }283284 fn set_variable_metadata(285 &self,286 sender: T::CrossAccountId,287 token: TokenId,288 data: BoundedVec<u8, CustomDataLimit>,289 ) -> DispatchResultWithPostInfo {290 let len = data.len();291 with_weight(292 <Pallet<T>>::set_variable_metadata(self, &sender, token, data),293 <CommonWeights<T>>::set_variable_metadata(len as u32),294 )295 }296297 fn check_nesting(298 &self,299 _sender: <T>::CrossAccountId,300 _from: (CollectionId, TokenId),301 _under: TokenId,302 _budget: &dyn Budget,303 ) -> sp_runtime::DispatchResult {304 fail!(<Error<T>>::RefungibleDisallowsNesting)305 }306307 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {308 <Owned<T>>::iter_prefix((self.id, account))309 .map(|(id, _)| id)310 .collect()311 }312313 fn collection_tokens(&self) -> Vec<TokenId> {314 <TokenData<T>>::iter_prefix((self.id,))315 .map(|(id, _)| id)316 .collect()317 }318319 fn token_exists(&self, token: TokenId) -> bool {320 <Pallet<T>>::token_exists(self, token)321 }322323 fn last_token_id(&self) -> TokenId {324 TokenId(<TokensMinted<T>>::get(self.id))325 }326327 fn token_owner(&self, _token: TokenId) -> Option<T::CrossAccountId> {328 None329 }330 fn const_metadata(&self, token: TokenId) -> Vec<u8> {331 <TokenData<T>>::get((self.id, token))332 .const_data333 .into_inner()334 }335 fn variable_metadata(&self, token: TokenId) -> Vec<u8> {336 <TokenData<T>>::get((self.id, token))337 .variable_data338 .into_inner()339 }340341 fn total_supply(&self) -> u32 {342 <Pallet<T>>::total_supply(self)343 }344345 fn account_balance(&self, account: T::CrossAccountId) -> u32 {346 <AccountBalance<T>>::get((self.id, account))347 }348349 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {350 <Balance<T>>::get((self.id, token, account))351 }352353 fn allowance(354 &self,355 sender: T::CrossAccountId,356 spender: T::CrossAccountId,357 token: TokenId,358 ) -> u128 {359 <Allowance<T>>::get((self.id, token, sender, spender))360 }361}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, PropertyKeyPermission,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_collection_properties(amount: u32) -> Weight {70 <SelfWeightOf<T>>::set_collection_properties(amount)71 }7273 fn set_token_properties(amount: u32) -> Weight {74 <SelfWeightOf<T>>::set_token_properties(amount)75 }7677 fn set_property_permissions(amount: u32) -> Weight {78 <SelfWeightOf<T>>::set_property_permissions(amount)79 }8081 fn transfer() -> Weight {82 max_weight_of!(83 transfer_normal(),84 transfer_creating(),85 transfer_removing(),86 transfer_creating_removing()87 )88 }8990 fn approve() -> Weight {91 <SelfWeightOf<T>>::approve()92 }9394 fn transfer_from() -> Weight {95 max_weight_of!(96 transfer_from_normal(),97 transfer_from_creating(),98 transfer_from_removing(),99 transfer_from_creating_removing()100 )101 }102103 fn burn_from() -> Weight {104 <SelfWeightOf<T>>::burn_from()105 }106107 fn set_variable_metadata(bytes: u32) -> Weight {108 <SelfWeightOf<T>>::set_variable_metadata(bytes)109 }110}111112fn map_create_data<T: Config>(113 data: up_data_structs::CreateItemData,114 to: &T::CrossAccountId,115) -> Result<CreateRefungibleExData<T::CrossAccountId>, DispatchError> {116 match data {117 up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateRefungibleExData {118 const_data: data.const_data,119 variable_data: data.variable_data,120 users: {121 let mut out = BTreeMap::new();122 out.insert(to.clone(), data.pieces);123 out.try_into().expect("limit > 0")124 },125 }),126 _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),127 }128}129130impl<T: Config> CommonCollectionOperations<T> for RefungibleHandle<T> {131 fn create_item(132 &self,133 sender: T::CrossAccountId,134 to: T::CrossAccountId,135 data: up_data_structs::CreateItemData,136 nesting_budget: &dyn Budget,137 ) -> DispatchResultWithPostInfo {138 with_weight(139 <Pallet<T>>::create_item(140 self,141 &sender,142 map_create_data::<T>(data, &to)?,143 nesting_budget,144 ),145 <CommonWeights<T>>::create_item(),146 )147 }148149 fn create_multiple_items(150 &self,151 sender: T::CrossAccountId,152 to: T::CrossAccountId,153 data: Vec<up_data_structs::CreateItemData>,154 nesting_budget: &dyn Budget,155 ) -> DispatchResultWithPostInfo {156 let data = data157 .into_iter()158 .map(|d| map_create_data::<T>(d, &to))159 .collect::<Result<Vec<_>, DispatchError>>()?;160161 let amount = data.len();162 with_weight(163 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),164 <CommonWeights<T>>::create_multiple_items(amount as u32),165 )166 }167168 fn create_multiple_items_ex(169 &self,170 sender: <T>::CrossAccountId,171 data: CreateItemExData<T::CrossAccountId>,172 nesting_budget: &dyn Budget,173 ) -> DispatchResultWithPostInfo {174 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);175 let data = match data {176 CreateItemExData::RefungibleMultipleOwners(r) => vec![r],177 CreateItemExData::RefungibleMultipleItems(r)178 if r.iter().all(|i| i.users.len() == 1) =>179 {180 r.into_inner()181 }182 _ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),183 };184185 with_weight(186 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),187 weight,188 )189 }190191 fn burn_item(192 &self,193 sender: T::CrossAccountId,194 token: TokenId,195 amount: u128,196 ) -> DispatchResultWithPostInfo {197 with_weight(198 <Pallet<T>>::burn(self, &sender, token, amount),199 <CommonWeights<T>>::burn_item(),200 )201 }202203 fn transfer(204 &self,205 from: T::CrossAccountId,206 to: T::CrossAccountId,207 token: TokenId,208 amount: u128,209 nesting_budget: &dyn Budget,210 ) -> DispatchResultWithPostInfo {211 with_weight(212 <Pallet<T>>::transfer(self, &from, &to, token, amount, nesting_budget),213 <CommonWeights<T>>::transfer(),214 )215 }216217 fn approve(218 &self,219 sender: T::CrossAccountId,220 spender: T::CrossAccountId,221 token: TokenId,222 amount: u128,223 ) -> DispatchResultWithPostInfo {224 with_weight(225 <Pallet<T>>::set_allowance(self, &sender, &spender, token, amount),226 <CommonWeights<T>>::approve(),227 )228 }229230 fn transfer_from(231 &self,232 sender: T::CrossAccountId,233 from: T::CrossAccountId,234 to: T::CrossAccountId,235 token: TokenId,236 amount: u128,237 nesting_budget: &dyn Budget,238 ) -> DispatchResultWithPostInfo {239 with_weight(240 <Pallet<T>>::transfer_from(self, &sender, &from, &to, token, amount, nesting_budget),241 <CommonWeights<T>>::transfer_from(),242 )243 }244245 fn burn_from(246 &self,247 sender: T::CrossAccountId,248 from: T::CrossAccountId,249 token: TokenId,250 amount: u128,251 nesting_budget: &dyn Budget,252 ) -> DispatchResultWithPostInfo {253 with_weight(254 <Pallet<T>>::burn_from(self, &sender, &from, token, amount, nesting_budget),255 <CommonWeights<T>>::burn_from(),256 )257 }258259 fn set_collection_properties(260 &self,261 _sender: T::CrossAccountId,262 _property: Vec<Property>,263 ) -> DispatchResultWithPostInfo {264 fail!(<Error<T>>::PropertiesNotAllowed)265 }266267 fn set_token_properties(268 &self,269 _sender: T::CrossAccountId,270 _token_id: TokenId,271 _property: Vec<Property>,272 ) -> DispatchResultWithPostInfo {273 fail!(<Error<T>>::PropertiesNotAllowed)274 }275276 fn set_property_permissions(277 &self,278 _sender: &T::CrossAccountId,279 _property_permissions: Vec<PropertyKeyPermission>,280 ) -> DispatchResultWithPostInfo {281 fail!(<Error<T>>::PropertiesNotAllowed)282 }283284 fn set_variable_metadata(285 &self,286 sender: T::CrossAccountId,287 token: TokenId,288 data: BoundedVec<u8, CustomDataLimit>,289 ) -> DispatchResultWithPostInfo {290 let len = data.len();291 with_weight(292 <Pallet<T>>::set_variable_metadata(self, &sender, token, data),293 <CommonWeights<T>>::set_variable_metadata(len as u32),294 )295 }296297 fn check_nesting(298 &self,299 _sender: <T>::CrossAccountId,300 _from: (CollectionId, TokenId),301 _under: TokenId,302 _budget: &dyn Budget,303 ) -> sp_runtime::DispatchResult {304 fail!(<Error<T>>::RefungibleDisallowsNesting)305 }306307 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {308 <Owned<T>>::iter_prefix((self.id, account))309 .map(|(id, _)| id)310 .collect()311 }312313 fn collection_tokens(&self) -> Vec<TokenId> {314 <TokenData<T>>::iter_prefix((self.id,))315 .map(|(id, _)| id)316 .collect()317 }318319 fn token_exists(&self, token: TokenId) -> bool {320 <Pallet<T>>::token_exists(self, token)321 }322323 fn last_token_id(&self) -> TokenId {324 TokenId(<TokensMinted<T>>::get(self.id))325 }326327 fn token_owner(&self, _token: TokenId) -> Option<T::CrossAccountId> {328 None329 }330 fn const_metadata(&self, token: TokenId) -> Vec<u8> {331 <TokenData<T>>::get((self.id, token))332 .const_data333 .into_inner()334 }335 fn variable_metadata(&self, token: TokenId) -> Vec<u8> {336 <TokenData<T>>::get((self.id, token))337 .variable_data338 .into_inner()339 }340341 fn total_supply(&self) -> u32 {342 <Pallet<T>>::total_supply(self)343 }344345 fn account_balance(&self, account: T::CrossAccountId) -> u32 {346 <AccountBalance<T>>::get((self.id, account))347 }348349 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {350 <Balance<T>>::get((self.id, token, account))351 }352353 fn allowance(354 &self,355 sender: T::CrossAccountId,356 spender: T::CrossAccountId,357 token: TokenId,358 ) -> u128 {359 <Allowance<T>>::get((self.id, token, sender, spender))360 }361}pallets/refungible/src/weights.rsdiffbeforeafterboth--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -38,9 +38,9 @@
fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight;
fn burn_item_partial() -> Weight;
fn burn_item_fully() -> Weight;
- fn change_collection_properties(amount: u32) -> Weight;
- fn change_token_properties(amount: u32) -> Weight;
- fn change_property_permissions(amount: u32) -> Weight;
+ fn set_collection_properties(amount: u32) -> Weight;
+ fn set_token_properties(amount: u32) -> Weight;
+ fn set_property_permissions(amount: u32) -> Weight;
fn transfer_normal() -> Weight;
fn transfer_creating() -> Weight;
fn transfer_removing() -> Weight;
@@ -133,17 +133,17 @@
.saturating_add(T::DbWeight::get().writes(6 as Weight))
}
- fn change_collection_properties(amount: u32) -> Weight {
+ fn set_collection_properties(amount: u32) -> Weight {
// Error
0
}
- fn change_token_properties(amount: u32) -> Weight {
+ fn set_token_properties(amount: u32) -> Weight {
// Error
0
}
- fn change_property_permissions(amount: u32) -> Weight {
+ fn set_property_permissions(amount: u32) -> Weight {
// Error
0
}
@@ -317,17 +317,17 @@
.saturating_add(RocksDbWeight::get().writes(6 as Weight))
}
- fn change_collection_properties(amount: u32) -> Weight {
+ fn set_collection_properties(amount: u32) -> Weight {
// Error
0
}
- fn change_token_properties(amount: u32) -> Weight {
+ fn set_token_properties(amount: u32) -> Weight {
// Error
0
}
- fn change_property_permissions(amount: u32) -> Weight {
+ fn set_property_permissions(amount: u32) -> Weight {
// Error
0
}
pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -694,9 +694,9 @@
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)]
+ #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]
#[transactional]
- pub fn change_collection_properties(
+ pub fn set_collection_properties(
origin,
collection_id: CollectionId,
properties: Vec<Property>
@@ -705,12 +705,12 @@
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
- dispatch_call::<T, _>(collection_id, |d| d.change_collection_properties(sender, properties))
+ dispatch_call::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))
}
- #[weight = T::CommonWeightInfo::change_token_properties(properties.len() as u32)]
+ #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]
#[transactional]
- pub fn change_token_properties(
+ pub fn set_token_properties(
origin,
collection_id: CollectionId,
token_id: TokenId,
@@ -720,12 +720,12 @@
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
- dispatch_call::<T, _>(collection_id, |d| d.change_token_properties(sender, token_id, properties))
+ dispatch_call::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties))
}
- #[weight = T::CommonWeightInfo::change_property_permissions(property_permissions.len() as u32)]
+ #[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]
#[transactional]
- pub fn change_property_permissions(
+ pub fn set_property_permissions(
origin,
collection_id: CollectionId,
property_permissions: Vec<PropertyKeyPermission>,
@@ -734,7 +734,7 @@
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
- dispatch_call::<T, _>(collection_id, |d| d.change_property_permissions(&sender, property_permissions))
+ dispatch_call::<T, _>(collection_id, |d| d.set_property_permissions(&sender, property_permissions))
}
#[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]
primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -698,13 +698,13 @@
let mut props = Self::new(MAX_COLLECTION_PROPERTIES_SIZE);
for property in data.into_iter() {
- props.try_change_property(property)?;
+ props.try_set_property(property)?;
}
Ok(props)
}
- pub fn try_change_property(&mut self, property: Property) -> Result<(), PropertiesError> {
+ pub fn try_set_property(&mut self, property: Property) -> Result<(), PropertiesError> {
let value_len = property.value.len();
if self.consumed_space as usize + value_len > self.space_limit as usize {
@@ -740,17 +740,3 @@
Properties::new(MAX_TOKEN_PROPERTIES_SIZE)
}
}
-
-// #[cfg(not(feature = "std"))]
-// fn properties_map_debug(_properties: &PropertiesMap, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
-// write!(f, "<properties>")
-// }
-
-// #[cfg(not(feature = "std"))]
-// fn opt_properties_permissions_map_debug(properties: &Option<PropertiesPermissionMap>, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
-// if properties.is_some() {
-// write!(f, "Some(<properties permissions>)")
-// } else {
-// write!(f, "None")
-// }
-// }
runtime/common/src/weights.rsdiffbeforeafterboth--- a/runtime/common/src/weights.rs
+++ b/runtime/common/src/weights.rs
@@ -54,16 +54,16 @@
dispatch_weight::<T>() + max_weight_of!(burn_item())
}
- fn change_collection_properties(amount: u32) -> Weight {
- dispatch_weight::<T>() + max_weight_of!(change_collection_properties(amount))
+ fn set_collection_properties(amount: u32) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(set_collection_properties(amount))
}
- fn change_token_properties(amount: u32) -> Weight {
- dispatch_weight::<T>() + max_weight_of!(change_token_properties(amount))
+ fn set_token_properties(amount: u32) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))
}
- fn change_property_permissions(amount: u32) -> Weight {
- dispatch_weight::<T>() + max_weight_of!(change_property_permissions(amount))
+ fn set_property_permissions(amount: u32) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(set_property_permissions(amount))
}
fn transfer() -> Weight {