From 7fd36cea2f6e00c02c67ccc1de9649ae404efd31 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Thu, 21 Jul 2022 07:55:18 +0000 Subject: [PATCH] refactor: remove `#[transactional]` from extrinsics Every extrinsic now runs in transaction implicitly, and `#[transactional]` on pallet dispatchable is now meaningless --- --- a/pallets/evm-migration/src/lib.rs +++ b/pallets/evm-migration/src/lib.rs @@ -23,7 +23,7 @@ #[frame_support::pallet] pub mod pallet { - use frame_support::{pallet_prelude::*, transactional}; + use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; use sp_core::{H160, H256}; use sp_std::vec::Vec; @@ -84,7 +84,6 @@ } #[pallet::weight(>::finish(code.len() as u32))] - #[transactional] pub fn finish(origin: OriginFor, address: H160, code: Vec) -> DispatchResult { ensure_root(origin)?; ensure!( --- a/pallets/proxy-rmrk-core/src/lib.rs +++ b/pallets/proxy-rmrk-core/src/lib.rs @@ -145,7 +145,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use frame_support::{pallet_prelude::*, transactional, BoundedVec, dispatch::DispatchResult}; +use frame_support::{pallet_prelude::*, BoundedVec, dispatch::DispatchResult}; use frame_system::{pallet_prelude::*, ensure_signed}; use sp_runtime::{DispatchError, Permill, traits::StaticLookup}; use sp_std::{ @@ -350,11 +350,11 @@ /// * Anyone - will be assigned as the issuer of the collection. /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `metadata`: Metadata describing the collection, e.g. IPFS hash. Cannot be changed. /// - `max`: Optional maximum number of tokens. /// - `symbol`: UTF-8 string with token prefix, by which to represent the token in wallets and UIs. /// Analogous to Unique's [`token_prefix`](up_data_structs::Collection). Cannot be changed. - #[transactional] #[pallet::weight(>::create_collection())] pub fn create_collection( origin: OriginFor, @@ -426,8 +426,8 @@ /// * Collection issuer /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `collection_id`: RMRK ID of the collection to destroy. - #[transactional] #[pallet::weight(>::destroy_collection())] pub fn destroy_collection( origin: OriginFor, @@ -459,9 +459,9 @@ /// * Collection issuer /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `collection_id`: RMRK collection ID to change the issuer of. /// - `new_issuer`: Collection's new issuer. - #[transactional] #[pallet::weight(>::change_collection_issuer())] pub fn change_collection_issuer( origin: OriginFor, @@ -497,8 +497,8 @@ /// * Collection issuer /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `collection_id`: RMRK ID of the collection to lock. - #[transactional] #[pallet::weight(>::lock_collection())] pub fn lock_collection( origin: OriginFor, @@ -535,6 +535,7 @@ /// * Collection issuer /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `owner`: Owner account of the NFT. If set to None, defaults to the sender (collection issuer). /// - `collection_id`: RMRK collection ID for the NFT to be minted within. Cannot be changed. /// - `recipient`: Receiver account of the royalty. Has no effect if the `royalty_amount` is not set. Cannot be changed. @@ -542,7 +543,6 @@ /// - `metadata`: Arbitrary data about an NFT, e.g. IPFS hash. Cannot be changed. /// - `transferable`: Can this NFT be transferred? Cannot be changed. /// - `resources`: Resource data to be added to the NFT immediately after minting. - #[transactional] #[pallet::weight(>::mint_nft(resources.as_ref().map(|r| r.len() as u32).unwrap_or(0)))] pub fn mint_nft( origin: OriginFor, @@ -620,12 +620,12 @@ /// * Token owner /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `collection_id`: RMRK ID of the collection in which the NFT to burn belongs to. /// - `nft_id`: ID of the NFT to be destroyed. /// - `max_burns`: Maximum number of tokens to burn, assuming nesting. The transaction /// is reverted if there are more tokens to burn in the nesting tree than this number. /// This is primarily a mechanism of transaction weight control. - #[transactional] #[pallet::weight(>::burn_nft(*max_burns))] pub fn burn_nft( origin: OriginFor, @@ -669,10 +669,10 @@ /// - Token owner /// /// # Arguments: - /// - `collection_id`: RMRK ID of the collection of the NFT to be transferred. - /// - `nft_id`: ID of the NFT to be transferred. + /// - `origin`: sender of the transaction + /// - `rmrk_collection_id`: RMRK ID of the collection of the NFT to be transferred. + /// - `rmrk_nft_id`: ID of the NFT to be transferred. /// - `new_owner`: New owner of the nft which can be either an account or a NFT. - #[transactional] #[pallet::weight(>::send())] pub fn send( origin: OriginFor, @@ -793,11 +793,11 @@ /// - Token-owner-to-be /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `rmrk_collection_id`: RMRK collection ID of the NFT to be accepted. /// - `rmrk_nft_id`: ID of the NFT to be accepted. /// - `new_owner`: Either the sender's account ID or a sender-owned NFT, /// whichever the accepted NFT was sent to. - #[transactional] #[pallet::weight(>::accept_nft())] pub fn accept_nft( origin: OriginFor, @@ -885,9 +885,9 @@ /// - Token-owner-to-be-not /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `rmrk_collection_id`: RMRK ID of the NFT to be rejected. /// - `rmrk_nft_id`: ID of the NFT to be rejected. - #[transactional] #[pallet::weight(>::reject_nft())] pub fn reject_nft( origin: OriginFor, @@ -950,10 +950,11 @@ /// - Token owner /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `rmrk_collection_id`: RMRK collection ID of the NFT. /// - `rmrk_nft_id`: ID of the NFT with a pending resource to be accepted. /// - `resource_id`: ID of the newly created pending resource. - #[transactional] + /// accept the addition of a new resource to an existing NFT #[pallet::weight(>::accept_resource())] pub fn accept_resource( origin: OriginFor, @@ -1004,10 +1005,10 @@ /// - Token owner /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `rmrk_collection_id`: RMRK collection ID of the NFT. /// - `rmrk_nft_id`: ID of the NFT with a resource to be removed. /// - `resource_id`: ID of the removal-pending resource. - #[transactional] #[pallet::weight(>::accept_resource_removal())] pub fn accept_resource_removal( origin: OriginFor, @@ -1084,11 +1085,11 @@ /// - Token owner - in case of NFT property /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `rmrk_collection_id`: RMRK collection ID. /// - `maybe_nft_id`: Optional ID of the NFT. If left empty, then the property is set for the collection. /// - `key`: Key of the custom property to be referenced by. /// - `value`: Value of the custom property to be stored. - #[transactional] #[pallet::weight(>::set_property())] pub fn set_property( origin: OriginFor, @@ -1158,10 +1159,10 @@ /// - Token owner /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `rmrk_collection_id`: RMRK collection ID of the NFT. /// - `rmrk_nft_id`: ID of the NFT to rearrange resource priorities for. /// - `priorities`: Ordered vector of resource IDs. - #[transactional] #[pallet::weight(>::set_priority())] pub fn set_priority( origin: OriginFor, @@ -1209,10 +1210,10 @@ /// the owner's [acceptance](Pallet::accept_resource). /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `rmrk_collection_id`: RMRK collection ID of the NFT. /// - `nft_id`: ID of the NFT to assign a resource to. /// - `resource`: Data of the resource to be created. - #[transactional] #[pallet::weight(>::add_basic_resource())] pub fn add_basic_resource( origin: OriginFor, @@ -1251,10 +1252,10 @@ /// the owner's [acceptance](Pallet::accept_resource). /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `rmrk_collection_id`: RMRK collection ID of the NFT. /// - `nft_id`: ID of the NFT to assign a resource to. /// - `resource`: Data of the resource to be created. - #[transactional] #[pallet::weight(>::add_composable_resource())] pub fn add_composable_resource( origin: OriginFor, @@ -1313,10 +1314,10 @@ /// the owner's [acceptance](Pallet::accept_resource). /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `rmrk_collection_id`: RMRK collection ID of the NFT. /// - `nft_id`: ID of the NFT to assign a resource to. /// - `resource`: Data of the resource to be created. - #[transactional] #[pallet::weight(>::add_slot_resource())] pub fn add_slot_resource( origin: OriginFor, @@ -1354,10 +1355,10 @@ /// - Collection issuer /// /// # Arguments - /// - `collection_id`: RMRK ID of a collection to which the NFT making use of the resource belongs to. + /// - `origin`: sender of the transaction + /// - `rmrk_collection_id`: RMRK ID of a collection to which the NFT making use of the resource belongs to. /// - `nft_id`: ID of the NFT with a resource to be removed. /// - `resource_id`: ID of the resource to be removed. - #[transactional] #[pallet::weight(>::remove_resource())] pub fn remove_resource( origin: OriginFor, --- a/pallets/proxy-rmrk-equip/src/lib.rs +++ b/pallets/proxy-rmrk-equip/src/lib.rs @@ -133,7 +133,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use frame_support::{pallet_prelude::*, transactional, BoundedVec, dispatch::DispatchResult}; +use frame_support::{pallet_prelude::*, BoundedVec, dispatch::DispatchResult}; use frame_system::{pallet_prelude::*, ensure_signed}; use sp_runtime::DispatchError; use up_data_structs::*; @@ -226,11 +226,11 @@ /// - Anyone - will be assigned as the issuer of the Base. /// /// # Arguments: + /// - `origin`: Caller, will be assigned as the issuer of the Base /// - `base_type`: Arbitrary media type, e.g. "svg". /// - `symbol`: Arbitrary client-chosen symbol. /// - `parts`: Array of Fixed and Slot Parts composing the Base, /// confined in length by [`RmrkPartsLimit`](up_data_structs::RmrkPartsLimit). - #[transactional] #[pallet::weight(>::create_base(parts.len() as u32))] pub fn create_base( origin: OriginFor, @@ -295,13 +295,13 @@ /// - Base issuer /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `base_id`: Base ID containing the Theme to be updated. /// - `theme`: Theme to add to the Base. A Theme has a name and properties, which are an /// array of [key, value, inherit]. /// - `key`: Arbitrary BoundedString, defined by client. /// - `value`: Arbitrary BoundedString, defined by client. /// - `inherit`: Optional bool. - #[transactional] #[pallet::weight(>::theme_add(theme.properties.len() as u32))] pub fn theme_add( origin: OriginFor, @@ -359,10 +359,10 @@ /// - Base issuer /// /// # Arguments: + /// - `origin`: sender of the transaction /// - `base_id`: Base containing the Slot Part to be updated. - /// - `part_id`: Slot Part whose Equippable List is being updated. + /// - `slot_id`: Slot Part whose Equippable List is being updated . /// - `equippables`: List of equippables that will override the current Equippables list. - #[transactional] #[pallet::weight(>::equippable())] pub fn equippable( origin: OriginFor, --- a/pallets/unique/src/lib.rs +++ b/pallets/unique/src/lib.rs @@ -78,7 +78,6 @@ dispatch::DispatchResult, ensure, fail, weights::{Weight}, - transactional, pallet_prelude::{DispatchResultWithPostInfo, ConstU32}, BoundedVec, }; @@ -311,7 +310,6 @@ /// * `mode`: Type of items stored in the collection and type dependent data. // returns collection ID #[weight = >::create_collection()] - #[transactional] #[deprecated(note = "`create_collection_ex` is more up-to-date and advanced, prefer it instead")] pub fn create_collection( origin, @@ -342,7 +340,6 @@ /// /// * `data`: Explicit data of a collection used for its creation. #[weight = >::create_collection()] - #[transactional] pub fn create_collection_ex(origin, data: CreateCollectionData) -> DispatchResult { let sender = ensure_signed(origin)?; @@ -363,7 +360,6 @@ /// /// * `collection_id`: Collection to destroy. #[weight = >::destroy_collection()] - #[transactional] pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult { let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let collection = >::try_get(collection_id)?; @@ -399,7 +395,6 @@ /// * `collection_id`: ID of the modified collection. /// * `address`: ID of the address to be added to the allowlist. #[weight = >::add_to_allow_list()] - #[transactional] pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{ let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); @@ -433,7 +428,6 @@ /// * `collection_id`: ID of the modified collection. /// * `address`: ID of the address to be removed from the allowlist. #[weight = >::remove_from_allow_list()] - #[transactional] pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{ let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); @@ -466,7 +460,6 @@ /// * `collection_id`: ID of the modified collection. /// * `new_owner`: ID of the account that will become the owner. #[weight = >::change_collection_owner()] - #[transactional] pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult { let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); @@ -501,8 +494,7 @@ /// * `collection_id`: ID of the Collection to add an admin for. /// * `new_admin`: Address of new admin to add. #[weight = >::add_collection_admin()] - #[transactional] - pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin: T::CrossAccountId) -> DispatchResult { + pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult { let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let collection = >::try_get(collection_id)?; collection.check_is_internal()?; @@ -530,7 +522,6 @@ /// * `collection_id`: ID of the collection to remove the admin for. /// * `account_id`: Address of the admin to remove. #[weight = >::remove_collection_admin()] - #[transactional] pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult { let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let collection = >::try_get(collection_id)?; @@ -558,7 +549,6 @@ /// * `collection_id`: ID of the modified collection. /// * `new_sponsor`: ID of the account of the sponsor-to-be. #[weight = >::set_collection_sponsor()] - #[transactional] pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult { let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); @@ -590,7 +580,6 @@ /// /// * `collection_id`: ID of the collection with the pending sponsor. #[weight = >::confirm_sponsorship()] - #[transactional] pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult { let sender = ensure_signed(origin)?; @@ -619,7 +608,6 @@ /// /// * `collection_id`: ID of the collection with the sponsor to remove. #[weight = >::remove_collection_sponsor()] - #[transactional] pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult { let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); @@ -654,7 +642,6 @@ /// * `owner`: Address of the initial owner of the item. /// * `data`: Token data describing the item to store on chain. #[weight = T::CommonWeightInfo::create_item()] - #[transactional] pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo { let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let budget = budget::Value::new(NESTING_BUDGET); @@ -681,7 +668,6 @@ /// * `owner`: Address of the initial owner of the tokens. /// * `items_data`: Vector of data describing each item to be created. #[weight = T::CommonWeightInfo::create_multiple_items(&items_data)] - #[transactional] pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec) -> DispatchResultWithPostInfo { ensure!(!items_data.is_empty(), Error::::EmptyArgument); let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); @@ -703,7 +689,6 @@ /// * `properties`: Vector of key-value pairs stored as the collection's metadata. /// Keys support Latin letters, `-`, `_`, and `.` as symbols. #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)] - #[transactional] pub fn set_collection_properties( origin, collection_id: CollectionId, @@ -729,7 +714,6 @@ /// * `property_keys`: Vector of keys of the properties to be deleted. /// Keys support Latin letters, `-`, `_`, and `.` as symbols. #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)] - #[transactional] pub fn delete_collection_properties( origin, collection_id: CollectionId, @@ -761,7 +745,6 @@ /// * `properties`: Vector of key-value pairs stored as the token's metadata. /// Keys support Latin letters, `-`, `_`, and `.` as symbols. #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)] - #[transactional] pub fn set_token_properties( origin, collection_id: CollectionId, @@ -792,7 +775,6 @@ /// * `property_keys`: Vector of keys of the properties to be deleted. /// Keys support Latin letters, `-`, `_`, and `.` as symbols. #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)] - #[transactional] pub fn delete_token_properties( origin, collection_id: CollectionId, @@ -823,7 +805,6 @@ /// * `property_permissions`: Vector of permissions for property keys. /// Keys support Latin letters, `-`, `_`, and `.` as symbols. #[weight = T::CommonWeightInfo::set_token_property_permissions(property_permissions.len() as u32)] - #[transactional] pub fn set_token_property_permissions( origin, collection_id: CollectionId, @@ -852,7 +833,6 @@ /// * `collection_id`: ID of the collection to which the tokens would belong. /// * `data`: Explicit item creation data. #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)] - #[transactional] pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData) -> DispatchResultWithPostInfo { let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let budget = budget::Value::new(NESTING_BUDGET); @@ -871,7 +851,6 @@ /// * `collection_id`: ID of the collection. /// * `value`: New value of the flag, are transfers allowed? #[weight = >::set_transfers_enabled_flag()] - #[transactional] pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult { let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let mut target_collection = >::try_get(collection_id)?; @@ -901,7 +880,6 @@ /// * Fungible Mode: The desired number of pieces to burn. /// * Re-Fungible Mode: The desired number of pieces to burn. #[weight = T::CommonWeightInfo::burn_item()] - #[transactional] pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo { let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); @@ -940,7 +918,6 @@ /// * Fungible Mode: The desired number of pieces to burn. /// * Re-Fungible Mode: The desired number of pieces to burn. #[weight = T::CommonWeightInfo::burn_from()] - #[transactional] pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo { let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let budget = budget::Value::new(NESTING_BUDGET); @@ -970,7 +947,6 @@ /// * Fungible Mode: The desired number of pieces to transfer. /// * Re-Fungible Mode: The desired number of pieces to transfer. #[weight = T::CommonWeightInfo::transfer()] - #[transactional] pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo { let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let budget = budget::Value::new(NESTING_BUDGET); @@ -994,7 +970,6 @@ /// * `amount`: Number of pieces of the item approved for a transaction (maximum of 1 for NFTs). /// Set to 0 to revoke the approval. #[weight = T::CommonWeightInfo::approve()] - #[transactional] pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo { let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); @@ -1026,7 +1001,6 @@ /// * Fungible Mode: The desired number of pieces to transfer. /// * Re-Fungible Mode: The desired number of pieces to transfer. #[weight = T::CommonWeightInfo::transfer_from()] - #[transactional] pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo { let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); let budget = budget::Value::new(NESTING_BUDGET); @@ -1047,7 +1021,6 @@ /// * `new_limit`: New limits of the collection. Fields that are not set (None) /// will not overwrite the old ones. #[weight = >::set_collection_limits()] - #[transactional] pub fn set_collection_limits( origin, collection_id: CollectionId, @@ -1081,7 +1054,6 @@ /// * `new_permission`: New permissions of the collection. Fields that are not set (None) /// will not overwrite the old ones. #[weight = >::set_collection_limits()] - #[transactional] pub fn set_collection_permissions( origin, collection_id: CollectionId, @@ -1114,7 +1086,6 @@ /// * `token_id`: ID of the RFT. /// * `amount`: New number of parts/pieces into which the token shall be partitioned. #[weight = T::RefungibleExtensionsWeightInfo::repartition()] - #[transactional] pub fn repartition( origin, collection_id: CollectionId, -- gitstuff