difftreelog
CORE-390 Refactor naming
in: master
7 files changed
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -317,7 +317,7 @@
fn save<T: Config>(collection: &CollectionHandle<T>) -> Result<void> {
collection
- .check_is_read_only()
+ .check_is_mutable()
.map_err(dispatch_to_evm::<T>)?;
<crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());
Ok(())
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -149,19 +149,19 @@
))
}
pub fn save(self) -> Result<(), DispatchError> {
- self.check_is_read_only()?;
+ self.check_is_mutable()?;
<CollectionById<T>>::insert(self.id, self.collection);
Ok(())
}
pub fn set_sponsor(&mut self, sponsor: T::AccountId) -> DispatchResult {
- self.check_is_read_only()?;
+ self.check_is_mutable()?;
self.collection.sponsorship = SponsorshipState::Unconfirmed(sponsor);
Ok(())
}
pub fn confirm_sponsorship(&mut self, sender: &T::AccountId) -> Result<bool, DispatchError> {
- self.check_is_read_only()?;
+ self.check_is_mutable()?;
if self.collection.sponsorship.pending_sponsor() != Some(sender) {
return Ok(false);
@@ -686,7 +686,7 @@
sponsorship,
limits,
permissions,
- read_only,
+ external_collection,
} = <CollectionById<T>>::get(collection)?;
let token_property_permissions = <CollectionPropertyPermissions<T>>::get(collection)
@@ -716,7 +716,7 @@
permissions,
token_property_permissions,
properties,
- read_only,
+ read_only: external_collection,
})
}
}
@@ -797,7 +797,7 @@
Self::clamp_permissions(data.mode.clone(), &Default::default(), permissions)
})
.unwrap_or_else(|| Ok(CollectionPermissions::default()))?,
- read_only: false,
+ external_collection: false,
};
let mut collection_properties = up_data_structs::CollectionProperties::get();
@@ -854,7 +854,7 @@
collection: CollectionHandle<T>,
sender: &T::CrossAccountId,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
ensure!(
collection.limits.owner_can_destroy(),
<Error<T>>::NoPermission,
@@ -884,7 +884,7 @@
sender: &T::CrossAccountId,
property: Property,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
collection.check_is_owner_or_admin(sender)?;
CollectionProperties::<T>::try_mutate(collection.id, |properties| {
@@ -930,7 +930,7 @@
sender: &T::CrossAccountId,
properties: Vec<Property>,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
for property in properties {
Self::set_collection_property(collection, sender, property)?;
@@ -944,7 +944,7 @@
sender: &T::CrossAccountId,
property_key: PropertyKey,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
collection.check_is_owner_or_admin(sender)?;
CollectionProperties::<T>::try_mutate(collection.id, |properties| {
@@ -966,7 +966,7 @@
sender: &T::CrossAccountId,
property_keys: Vec<PropertyKey>,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
for key in property_keys {
Self::delete_collection_property(collection, sender, key)?;
@@ -992,7 +992,7 @@
sender: &T::CrossAccountId,
property_permission: PropertyKeyPermission,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
collection.check_is_owner_or_admin(sender)?;
let all_permissions = CollectionPropertyPermissions::<T>::get(collection.id);
@@ -1024,7 +1024,7 @@
sender: &T::CrossAccountId,
property_permissions: Vec<PropertyKeyPermission>,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
for prop_pemission in property_permissions {
Self::set_property_permission(collection, sender, prop_pemission)?;
@@ -1113,7 +1113,7 @@
user: &T::CrossAccountId,
allowed: bool,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
collection.check_is_owner_or_admin(sender)?;
// =========
@@ -1133,7 +1133,7 @@
user: &T::CrossAccountId,
admin: bool,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
collection.check_is_owner_or_admin(sender)?;
let was_admin = <IsAdmin<T>>::get((collection.id, user));
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -168,7 +168,7 @@
owner: &T::CrossAccountId,
amount: u128,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
let total_supply = <TotalSupply<T>>::get(collection.id)
.checked_sub(amount)
@@ -216,7 +216,7 @@
amount: u128,
nesting_budget: &dyn Budget,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
ensure!(
collection.limits.transfers_enabled(),
@@ -287,7 +287,7 @@
data: BTreeMap<T::CrossAccountId, u128>,
nesting_budget: &dyn Budget,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
if !collection.is_owner_or_admin(sender) {
ensure!(
@@ -390,7 +390,7 @@
spender: &T::CrossAccountId,
amount: u128,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
if collection.permissions.access() == AccessMode::AllowList {
collection.check_allowlist(owner)?;
collection.check_allowlist(spender)?;
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -336,7 +336,7 @@
sender: &T::CrossAccountId,
token: TokenId,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
let token_data =
<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
@@ -458,7 +458,7 @@
&property.key,
is_token_create,
)?;
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
<TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
let property = property.clone();
@@ -496,8 +496,8 @@
token_id: TokenId,
property_key: PropertyKey,
) -> DispatchResult {
+ collection.check_is_mutable()?;
Self::check_token_change_permission(collection, sender, token_id, &property_key, false)?;
- collection.check_is_read_only()?;
<TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
properties.remove(&property_key)
@@ -574,7 +574,7 @@
token_id: TokenId,
property_keys: Vec<PropertyKey>,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
for key in property_keys {
Self::delete_token_property(collection, sender, token_id, key)?;
@@ -622,7 +622,7 @@
token: TokenId,
nesting_budget: &dyn Budget,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
ensure!(
collection.limits.transfers_enabled(),
@@ -902,7 +902,7 @@
token: TokenId,
spender: Option<&T::CrossAccountId>,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
if collection.permissions.access() == AccessMode::AllowList {
collection.check_allowlist(sender)?;
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -234,7 +234,7 @@
}
pub fn burn_token(collection: &RefungibleHandle<T>, token_id: TokenId) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
let burnt = <TokensBurnt<T>>::get(collection.id)
.checked_add(1)
.ok_or(ArithmeticError::Overflow)?;
@@ -254,7 +254,7 @@
token: TokenId,
amount: u128,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
let total_supply = <TotalSupply<T>>::get((collection.id, token))
.checked_sub(amount)
.ok_or(<CommonError<T>>::TokenValueTooLow)?;
@@ -327,7 +327,7 @@
amount: u128,
nesting_budget: &dyn Budget,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
ensure!(
collection.limits.transfers_enabled(),
<CommonError<T>>::TransferNotAllowed
@@ -576,7 +576,7 @@
token: TokenId,
amount: u128,
) -> DispatchResult {
- collection.check_is_read_only()?;
+ collection.check_is_mutable()?;
if collection.permissions.access() == AccessMode::AllowList {
collection.check_allowlist(sender)?;
collection.check_allowlist(spender)?;
pallets/unique/src/lib.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/>.1617#![recursion_limit = "1024"]18#![cfg_attr(not(feature = "std"), no_std)]19#![allow(20 clippy::too_many_arguments,21 clippy::unnecessary_mut_passed,22 clippy::unused_unit23)]2425extern crate alloc;2627use frame_support::{28 decl_module, decl_storage, decl_error, decl_event,29 dispatch::DispatchResult,30 ensure,31 weights::{Weight},32 transactional,33 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},34 BoundedVec,35};36use scale_info::TypeInfo;37use frame_system::{self as system, ensure_signed};38use sp_runtime::{sp_std::prelude::Vec};39use up_data_structs::{40 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,41 CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId,42 SponsorshipState, CreateCollectionData, CreateItemExData, budget, Property, PropertyKey,43 PropertyKeyPermission,44};45use pallet_evm::account::CrossAccountId;46use pallet_common::{47 CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_call,48 dispatch::CollectionDispatch,49};50pub mod eth;5152#[cfg(feature = "runtime-benchmarks")]53mod benchmarking;54pub mod weights;55use weights::WeightInfo;5657const NESTING_BUDGET: u32 = 5;5859decl_error! {60 /// Error for non-fungible-token module.61 pub enum Error for Module<T: Config> {62 /// Decimal_points parameter must be lower than MAX_DECIMAL_POINTS constant, currently it is 30.63 CollectionDecimalPointLimitExceeded,64 /// This address is not set as sponsor, use setCollectionSponsor first.65 ConfirmUnsetSponsorFail,66 /// Length of items properties must be greater than 0.67 EmptyArgument,68 }69}7071pub trait Config: system::Config + pallet_common::Config + Sized + TypeInfo {72 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;7374 /// Weight information for extrinsics in this pallet.75 type WeightInfo: WeightInfo;76 type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;77}7879decl_event! {80 pub enum Event<T>81 where82 <T as frame_system::Config>::AccountId,83 <T as pallet_evm::account::Config>::CrossAccountId,84 {85 /// Collection sponsor was removed86 ///87 /// # Arguments88 ///89 /// * collection_id: Globally unique collection identifier.90 CollectionSponsorRemoved(CollectionId),9192 /// Collection admin was added93 ///94 /// # Arguments95 ///96 /// * collection_id: Globally unique collection identifier.97 ///98 /// * admin: Admin address.99 CollectionAdminAdded(CollectionId, CrossAccountId),100101 /// Collection owned was change102 ///103 /// # Arguments104 ///105 /// * collection_id: Globally unique collection identifier.106 ///107 /// * owner: New owner address.108 CollectionOwnedChanged(CollectionId, AccountId),109110 /// Collection sponsor was set111 ///112 /// # Arguments113 ///114 /// * collection_id: Globally unique collection identifier.115 ///116 /// * owner: New sponsor address.117 CollectionSponsorSet(CollectionId, AccountId),118119 /// New sponsor was confirm120 ///121 /// # Arguments122 ///123 /// * collection_id: Globally unique collection identifier.124 ///125 /// * sponsor: New sponsor address.126 SponsorshipConfirmed(CollectionId, AccountId),127128 /// Collection admin was removed129 ///130 /// # Arguments131 ///132 /// * collection_id: Globally unique collection identifier.133 ///134 /// * admin: Admin address.135 CollectionAdminRemoved(CollectionId, CrossAccountId),136137 /// Address was remove from allow list138 ///139 /// # Arguments140 ///141 /// * collection_id: Globally unique collection identifier.142 ///143 /// * user: Address.144 AllowListAddressRemoved(CollectionId, CrossAccountId),145146 /// Address was add to allow list147 ///148 /// # Arguments149 ///150 /// * collection_id: Globally unique collection identifier.151 ///152 /// * user: Address.153 AllowListAddressAdded(CollectionId, CrossAccountId),154155 /// Collection limits was set156 ///157 /// # Arguments158 ///159 /// * collection_id: Globally unique collection identifier.160 CollectionLimitSet(CollectionId),161162 CollectionPermissionSet(CollectionId),163 }164}165166type SelfWeightOf<T> = <T as Config>::WeightInfo;167168// # Used definitions169//170// ## User control levels171//172// chain-controlled - key is uncontrolled by user173// i.e autoincrementing index174// can use non-cryptographic hash175// real - key is controlled by user176// but it is hard to generate enough colliding values, i.e owner of signed txs177// can use non-cryptographic hash178// controlled - key is completly controlled by users179// i.e maps with mutable keys180// should use cryptographic hash181//182// ## User control level downgrade reasons183//184// ?1 - chain-controlled -> controlled185// collections/tokens can be destroyed, resulting in massive holes186// ?2 - chain-controlled -> controlled187// same as ?1, but can be only added, resulting in easier exploitation188// ?3 - real -> controlled189// no confirmation required, so addresses can be easily generated190decl_storage! {191 trait Store for Module<T: Config> as Unique {192193 //#region Private members194 /// Used for migrations195 ChainVersion: u64;196 //#endregion197198 //#region Tokens transfer rate limit baskets199 /// (Collection id (controlled?2), who created (real))200 /// TODO: Off chain worker should remove from this map when collection gets removed201 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;202 /// Collection id (controlled?2), token id (controlled?2)203 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;204 /// Collection id (controlled?2), owning user (real)205 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;206 /// Collection id (controlled?2), token id (controlled?2)207 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;208 //#endregion209210 /// Variable metadata sponsoring211 /// Collection id (controlled?2), token id (controlled?2)212 #[deprecated]213 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;214 pub TokenPropertyBasket get(fn token_property_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;215216 /// Approval sponsoring217 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;218 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;219 pub RefungibleApproveBasket get(fn refungible_approve_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;220 }221}222223decl_module! {224 pub struct Module<T: Config> for enum Call225 where226 origin: T::Origin227 {228 type Error = Error<T>;229230 fn deposit_event() = default;231232 fn on_initialize(_now: T::BlockNumber) -> Weight {233 0234 }235236 fn on_runtime_upgrade() -> Weight {237 let limit = None;238239 <VariableMetaDataBasket<T>>::remove_all(limit);240241 0242 }243244 /// This method creates a Collection of NFTs. Each Token may have multiple properties encoded as an array of bytes of certain length. The initial owner of the collection is set to the address that signed the transaction and can be changed later.245 ///246 /// # Permissions247 ///248 /// * Anyone.249 ///250 /// # Arguments251 ///252 /// * collection_name: UTF-16 string with collection name (limit 64 characters), will be stored as zero-terminated.253 ///254 /// * collection_description: UTF-16 string with collection description (limit 256 characters), will be stored as zero-terminated.255 ///256 /// * token_prefix: UTF-8 string with token prefix.257 ///258 /// * mode: [CollectionMode] collection type and type dependent data.259 // returns collection ID260 #[weight = <SelfWeightOf<T>>::create_collection()]261 #[transactional]262 #[deprecated]263 pub fn create_collection(origin,264 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,265 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,266 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,267 mode: CollectionMode) -> DispatchResult {268 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {269 name: collection_name,270 description: collection_description,271 token_prefix,272 mode,273 ..Default::default()274 };275 Self::create_collection_ex(origin, data)276 }277278 /// This method creates a collection279 ///280 /// Prefer it to deprecated [`created_collection`] method281 #[weight = <SelfWeightOf<T>>::create_collection()]282 #[transactional]283 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {284 let sender = ensure_signed(origin)?;285286 // =========287288 T::CollectionDispatch::create(T::CrossAccountId::from_sub(sender), data)?;289290 Ok(())291 }292293 /// **DANGEROUS**: Destroys collection and all NFTs within this collection. Users irrecoverably lose their assets and may lose real money.294 ///295 /// # Permissions296 ///297 /// * Collection Owner.298 ///299 /// # Arguments300 ///301 /// * collection_id: collection to destroy.302 #[weight = <SelfWeightOf<T>>::destroy_collection()]303 #[transactional]304 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {305 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);306 let collection = <CollectionHandle<T>>::try_get(collection_id)?;307 collection.check_is_read_only()?;308309 // =========310311 T::CollectionDispatch::destroy(sender, collection)?;312313 <NftTransferBasket<T>>::remove_prefix(collection_id, None);314 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);315 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);316317 <NftApproveBasket<T>>::remove_prefix(collection_id, None);318 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);319 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);320321 Ok(())322 }323324 /// Add an address to allow list.325 ///326 /// # Permissions327 ///328 /// * Collection Owner329 /// * Collection Admin330 ///331 /// # Arguments332 ///333 /// * collection_id.334 ///335 /// * address.336 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]337 #[transactional]338 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{339340 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);341 let collection = <CollectionHandle<T>>::try_get(collection_id)?;342343 <PalletCommon<T>>::toggle_allowlist(344 &collection,345 &sender,346 &address,347 true,348 )?;349350 Self::deposit_event(Event::<T>::AllowListAddressAdded(351 collection_id,352 address353 ));354355 Ok(())356 }357358 /// Remove an address from allow list.359 ///360 /// # Permissions361 ///362 /// * Collection Owner363 /// * Collection Admin364 ///365 /// # Arguments366 ///367 /// * collection_id.368 ///369 /// * address.370 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]371 #[transactional]372 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{373374 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);375 let collection = <CollectionHandle<T>>::try_get(collection_id)?;376377 <PalletCommon<T>>::toggle_allowlist(378 &collection,379 &sender,380 &address,381 false,382 )?;383384 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(385 collection_id,386 address387 ));388389 Ok(())390 }391392 /// Change the owner of the collection.393 ///394 /// # Permissions395 ///396 /// * Collection Owner.397 ///398 /// # Arguments399 ///400 /// * collection_id.401 ///402 /// * new_owner.403 #[weight = <SelfWeightOf<T>>::change_collection_owner()]404 #[transactional]405 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {406407 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);408409 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;410 target_collection.check_is_read_only()?;411 target_collection.check_is_owner(&sender)?;412413 target_collection.owner = new_owner.clone();414 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(415 collection_id,416 new_owner417 ));418419 target_collection.save()420 }421422 /// Adds an admin of the Collection.423 /// NFT Collection can be controlled by multiple admin addresses (some which can also be servers, for example). Admins can issue and burn NFTs, as well as add and remove other admins, but cannot change NFT or Collection ownership.424 ///425 /// # Permissions426 ///427 /// * Collection Owner.428 /// * Collection Admin.429 ///430 /// # Arguments431 ///432 /// * collection_id: ID of the Collection to add admin for.433 ///434 /// * new_admin_id: Address of new admin to add.435 #[weight = <SelfWeightOf<T>>::add_collection_admin()]436 #[transactional]437 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {438 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);439 let collection = <CollectionHandle<T>>::try_get(collection_id)?;440441 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(442 collection_id,443 new_admin_id.clone()444 ));445446 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)447 }448449 /// Remove admin address of the Collection. An admin address can remove itself. List of admins may become empty, in which case only Collection Owner will be able to add an Admin.450 ///451 /// # Permissions452 ///453 /// * Collection Owner.454 /// * Collection Admin.455 ///456 /// # Arguments457 ///458 /// * collection_id: ID of the Collection to remove admin for.459 ///460 /// * account_id: Address of admin to remove.461 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]462 #[transactional]463 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {464 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);465 let collection = <CollectionHandle<T>>::try_get(collection_id)?;466467 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(468 collection_id,469 account_id.clone()470 ));471472 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)473 }474475 /// # Permissions476 ///477 /// * Collection Owner478 ///479 /// # Arguments480 ///481 /// * collection_id.482 ///483 /// * new_sponsor.484 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]485 #[transactional]486 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {487 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);488489 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;490 target_collection.check_is_owner(&sender)?;491492 target_collection.set_sponsor(new_sponsor.clone())?;493494 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(495 collection_id,496 new_sponsor497 ));498499 target_collection.save()500 }501502 /// # Permissions503 ///504 /// * Sponsor.505 ///506 /// # Arguments507 ///508 /// * collection_id.509 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]510 #[transactional]511 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {512 let sender = ensure_signed(origin)?;513514 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;515 ensure!(516 target_collection.confirm_sponsorship(&sender)?,517 Error::<T>::ConfirmUnsetSponsorFail518 );519520 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(521 collection_id,522 sender523 ));524525 target_collection.save()526 }527528 /// Switch back to pay-per-own-transaction model.529 ///530 /// # Permissions531 ///532 /// * Collection owner.533 ///534 /// # Arguments535 ///536 /// * collection_id.537 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]538 #[transactional]539 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {540 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);541542 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;543 target_collection.check_is_owner(&sender)?;544545 target_collection.sponsorship = SponsorshipState::Disabled;546547 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(548 collection_id549 ));550 target_collection.save()551 }552553 /// This method creates a concrete instance of NFT Collection created with CreateCollection method.554 ///555 /// # Permissions556 ///557 /// * Collection Owner.558 /// * Collection Admin.559 /// * Anyone if560 /// * Allow List is enabled, and561 /// * Address is added to allow list, and562 /// * MintPermission is enabled (see SetMintPermission method)563 ///564 /// # Arguments565 ///566 /// * collection_id: ID of the collection.567 ///568 /// * owner: Address, initial owner of the NFT.569 ///570 /// * data: Token data to store on chain.571 #[weight = T::CommonWeightInfo::create_item()]572 #[transactional]573 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {574 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);575 let budget = budget::Value::new(NESTING_BUDGET);576577 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))578 }579580 /// This method creates multiple items in a collection created with CreateCollection method.581 ///582 /// # Permissions583 ///584 /// * Collection Owner.585 /// * Collection Admin.586 /// * Anyone if587 /// * Allow List is enabled, and588 /// * Address is added to allow list, and589 /// * MintPermission is enabled (see SetMintPermission method)590 ///591 /// # Arguments592 ///593 /// * collection_id: ID of the collection.594 ///595 /// * itemsData: Array items properties. Each property is an array of bytes itself, see [create_item].596 ///597 /// * owner: Address, initial owner of the NFT.598 #[weight = T::CommonWeightInfo::create_multiple_items(&items_data)]599 #[transactional]600 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {601 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);602 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);603 let budget = budget::Value::new(NESTING_BUDGET);604605 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))606 }607608 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]609 #[transactional]610 pub fn set_collection_properties(611 origin,612 collection_id: CollectionId,613 properties: Vec<Property>614 ) -> DispatchResultWithPostInfo {615 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);616617 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);618619 dispatch_call::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))620 }621622 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]623 #[transactional]624 pub fn delete_collection_properties(625 origin,626 collection_id: CollectionId,627 property_keys: Vec<PropertyKey>,628 ) -> DispatchResultWithPostInfo {629 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);630631 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);632633 dispatch_call::<T, _>(collection_id, |d| d.delete_collection_properties(&sender, property_keys))634 }635636 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]637 #[transactional]638 pub fn set_token_properties(639 origin,640 collection_id: CollectionId,641 token_id: TokenId,642 properties: Vec<Property>643 ) -> DispatchResultWithPostInfo {644 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);645646 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);647648 dispatch_call::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties))649 }650651 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]652 #[transactional]653 pub fn delete_token_properties(654 origin,655 collection_id: CollectionId,656 token_id: TokenId,657 property_keys: Vec<PropertyKey>658 ) -> DispatchResultWithPostInfo {659 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);660661 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);662663 dispatch_call::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys))664 }665666 #[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]667 #[transactional]668 pub fn set_property_permissions(669 origin,670 collection_id: CollectionId,671 property_permissions: Vec<PropertyKeyPermission>,672 ) -> DispatchResultWithPostInfo {673 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);674675 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);676677 dispatch_call::<T, _>(collection_id, |d| d.set_property_permissions(&sender, property_permissions))678 }679680 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]681 #[transactional]682 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {683 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);684 let budget = budget::Value::new(NESTING_BUDGET);685686 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))687 }688689 // TODO! transaction weight690691 /// Set transfers_enabled value for particular collection692 ///693 /// # Permissions694 ///695 /// * Collection Owner.696 ///697 /// # Arguments698 ///699 /// * collection_id: ID of the collection.700 ///701 /// * value: New flag value.702 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]703 #[transactional]704 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {705 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);706 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;707 target_collection.check_is_owner(&sender)?;708709 // =========710711 target_collection.limits.transfers_enabled = Some(value);712 target_collection.save()713 }714715 /// Destroys a concrete instance of NFT.716 ///717 /// # Permissions718 ///719 /// * Collection Owner.720 /// * Collection Admin.721 /// * Current NFT Owner.722 ///723 /// # Arguments724 ///725 /// * collection_id: ID of the collection.726 ///727 /// * item_id: ID of NFT to burn.728 #[weight = T::CommonWeightInfo::burn_item()]729 #[transactional]730 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {731 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);732733 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;734 if value == 1 {735 <NftTransferBasket<T>>::remove(collection_id, item_id);736 <NftApproveBasket<T>>::remove(collection_id, item_id);737 }738 // Those maps should be cleared only if token disappears completly, need to move this part of logic to pallets?739 // <FungibleApproveBasket<T>>::remove(collection_id, sender.as_sub());740 // <RefungibleApproveBasket<T>>::remove((collection_id, item_id, sender.as_sub()));741 Ok(post_info)742 }743744 /// Destroys a concrete instance of NFT on behalf of the owner745 /// See also: [`approve`]746 ///747 /// # Permissions748 ///749 /// * Collection Owner.750 /// * Collection Admin.751 /// * Current NFT Owner.752 ///753 /// # Arguments754 ///755 /// * collection_id: ID of the collection.756 ///757 /// * item_id: ID of NFT to burn.758 ///759 /// * from: owner of item760 #[weight = T::CommonWeightInfo::burn_from()]761 #[transactional]762 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {763 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);764 let budget = budget::Value::new(NESTING_BUDGET);765766 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))767 }768769 /// Change ownership of the token.770 ///771 /// # Permissions772 ///773 /// * Collection Owner774 /// * Collection Admin775 /// * Current NFT owner776 ///777 /// # Arguments778 ///779 /// * recipient: Address of token recipient.780 ///781 /// * collection_id.782 ///783 /// * item_id: ID of the item784 /// * Non-Fungible Mode: Required.785 /// * Fungible Mode: Ignored.786 /// * Re-Fungible Mode: Required.787 ///788 /// * value: Amount to transfer.789 /// * Non-Fungible Mode: Ignored790 /// * Fungible Mode: Must specify transferred amount791 /// * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)792 #[weight = T::CommonWeightInfo::transfer()]793 #[transactional]794 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {795 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);796 let budget = budget::Value::new(NESTING_BUDGET);797798 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))799 }800801 /// Set, change, or remove approved address to transfer the ownership of the NFT.802 ///803 /// # Permissions804 ///805 /// * Collection Owner806 /// * Collection Admin807 /// * Current NFT owner808 ///809 /// # Arguments810 ///811 /// * approved: Address that is approved to transfer this NFT or zero (if needed to remove approval).812 ///813 /// * collection_id.814 ///815 /// * item_id: ID of the item.816 #[weight = T::CommonWeightInfo::approve()]817 #[transactional]818 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {819 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);820821 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))822 }823824 /// Change ownership of a NFT on behalf of the owner. See Approve method for additional information. After this method executes, the approval is removed so that the approved address will not be able to transfer this NFT again from this owner.825 ///826 /// # Permissions827 /// * Collection Owner828 /// * Collection Admin829 /// * Current NFT owner830 /// * Address approved by current NFT owner831 ///832 /// # Arguments833 ///834 /// * from: Address that owns token.835 ///836 /// * recipient: Address of token recipient.837 ///838 /// * collection_id.839 ///840 /// * item_id: ID of the item.841 ///842 /// * value: Amount to transfer.843 #[weight = T::CommonWeightInfo::transfer_from()]844 #[transactional]845 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {846 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);847 let budget = budget::Value::new(NESTING_BUDGET);848849 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))850 }851852 #[weight = <SelfWeightOf<T>>::set_collection_limits()]853 #[transactional]854 pub fn set_collection_limits(855 origin,856 collection_id: CollectionId,857 new_limit: CollectionLimits,858 ) -> DispatchResult {859 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);860 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;861 target_collection.check_is_owner(&sender)?;862 let old_limit = &target_collection.limits;863864 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;865866 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(867 collection_id868 ));869870 target_collection.save()871 }872873 #[weight = <SelfWeightOf<T>>::set_collection_limits()]874 #[transactional]875 pub fn set_collection_permissions(876 origin,877 collection_id: CollectionId,878 new_limit: CollectionPermissions,879 ) -> DispatchResult {880 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);881 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;882 target_collection.check_is_owner(&sender)?;883 let old_limit = &target_collection.permissions;884885 target_collection.permissions = <PalletCommon<T>>::clamp_permissions(target_collection.mode.clone(), &old_limit, new_limit)?;886887 <Pallet<T>>::deposit_event(Event::<T>::CollectionPermissionSet(888 collection_id889 ));890891 target_collection.save()892 }893 }894}primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -316,8 +316,9 @@
#[version(2.., upper(Default::default()))]
pub permissions: CollectionPermissions,
+ /// Marks that this collection is not "unique", and managed from external.
#[version(2.., upper(false))]
- pub read_only: bool,
+ pub external_collection: bool,
#[version(..2)]
pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,