--- a/client/rpc/src/lib.rs +++ b/client/rpc/src/lib.rs @@ -328,7 +328,7 @@ macro_rules! pass_method { ( $method_name:ident( - $($(#[map(|$map_arg:ident| $map:expr)])? $name:ident: $ty:ty),* $(,)? + $($(#[map = $map:expr])? $name:ident: $ty:ty),* $(,)? ) -> $result:ty $(=> $mapper:expr)?, //$runtime_name:ident $(<$($lt: tt),+>)* $runtime_api_macro:ident @@ -355,7 +355,7 @@ let result = $(if _api_version < $ver { api.$changed_method_name(at, $($changed_name),*).map(|r| r.and_then($fixer)) } else)* - { api.$method_name(at, $($((|$map_arg: $ty| $map))? ($name)),*) }; + { api.$method_name(at, $($($map)? ($name)),*) }; Ok(result .map_err(|e| anyhow!("unable to query: {e}"))? @@ -413,7 +413,7 @@ pass_method!(collection_properties( collection: CollectionId, - #[map(|keys| string_keys_to_bytes_keys(keys))] + #[map = string_keys_to_bytes_keys] keys: Option> ) -> Vec, unique_api); @@ -421,14 +421,14 @@ collection: CollectionId, token_id: TokenId, - #[map(|keys| string_keys_to_bytes_keys(keys))] + #[map = string_keys_to_bytes_keys] keys: Option> ) -> Vec, unique_api); pass_method!(property_permissions( collection: CollectionId, - #[map(|keys| string_keys_to_bytes_keys(keys))] + #[map = string_keys_to_bytes_keys] keys: Option> ) -> Vec, unique_api); @@ -437,7 +437,7 @@ collection: CollectionId, token_id: TokenId, - #[map(|keys| string_keys_to_bytes_keys(keys))] + #[map = string_keys_to_bytes_keys] keys: Option>, ) -> TokenData, unique_api; changed_in 3, token_data_before_version_3(collection, token_id, string_keys_to_bytes_keys(keys)) => |value| Ok(value.into()) --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -531,7 +531,11 @@ debug!("Parachain genesis block: {:?}", block); info!( "Is collating: {}", - config.role.is_authority().then_some("yes").unwrap_or("no") + if config.role.is_authority() { + "yes" + } else { + "no" + } ); start_node_using_chain_runtime! { --- a/pallets/app-promotion/src/lib.rs +++ b/pallets/app-promotion/src/lib.rs @@ -30,11 +30,11 @@ //! //! //! ## Interface -//! The pallet provides interfaces for funds, collection/contract operations (see [types] module). +//! The pallet provides interfaces for funds, collection/contract operations (see [types] module). //! //! ### Dispatchable Functions -//! - [`set_admin_address`][`Pallet::set_admin_address`] - sets an address as the the admin. +//! - [`set_admin_address`][`Pallet::set_admin_address`] - sets an address as the the admin. //! - [`stake`][`Pallet::stake`] - stakes the amount of native tokens. //! - [`unstake`][`Pallet::unstake`] - unstakes all stakes. //! - [`sponsor_collection`][`Pallet::sponsor_collection`] - sets the pallet to be the sponsor for the collection. --- a/pallets/fungible/src/lib.rs +++ b/pallets/fungible/src/lib.rs @@ -73,7 +73,7 @@ //! //! - [`WithRecorder`](pallet_evm_coder_substrate::WithRecorder): Trait for EVM support //! - [`CommonCollectionOperations`](pallet_common::CommonCollectionOperations): Functions for dealing with collections -//! - [`CommonWeightInfo`](pallet_common::CommonWeightInfo): Functions for retrieval of transaction weight +//! - [`CommonWeightInfo`](pallet_common::CommonWeightInfo): Functions for retrieval of transaction weight //! - [`CommonEvmHandler`](pallet_common::erc::CommonEvmHandler): Function for handling EVM runtime calls #![cfg_attr(not(feature = "std"), no_std)] @@ -728,7 +728,7 @@ /// Transfer fungible tokens from one account to another. /// Same as the [`transfer`][`Pallet::transfer`] but spender doesn't needs to be an owner of the token pieces. /// The owner should set allowance for the spender to transfer pieces. - /// See [`set_allowance`][`Pallet::set_allowance`] for more details. + /// See [`set_allowance`][`Pallet::set_allowance`] for more details. pub fn transfer_from( collection: &FungibleHandle, spender: &T::CrossAccountId, @@ -778,7 +778,7 @@ Ok(()) } - /// Creates fungible token. + /// Creates fungible token. /// /// The sender should be the owner/admin of the collection or collection should be configured /// to allow public minting. @@ -799,7 +799,7 @@ ) } - /// Creates fungible token. + /// Creates fungible token. /// /// - `data`: Contains user who will become the owners of the tokens and amount /// of tokens he will receive. --- a/pallets/identity/src/lib.rs +++ b/pallets/identity/src/lib.rs @@ -95,8 +95,13 @@ mod types; pub mod weights; -use frame_support::traits::{BalanceStatus, Currency, OnUnbalanced, ReservableCurrency}; -use sp_runtime::traits::{AppendZerosInput, Hash, Saturating, StaticLookup, Zero}; +use frame_support::{ + traits::{BalanceStatus, Currency, OnUnbalanced, ReservableCurrency}, +}; +use sp_runtime::{ + BoundedVec, + traits::{AppendZerosInput, Hash, Saturating, StaticLookup, Zero}, +}; use sp_std::prelude::*; pub use weights::WeightInfo; @@ -112,6 +117,18 @@ ::AccountId, >>::NegativeImbalance; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; +type RegistrarInfoOf = RegistrarInfo, ::AccountId>; +type RegistrationOf = + Registration, ::MaxRegistrars, ::MaxAdditionalFields>; +type SubAccounts = + sp_runtime::BoundedVec<::AccountId, ::MaxSubAccounts>; +type SubAccountsByAccountId = ( + ::AccountId, + ( + BalanceOf, + BoundedVec<(::AccountId, Data), ::MaxSubAccounts>, + ), +); #[frame_support::pallet] pub mod pallet { @@ -198,13 +215,8 @@ /// TWOX-NOTE: OK ― `AccountId` is a secure hash. #[pallet::storage] #[pallet::getter(fn subs_of)] - pub(super) type SubsOf = StorageMap< - _, - Twox64Concat, - T::AccountId, - (BalanceOf, BoundedVec), - ValueQuery, - >; + pub(super) type SubsOf = + StorageMap<_, Twox64Concat, T::AccountId, (BalanceOf, SubAccounts), ValueQuery>; /// The set of registrars. Not expected to get very big as can only be added through a /// special origin (likely a council motion). @@ -212,11 +224,8 @@ /// The index into this can be cast to `RegistrarIndex` to get a valid value. #[pallet::storage] #[pallet::getter(fn registrars)] - pub(super) type Registrars = StorageValue< - _, - BoundedVec, T::AccountId>>, T::MaxRegistrars>, - ValueQuery, - >; + pub(super) type Registrars = + StorageValue<_, BoundedVec>, T::MaxRegistrars>, ValueQuery>; #[pallet::error] pub enum Error { @@ -482,18 +491,21 @@ .all(|i| i.0 == sender); ensure!(not_other_sub, Error::::AlreadyClaimed); - if old_deposit < new_deposit { - T::Currency::reserve(&sender, new_deposit - old_deposit)?; - } else if old_deposit > new_deposit { - let err_amount = T::Currency::unreserve(&sender, old_deposit - new_deposit); - debug_assert!(err_amount.is_zero()); + match old_deposit.cmp(&new_deposit) { + core::cmp::Ordering::Less => { + T::Currency::reserve(&sender, new_deposit - old_deposit)? + } + core::cmp::Ordering::Equal => { /* do nothing if they're equal. */ } + core::cmp::Ordering::Greater => { + let err_amount = T::Currency::unreserve(&sender, old_deposit - new_deposit); + debug_assert!(err_amount.is_zero()); + } } - // do nothing if they're equal. for s in old_ids.iter() { >::remove(s); } - let mut ids = BoundedVec::::default(); + let mut ids = >::default(); for (id, name) in subs { >::insert(&id, (sender.clone(), name)); ids.try_push(id) @@ -1107,10 +1119,7 @@ ))] pub fn force_insert_identities( origin: OriginFor, - identities: Vec<( - T::AccountId, - Registration, T::MaxRegistrars, T::MaxAdditionalFields>, - )>, + identities: Vec<(T::AccountId, RegistrationOf)>, ) -> DispatchResult { T::ForceOrigin::ensure_origin(origin)?; for identity in identities.clone() { @@ -1162,13 +1171,7 @@ ))] pub fn force_set_subs( origin: OriginFor, - subs: Vec<( - T::AccountId, - ( - BalanceOf, - BoundedVec<(T::AccountId, Data), T::MaxSubAccounts>, - ), - )>, + subs: Vec>, ) -> DispatchResult { T::ForceOrigin::ensure_origin(origin)?; for identity in subs.clone() { @@ -1178,7 +1181,7 @@ >::remove(old_sub); } - let mut ids = BoundedVec::::default(); + let mut ids = >::default(); for (id, name) in identity.1 .1 { >::insert(&id, (account.clone(), name)); ids.try_push(id) --- a/pallets/inflation/src/lib.rs +++ b/pallets/inflation/src/lib.rs @@ -26,7 +26,7 @@ //! //! * `start_inflation` - This method sets the inflation start date. Can be only called once. //! Inflation start block can be backdated and will catch up. The method will create Treasury -//! account if it does not exist and perform the first inflation deposit. +//! account if it does not exist and perform the first inflation deposit. // #![recursion_limit = "1024"] #![cfg_attr(not(feature = "std"), no_std)] --- a/pallets/refungible/src/lib.rs +++ b/pallets/refungible/src/lib.rs @@ -90,7 +90,7 @@ use crate::erc_token::ERC20Events; use crate::erc::ERC721Events; -use core::ops::Deref; +use core::{ops::Deref, cmp::Ordering}; use evm_coder::ToLog; use frame_support::{ensure, storage::with_transaction, transactional}; use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm}; @@ -1266,44 +1266,48 @@ >::insert((collection.id, token, owner), amount); >::insert((collection.id, token), amount); - if amount > total_pieces { - let mint_amount = amount - total_pieces; - >::deposit_log( - ERC20Events::Transfer { - from: H160::default(), - to: *owner.as_eth(), - value: mint_amount.into(), - } - .to_log(T::EvmTokenAddressMapping::token_to_address( + match total_pieces.cmp(&amount) { + Ordering::Less => { + let mint_amount = amount - total_pieces; + >::deposit_log( + ERC20Events::Transfer { + from: H160::default(), + to: *owner.as_eth(), + value: mint_amount.into(), + } + .to_log(T::EvmTokenAddressMapping::token_to_address( + collection.id, + token, + )), + ); + >::deposit_event(CommonEvent::ItemCreated( collection.id, token, - )), - ); - >::deposit_event(CommonEvent::ItemCreated( - collection.id, - token, - owner.clone(), - mint_amount, - )); - } else if total_pieces > amount { - let burn_amount = total_pieces - amount; - >::deposit_log( - ERC20Events::Transfer { - from: *owner.as_eth(), - to: H160::default(), - value: burn_amount.into(), - } - .to_log(T::EvmTokenAddressMapping::token_to_address( + owner.clone(), + mint_amount, + )); + } + Ordering::Greater => { + let burn_amount = total_pieces - amount; + >::deposit_log( + ERC20Events::Transfer { + from: *owner.as_eth(), + to: H160::default(), + value: burn_amount.into(), + } + .to_log(T::EvmTokenAddressMapping::token_to_address( + collection.id, + token, + )), + ); + >::deposit_event(CommonEvent::ItemDestroyed( collection.id, token, - )), - ); - >::deposit_event(CommonEvent::ItemDestroyed( - collection.id, - token, - owner.clone(), - burn_amount, - )); + owner.clone(), + burn_amount, + )); + } + Ordering::Equal => {} } Ok(()) --- a/runtime/common/ethereum/precompiles/utils/macro/src/lib.rs +++ b/runtime/common/ethereum/precompiles/utils/macro/src/lib.rs @@ -35,8 +35,8 @@ /// ```ignore /// #[generate_function_selector] /// enum Action { -/// Toto = "toto()", -/// Tata = "tata()", +/// Toto = "toto()", +/// Tata = "tata()", /// } /// ``` /// @@ -45,8 +45,8 @@ /// ```rust /// #[repr(u32)] /// enum Action { -/// Toto = 119097542u32, -/// Tata = 1414311903u32, +/// Toto = 119097542u32, +/// Tata = 1414311903u32, /// } /// ``` /// --- a/runtime/common/runtime_apis.rs +++ b/runtime/common/runtime_apis.rs @@ -687,7 +687,7 @@ fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { log::info!("try-runtime::on_runtime_upgrade unique-chain."); let weight = Executive::try_runtime_upgrade(checks).unwrap(); - (weight, crate::config::substrate::RuntimeBlockWeights::get().max_block) + (weight, $crate::config::substrate::RuntimeBlockWeights::get().max_block) } fn execute_block(