Skip to content

Commit

Permalink
refactor: remove #[transactional] from extrinsics
Browse files Browse the repository at this point in the history
Every extrinsic now runs in transaction implicitly, and
`#[transactional]` on pallet dispatchable is now meaningless

Upstream-Change: paritytech/substrate#10806
Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>
  • Loading branch information
CertainLach authored and Daniel Shiposha committed Aug 16, 2022
1 parent e198017 commit 7fd36ce
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 58 deletions.
3 changes: 1 addition & 2 deletions pallets/evm-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub mod weights;

#[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;
Expand Down Expand Up @@ -84,7 +84,6 @@ pub mod pallet {
}

#[pallet::weight(<SelfWeightOf<T>>::finish(code.len() as u32))]
#[transactional]
pub fn finish(origin: OriginFor<T>, address: H160, code: Vec<u8>) -> DispatchResult {
ensure_root(origin)?;
ensure!(
Expand Down
43 changes: 22 additions & 21 deletions pallets/proxy-rmrk-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -350,11 +350,11 @@ pub mod pallet {
/// * 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(<SelfWeightOf<T>>::create_collection())]
pub fn create_collection(
origin: OriginFor<T>,
Expand Down Expand Up @@ -426,8 +426,8 @@ pub mod pallet {
/// * Collection issuer
///
/// # Arguments:
/// - `origin`: sender of the transaction
/// - `collection_id`: RMRK ID of the collection to destroy.
#[transactional]
#[pallet::weight(<SelfWeightOf<T>>::destroy_collection())]
pub fn destroy_collection(
origin: OriginFor<T>,
Expand Down Expand Up @@ -459,9 +459,9 @@ pub mod pallet {
/// * 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(<SelfWeightOf<T>>::change_collection_issuer())]
pub fn change_collection_issuer(
origin: OriginFor<T>,
Expand Down Expand Up @@ -497,8 +497,8 @@ pub mod pallet {
/// * Collection issuer
///
/// # Arguments:
/// - `origin`: sender of the transaction
/// - `collection_id`: RMRK ID of the collection to lock.
#[transactional]
#[pallet::weight(<SelfWeightOf<T>>::lock_collection())]
pub fn lock_collection(
origin: OriginFor<T>,
Expand Down Expand Up @@ -535,14 +535,14 @@ pub mod pallet {
/// * 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.
/// - `royalty_amount`: Optional permillage reward from each trade for the `recipient`. Cannot be changed.
/// - `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(<SelfWeightOf<T>>::mint_nft(resources.as_ref().map(|r| r.len() as u32).unwrap_or(0)))]
pub fn mint_nft(
origin: OriginFor<T>,
Expand Down Expand Up @@ -620,12 +620,12 @@ pub mod pallet {
/// * 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(<SelfWeightOf<T>>::burn_nft(*max_burns))]
pub fn burn_nft(
origin: OriginFor<T>,
Expand Down Expand Up @@ -669,10 +669,10 @@ pub mod pallet {
/// - 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(<SelfWeightOf<T>>::send())]
pub fn send(
origin: OriginFor<T>,
Expand Down Expand Up @@ -793,11 +793,11 @@ pub mod pallet {
/// - 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(<SelfWeightOf<T>>::accept_nft())]
pub fn accept_nft(
origin: OriginFor<T>,
Expand Down Expand Up @@ -885,9 +885,9 @@ pub mod pallet {
/// - 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(<SelfWeightOf<T>>::reject_nft())]
pub fn reject_nft(
origin: OriginFor<T>,
Expand Down Expand Up @@ -950,10 +950,11 @@ pub mod pallet {
/// - 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(<SelfWeightOf<T>>::accept_resource())]
pub fn accept_resource(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1004,10 +1005,10 @@ pub mod pallet {
/// - 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(<SelfWeightOf<T>>::accept_resource_removal())]
pub fn accept_resource_removal(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1084,11 +1085,11 @@ pub mod pallet {
/// - 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(<SelfWeightOf<T>>::set_property())]
pub fn set_property(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1158,10 +1159,10 @@ pub mod pallet {
/// - 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(<SelfWeightOf<T>>::set_priority())]
pub fn set_priority(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1209,10 +1210,10 @@ pub mod pallet {
/// 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(<SelfWeightOf<T>>::add_basic_resource())]
pub fn add_basic_resource(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1251,10 +1252,10 @@ pub mod pallet {
/// 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(<SelfWeightOf<T>>::add_composable_resource())]
pub fn add_composable_resource(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1313,10 +1314,10 @@ pub mod pallet {
/// 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(<SelfWeightOf<T>>::add_slot_resource())]
pub fn add_slot_resource(
origin: OriginFor<T>,
Expand Down Expand Up @@ -1354,10 +1355,10 @@ pub mod pallet {
/// - 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(<SelfWeightOf<T>>::remove_resource())]
pub fn remove_resource(
origin: OriginFor<T>,
Expand Down
10 changes: 5 additions & 5 deletions pallets/proxy-rmrk-equip/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -226,11 +226,11 @@ pub mod pallet {
/// - 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(<SelfWeightOf<T>>::create_base(parts.len() as u32))]
pub fn create_base(
origin: OriginFor<T>,
Expand Down Expand Up @@ -295,13 +295,13 @@ pub mod pallet {
/// - 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(<SelfWeightOf<T>>::theme_add(theme.properties.len() as u32))]
pub fn theme_add(
origin: OriginFor<T>,
Expand Down Expand Up @@ -359,10 +359,10 @@ pub mod pallet {
/// - 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(<SelfWeightOf<T>>::equippable())]
pub fn equippable(
origin: OriginFor<T>,
Expand Down
Loading

0 comments on commit 7fd36ce

Please sign in to comment.