difftreelog
style fix clippy warnings
in: master
26 files changed
.maintain/frame-weight-template.hbsdiffbeforeafterboth--- a/.maintain/frame-weight-template.hbs
+++ b/.maintain/frame-weight-template.hbs
@@ -14,6 +14,7 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
+#![allow(clippy::unnecessary_cast)]
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;
Makefilediffbeforeafterboth--- a/Makefile
+++ b/Makefile
@@ -57,9 +57,5 @@
bench-nonfungible:
make _bench PALLET=nonfungible
-.PHONY: bench-evm-coder-substrate
-bench-evm-coder-substrate:
- make _bench PALLET=evm-coder-substrate
-
.PHONY: bench
-bench: bench-evm-migration bench-nft bench-fungible bench-refungible bench-nonfungible bench-evm-coder-substrate
+bench: bench-evm-migration bench-nft bench-fungible bench-refungible bench-nonfungible
crates/evm-coder-macros/src/solidity_interface.rsdiffbeforeafterboth--- a/crates/evm-coder-macros/src/solidity_interface.rs
+++ b/crates/evm-coder-macros/src/solidity_interface.rs
@@ -226,16 +226,10 @@
}
}
fn is_value(&self) -> bool {
- match self {
- Self::Plain(v) if v == "value" => true,
- _ => false,
- }
+ matches!(self, Self::Plain(v) if v == "value")
}
fn is_caller(&self) -> bool {
- match self {
- Self::Plain(v) if v == "caller" => true,
- _ => false,
- }
+ matches!(self, Self::Plain(v) if v == "caller")
}
fn is_special(&self) -> bool {
self.is_caller() || self.is_value()
@@ -599,7 +593,7 @@
#args,
)*
)?;
- (&result).into_result()
+ (&result).to_result()
}
}
}
crates/evm-coder/src/abi.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi.rs
+++ b/crates/evm-coder/src/abi.rs
@@ -310,7 +310,7 @@
pub trait AbiWrite {
fn abi_write(&self, writer: &mut AbiWriter);
- fn into_result(&self) -> ResultWithPostInfo<AbiWriter> {
+ fn to_result(&self) -> ResultWithPostInfo<AbiWriter> {
let mut writer = AbiWriter::new();
self.abi_write(&mut writer);
Ok(writer.into())
@@ -319,7 +319,7 @@
impl<T: AbiWrite> AbiWrite for ResultWithPostInfo<T> {
// this particular AbiWrite implementation should be split to another trait,
- // which only implements [`into_result`]
+ // which only implements [`to_result`]
//
// But due to lack of specialization feature in stable Rust, we can't have
// blanket impl of this trait `for T where T: AbiWrite`, so here we abusing
@@ -327,7 +327,7 @@
fn abi_write(&self, _writer: &mut AbiWriter) {
debug_assert!(false, "shouldn't be called, see comment")
}
- fn into_result(&self) -> ResultWithPostInfo<AbiWriter> {
+ fn to_result(&self) -> ResultWithPostInfo<AbiWriter> {
match self {
Ok(v) => Ok(WithPostDispatchInfo {
post_info: v.post_info.clone(),
node/rpc/src/lib.rsdiffbeforeafterboth--- a/node/rpc/src/lib.rs
+++ b/node/rpc/src/lib.rs
@@ -214,7 +214,7 @@
500_usize, // max stored filters
overrides.clone(),
max_past_logs,
- block_data_cache.clone(),
+ block_data_cache,
)));
}
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -51,7 +51,7 @@
Self::new_with_gas_limit(id, u64::MAX)
}
pub fn try_get(id: CollectionId) -> Result<Self, DispatchError> {
- Ok(Self::new(id).ok_or_else(|| <Error<T>>::CollectionNotFound)?)
+ Ok(Self::new(id).ok_or(<Error<T>>::CollectionNotFound)?)
}
pub fn log(&self, log: impl evm_coder::ToLog) {
self.recorder.log(log)
@@ -453,7 +453,7 @@
collection.limits.owner_can_destroy(),
<Error<T>>::NoPermission,
);
- collection.check_is_owner(&sender)?;
+ collection.check_is_owner(sender)?;
let destroyed_collections = <DestroyedCollectionCount<T>>::get()
.0
@@ -476,7 +476,7 @@
user: &T::CrossAccountId,
allowed: bool,
) -> DispatchResult {
- collection.check_is_owner_or_admin(&sender)?;
+ collection.check_is_owner_or_admin(sender)?;
// =========
@@ -495,7 +495,7 @@
user: &T::CrossAccountId,
admin: bool,
) -> DispatchResult {
- collection.check_is_owner_or_admin(&sender)?;
+ collection.check_is_owner_or_admin(sender)?;
let was_admin = <IsAdmin<T>>::get((collection.id, user));
if was_admin == admin {
pallets/evm-contract-helpers/exp.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/exp.rs
+++ b/pallets/evm-contract-helpers/exp.rs
@@ -532,11 +532,11 @@
match c.call {
InternalCall::ContractOwner { contract_address } => {
let result = self.contract_owner(contract_address)?;
- (&result).into_result()
+ (&result).to_result()
}
InternalCall::SponsoringEnabled { contract_address } => {
let result = self.sponsoring_enabled(contract_address)?;
- (&result).into_result()
+ (&result).to_result()
}
InternalCall::ToggleSponsoring {
contract_address,
@@ -544,7 +544,7 @@
} => {
let result =
self.toggle_sponsoring(c.caller.clone(), contract_address, enabled)?;
- (&result).into_result()
+ (&result).to_result()
}
InternalCall::SetSponsoringRateLimit {
contract_address,
@@ -555,22 +555,22 @@
contract_address,
rate_limit,
)?;
- (&result).into_result()
+ (&result).to_result()
}
InternalCall::GetSponsoringRateLimit { contract_address } => {
let result = self.get_sponsoring_rate_limit(contract_address)?;
- (&result).into_result()
+ (&result).to_result()
}
InternalCall::Allowed {
contract_address,
user,
} => {
let result = self.allowed(contract_address, user)?;
- (&result).into_result()
+ (&result).to_result()
}
InternalCall::AllowlistEnabled { contract_address } => {
let result = self.allowlist_enabled(contract_address)?;
- (&result).into_result()
+ (&result).to_result()
}
InternalCall::ToggleAllowlist {
contract_address,
@@ -578,7 +578,7 @@
} => {
let result =
self.toggle_allowlist(c.caller.clone(), contract_address, enabled)?;
- (&result).into_result()
+ (&result).to_result()
}
InternalCall::ToggleAllowed {
contract_address,
@@ -587,7 +587,7 @@
} => {
let result =
self.toggle_allowed(c.caller.clone(), contract_address, user, allowed)?;
- (&result).into_result()
+ (&result).to_result()
}
_ => ::core::panicking::panic("internal error: entered unreachable code"),
}
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -1,10 +1,7 @@
use core::marker::PhantomData;
use evm_coder::{abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*};
use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
-use pallet_evm::{
- ExitReason, ExitRevert, OnCreate, OnMethodCall, PrecompileOutput, PrecompileResult,
- PrecompileFailure,
-};
+use pallet_evm::{ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure};
use sp_core::H160;
use crate::{
AllowlistEnabled, Config, Owner, Pallet, SelfSponsoring, SponsorBasket, SponsoringRateLimit,
@@ -161,7 +158,7 @@
if let Some(last_tx_block) = <SponsorBasket<T>>::get(&call.0, who) {
let limit = <SponsoringRateLimit<T>>::get(&call.0);
- let timeout = last_tx_block + limit.into();
+ let timeout = last_tx_block + limit;
if block_number < timeout {
return None;
}
pallets/evm-migration/src/weights.rsdiffbeforeafterboth--- a/pallets/evm-migration/src/weights.rs
+++ b/pallets/evm-migration/src/weights.rs
@@ -25,6 +25,7 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
+#![allow(clippy::unnecessary_cast)]
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;
pallets/evm-transaction-payment/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-transaction-payment/src/lib.rs
+++ b/pallets/evm-transaction-payment/src/lib.rs
@@ -128,7 +128,7 @@
let sponsor = frame_support::storage::with_transaction(|| {
TransactionOutcome::Rollback(T::EvmSponsorshipHandler::get_sponsor(
&who,
- &(target.clone(), input.clone()),
+ &(*target, input.clone()),
))
})?;
let sponsor = T::EvmAddressMapping::into_account_id(sponsor);
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -116,7 +116,7 @@
);
with_weight(
- <Pallet<T>>::transfer(&self, &from, &to, amount),
+ <Pallet<T>>::transfer(self, &from, &to, amount),
<CommonWeights<T>>::transfer(),
)
}
@@ -134,7 +134,7 @@
);
with_weight(
- <Pallet<T>>::set_allowance(&self, &sender, &spender, amount),
+ <Pallet<T>>::set_allowance(self, &sender, &spender, amount),
<CommonWeights<T>>::approve(),
)
}
@@ -153,7 +153,7 @@
);
with_weight(
- <Pallet<T>>::transfer_from(&self, &sender, &from, &to, amount),
+ <Pallet<T>>::transfer_from(self, &sender, &from, &to, amount),
<CommonWeights<T>>::transfer_from(),
)
}
@@ -171,7 +171,7 @@
);
with_weight(
- <Pallet<T>>::burn_from(&self, &sender, &from, amount),
+ <Pallet<T>>::burn_from(self, &sender, &from, amount),
<CommonWeights<T>>::burn_from(),
)
}
pallets/fungible/src/erc.rsdiffbeforeafterboth--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -6,7 +6,6 @@
use sp_core::{H160, U256};
use sp_std::vec::Vec;
use pallet_common::account::CrossAccountId;
-use pallet_common::erc::PrecompileOutput;
use pallet_evm_coder_substrate::{call, dispatch_to_evm};
use crate::{
pallets/fungible/src/lib.rsdiffbeforeafterboth1#![cfg_attr(not(feature = "std"), no_std)]23use core::ops::Deref;4use frame_support::{ensure};5use nft_data_structs::{AccessMode, Collection, CollectionId, TokenId};6use pallet_common::{7 Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, account::CrossAccountId,8};9use pallet_evm_coder_substrate::WithRecorder;10use sp_core::H160;11use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};12use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};1314pub use pallet::*;1516use crate::erc::ERC20Events;17#[cfg(feature = "runtime-benchmarks")]18pub mod benchmarking;19pub mod common;20pub mod erc;21pub mod weights;2223pub type CreateItemData<T> = (<T as pallet_common::Config>::CrossAccountId, u128);24pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;2526#[frame_support::pallet]27pub mod pallet {28 use frame_support::{Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key};29 use nft_data_structs::CollectionId;30 use super::weights::WeightInfo;3132 #[pallet::error]33 pub enum Error<T> {34 /// Not Fungible item data used to mint in Fungible collection.35 NotFungibleDataUsedToMintFungibleCollectionToken,36 /// Not default id passed as TokenId argument37 FungibleItemsHaveNoId,38 /// Tried to set data for fungible item39 FungibleItemsHaveData,40 }4142 #[pallet::config]43 pub trait Config: frame_system::Config + pallet_common::Config {44 type WeightInfo: WeightInfo;45 }4647 #[pallet::pallet]48 #[pallet::generate_store(pub(super) trait Store)]49 pub struct Pallet<T>(_);5051 #[pallet::storage]52 pub(super) type TotalSupply<T: Config> =53 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;5455 #[pallet::storage]56 pub type Balance<T: Config> = StorageNMap<57 Key = (58 Key<Twox64Concat, CollectionId>,59 Key<Blake2_128Concat, T::CrossAccountId>,60 ),61 Value = u128,62 QueryKind = ValueQuery,63 >;6465 #[pallet::storage]66 pub(super) type Allowance<T: Config> = StorageNMap<67 Key = (68 Key<Twox64Concat, CollectionId>,69 Key<Blake2_128, T::CrossAccountId>,70 Key<Blake2_128Concat, T::CrossAccountId>,71 ),72 Value = u128,73 QueryKind = ValueQuery,74 >;75}7677pub struct FungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);78impl<T: Config> FungibleHandle<T> {79 pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {80 Self(inner)81 }82 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {83 self.084 }85}86impl<T: Config> WithRecorder<T> for FungibleHandle<T> {87 fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {88 self.0.recorder()89 }90 fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {91 self.0.into_recorder()92 }93}94impl<T: Config> Deref for FungibleHandle<T> {95 type Target = pallet_common::CollectionHandle<T>;9697 fn deref(&self) -> &Self::Target {98 &self.099 }100}101102impl<T: Config> Pallet<T> {103 pub fn init_collection(data: Collection<T::AccountId>) -> Result<CollectionId, DispatchError> {104 <PalletCommon<T>>::init_collection(data)105 }106 pub fn destroy_collection(107 collection: FungibleHandle<T>,108 sender: &T::CrossAccountId,109 ) -> DispatchResult {110 let id = collection.id;111112 // =========113114 PalletCommon::destroy_collection(collection.0, sender)?;115116 <TotalSupply<T>>::remove(id);117 <Balance<T>>::remove_prefix((id,), None);118 <Allowance<T>>::remove_prefix((id,), None);119 Ok(())120 }121122 pub fn burn(123 collection: &FungibleHandle<T>,124 owner: &T::CrossAccountId,125 amount: u128,126 ) -> DispatchResult {127 let total_supply = <TotalSupply<T>>::get(collection.id)128 .checked_sub(amount)129 .ok_or(<CommonError<T>>::TokenValueTooLow)?;130131 let balance = <Balance<T>>::get((collection.id, owner))132 .checked_sub(amount)133 .ok_or(<CommonError<T>>::TokenValueTooLow)?;134135 if collection.access == AccessMode::AllowList {136 collection.check_allowlist(owner)?;137 }138139 // =========140141 if balance == 0 {142 <Balance<T>>::remove((collection.id, owner));143 } else {144 <Balance<T>>::insert((collection.id, owner), balance);145 }146 <TotalSupply<T>>::insert(collection.id, total_supply);147148 collection.log(ERC20Events::Transfer {149 from: *owner.as_eth(),150 to: H160::default(),151 value: amount.into(),152 });153 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(154 collection.id,155 TokenId::default(),156 owner.clone(),157 amount,158 ));159 Ok(())160 }161162 pub fn transfer(163 collection: &FungibleHandle<T>,164 from: &T::CrossAccountId,165 to: &T::CrossAccountId,166 amount: u128,167 ) -> DispatchResult {168 ensure!(169 collection.limits.transfers_enabled(),170 <CommonError<T>>::TransferNotAllowed,171 );172173 if collection.access == AccessMode::AllowList {174 collection.check_allowlist(from)?;175 collection.check_allowlist(to)?;176 }177 <PalletCommon<T>>::ensure_correct_receiver(to)?;178179 let balance_from = <Balance<T>>::get((collection.id, from))180 .checked_sub(amount)181 .ok_or(<CommonError<T>>::TokenValueTooLow)?;182 let balance_to = if from != to {183 Some(184 <Balance<T>>::get((collection.id, to))185 .checked_add(amount)186 .ok_or(ArithmeticError::Overflow)?,187 )188 } else {189 None190 };191192 // =========193194 if let Some(balance_to) = balance_to {195 // from != to196 if balance_from == 0 {197 <Balance<T>>::remove((collection.id, from));198 } else {199 <Balance<T>>::insert((collection.id, from), balance_from);200 }201 <Balance<T>>::insert((collection.id, to), balance_to);202 }203204 collection.log(ERC20Events::Transfer {205 from: *from.as_eth(),206 to: *to.as_eth(),207 value: amount.into(),208 });209 <PalletCommon<T>>::deposit_event(CommonEvent::Transfer(210 collection.id,211 TokenId::default(),212 from.clone(),213 to.clone(),214 amount,215 ));216 Ok(())217 }218219 pub fn create_multiple_items(220 collection: &FungibleHandle<T>,221 sender: &T::CrossAccountId,222 data: Vec<CreateItemData<T>>,223 ) -> DispatchResult {224 if !collection.is_owner_or_admin(sender) {225 ensure!(226 collection.mint_mode,227 <CommonError<T>>::PublicMintingNotAllowed228 );229 collection.check_allowlist(sender)?;230231 for (owner, _) in data.iter() {232 collection.check_allowlist(owner)?;233 }234 }235236 let mut balances = BTreeMap::new();237238 let total_supply = data239 .iter()240 .map(|u| u.1)241 .try_fold(<TotalSupply<T>>::get(collection.id), |acc, v| {242 acc.checked_add(v)243 })244 .ok_or(ArithmeticError::Overflow)?;245246 for (user, amount) in data.into_iter() {247 let balance = balances248 .entry(user.clone())249 .or_insert_with(|| <Balance<T>>::get((collection.id, user)));250 *balance = (*balance)251 .checked_add(amount)252 .ok_or(ArithmeticError::Overflow)?;253 }254255 // =========256257 <TotalSupply<T>>::insert(collection.id, total_supply);258 for (user, amount) in balances {259 <Balance<T>>::insert((collection.id, &user), amount);260261 collection.log(ERC20Events::Transfer {262 from: H160::default(),263 to: *user.as_eth(),264 value: amount.into(),265 });266 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(267 collection.id,268 TokenId::default(),269 user.clone(),270 amount,271 ));272 }273274 Ok(())275 }276277 fn set_allowance_unchecked(278 collection: &FungibleHandle<T>,279 owner: &T::CrossAccountId,280 spender: &T::CrossAccountId,281 amount: u128,282 ) {283 <Allowance<T>>::insert((collection.id, owner, spender), amount);284285 collection.log(ERC20Events::Approval {286 owner: *owner.as_eth(),287 spender: *spender.as_eth(),288 value: amount.into(),289 });290 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(291 collection.id,292 TokenId(0),293 owner.clone(),294 spender.clone(),295 amount,296 ));297 }298299 pub fn set_allowance(300 collection: &FungibleHandle<T>,301 owner: &T::CrossAccountId,302 spender: &T::CrossAccountId,303 amount: u128,304 ) -> DispatchResult {305 if collection.access == AccessMode::AllowList {306 collection.check_allowlist(&owner)?;307 collection.check_allowlist(&spender)?;308 }309310 if <Balance<T>>::get((collection.id, owner)) < amount {311 ensure!(312 collection.ignores_owned_amount(owner),313 <CommonError<T>>::CantApproveMoreThanOwned314 );315 }316317 // =========318319 Self::set_allowance_unchecked(collection, owner, spender, amount);320 Ok(())321 }322323 pub fn transfer_from(324 collection: &FungibleHandle<T>,325 spender: &T::CrossAccountId,326 from: &T::CrossAccountId,327 to: &T::CrossAccountId,328 amount: u128,329 ) -> DispatchResult {330 if spender.conv_eq(from) {331 return Self::transfer(collection, from, to, amount);332 }333 if collection.access == AccessMode::AllowList {334 // `from`, `to` checked in [`transfer`]335 collection.check_allowlist(spender)?;336 }337338 let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);339 if allowance.is_none() {340 ensure!(341 collection.ignores_allowance(spender),342 <CommonError<T>>::TokenValueNotEnough343 );344 }345346 // =========347348 Self::transfer(collection, from, to, amount)?;349 if let Some(allowance) = allowance {350 Self::set_allowance_unchecked(collection, from, spender, allowance);351 }352 Ok(())353 }354355 pub fn burn_from(356 collection: &FungibleHandle<T>,357 spender: &T::CrossAccountId,358 from: &T::CrossAccountId,359 amount: u128,360 ) -> DispatchResult {361 if spender.conv_eq(from) {362 return Self::burn(collection, from, amount);363 }364 if collection.access == AccessMode::AllowList {365 // `from` checked in [`burn`]366 collection.check_allowlist(spender)?;367 }368369 let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);370 if allowance.is_none() {371 ensure!(372 collection.ignores_allowance(spender),373 <CommonError<T>>::TokenValueNotEnough374 );375 }376377 // =========378379 Self::burn(collection, from, amount)?;380 if let Some(allowance) = allowance {381 Self::set_allowance_unchecked(collection, from, spender, allowance);382 }383 Ok(())384 }385386 /// Delegated to `create_multiple_items`387 pub fn create_item(388 collection: &FungibleHandle<T>,389 sender: &T::CrossAccountId,390 data: CreateItemData<T>,391 ) -> DispatchResult {392 Self::create_multiple_items(collection, sender, vec![data])393 }394}1#![cfg_attr(not(feature = "std"), no_std)]23use core::ops::Deref;4use frame_support::{ensure};5use nft_data_structs::{AccessMode, Collection, CollectionId, TokenId};6use pallet_common::{7 Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, account::CrossAccountId,8};9use pallet_evm_coder_substrate::WithRecorder;10use sp_core::H160;11use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};12use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};1314pub use pallet::*;1516use crate::erc::ERC20Events;17#[cfg(feature = "runtime-benchmarks")]18pub mod benchmarking;19pub mod common;20pub mod erc;21pub mod weights;2223pub type CreateItemData<T> = (<T as pallet_common::Config>::CrossAccountId, u128);24pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;2526#[frame_support::pallet]27pub mod pallet {28 use frame_support::{Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key};29 use nft_data_structs::CollectionId;30 use super::weights::WeightInfo;3132 #[pallet::error]33 pub enum Error<T> {34 /// Not Fungible item data used to mint in Fungible collection.35 NotFungibleDataUsedToMintFungibleCollectionToken,36 /// Not default id passed as TokenId argument37 FungibleItemsHaveNoId,38 /// Tried to set data for fungible item39 FungibleItemsHaveData,40 }4142 #[pallet::config]43 pub trait Config: frame_system::Config + pallet_common::Config {44 type WeightInfo: WeightInfo;45 }4647 #[pallet::pallet]48 #[pallet::generate_store(pub(super) trait Store)]49 pub struct Pallet<T>(_);5051 #[pallet::storage]52 pub(super) type TotalSupply<T: Config> =53 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;5455 #[pallet::storage]56 pub type Balance<T: Config> = StorageNMap<57 Key = (58 Key<Twox64Concat, CollectionId>,59 Key<Blake2_128Concat, T::CrossAccountId>,60 ),61 Value = u128,62 QueryKind = ValueQuery,63 >;6465 #[pallet::storage]66 pub(super) type Allowance<T: Config> = StorageNMap<67 Key = (68 Key<Twox64Concat, CollectionId>,69 Key<Blake2_128, T::CrossAccountId>,70 Key<Blake2_128Concat, T::CrossAccountId>,71 ),72 Value = u128,73 QueryKind = ValueQuery,74 >;75}7677pub struct FungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);78impl<T: Config> FungibleHandle<T> {79 pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {80 Self(inner)81 }82 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {83 self.084 }85}86impl<T: Config> WithRecorder<T> for FungibleHandle<T> {87 fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {88 self.0.recorder()89 }90 fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {91 self.0.into_recorder()92 }93}94impl<T: Config> Deref for FungibleHandle<T> {95 type Target = pallet_common::CollectionHandle<T>;9697 fn deref(&self) -> &Self::Target {98 &self.099 }100}101102impl<T: Config> Pallet<T> {103 pub fn init_collection(data: Collection<T::AccountId>) -> Result<CollectionId, DispatchError> {104 <PalletCommon<T>>::init_collection(data)105 }106 pub fn destroy_collection(107 collection: FungibleHandle<T>,108 sender: &T::CrossAccountId,109 ) -> DispatchResult {110 let id = collection.id;111112 // =========113114 PalletCommon::destroy_collection(collection.0, sender)?;115116 <TotalSupply<T>>::remove(id);117 <Balance<T>>::remove_prefix((id,), None);118 <Allowance<T>>::remove_prefix((id,), None);119 Ok(())120 }121122 pub fn burn(123 collection: &FungibleHandle<T>,124 owner: &T::CrossAccountId,125 amount: u128,126 ) -> DispatchResult {127 let total_supply = <TotalSupply<T>>::get(collection.id)128 .checked_sub(amount)129 .ok_or(<CommonError<T>>::TokenValueTooLow)?;130131 let balance = <Balance<T>>::get((collection.id, owner))132 .checked_sub(amount)133 .ok_or(<CommonError<T>>::TokenValueTooLow)?;134135 if collection.access == AccessMode::AllowList {136 collection.check_allowlist(owner)?;137 }138139 // =========140141 if balance == 0 {142 <Balance<T>>::remove((collection.id, owner));143 } else {144 <Balance<T>>::insert((collection.id, owner), balance);145 }146 <TotalSupply<T>>::insert(collection.id, total_supply);147148 collection.log(ERC20Events::Transfer {149 from: *owner.as_eth(),150 to: H160::default(),151 value: amount.into(),152 });153 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(154 collection.id,155 TokenId::default(),156 owner.clone(),157 amount,158 ));159 Ok(())160 }161162 pub fn transfer(163 collection: &FungibleHandle<T>,164 from: &T::CrossAccountId,165 to: &T::CrossAccountId,166 amount: u128,167 ) -> DispatchResult {168 ensure!(169 collection.limits.transfers_enabled(),170 <CommonError<T>>::TransferNotAllowed,171 );172173 if collection.access == AccessMode::AllowList {174 collection.check_allowlist(from)?;175 collection.check_allowlist(to)?;176 }177 <PalletCommon<T>>::ensure_correct_receiver(to)?;178179 let balance_from = <Balance<T>>::get((collection.id, from))180 .checked_sub(amount)181 .ok_or(<CommonError<T>>::TokenValueTooLow)?;182 let balance_to = if from != to {183 Some(184 <Balance<T>>::get((collection.id, to))185 .checked_add(amount)186 .ok_or(ArithmeticError::Overflow)?,187 )188 } else {189 None190 };191192 // =========193194 if let Some(balance_to) = balance_to {195 // from != to196 if balance_from == 0 {197 <Balance<T>>::remove((collection.id, from));198 } else {199 <Balance<T>>::insert((collection.id, from), balance_from);200 }201 <Balance<T>>::insert((collection.id, to), balance_to);202 }203204 collection.log(ERC20Events::Transfer {205 from: *from.as_eth(),206 to: *to.as_eth(),207 value: amount.into(),208 });209 <PalletCommon<T>>::deposit_event(CommonEvent::Transfer(210 collection.id,211 TokenId::default(),212 from.clone(),213 to.clone(),214 amount,215 ));216 Ok(())217 }218219 pub fn create_multiple_items(220 collection: &FungibleHandle<T>,221 sender: &T::CrossAccountId,222 data: Vec<CreateItemData<T>>,223 ) -> DispatchResult {224 if !collection.is_owner_or_admin(sender) {225 ensure!(226 collection.mint_mode,227 <CommonError<T>>::PublicMintingNotAllowed228 );229 collection.check_allowlist(sender)?;230231 for (owner, _) in data.iter() {232 collection.check_allowlist(owner)?;233 }234 }235236 let mut balances = BTreeMap::new();237238 let total_supply = data239 .iter()240 .map(|u| u.1)241 .try_fold(<TotalSupply<T>>::get(collection.id), |acc, v| {242 acc.checked_add(v)243 })244 .ok_or(ArithmeticError::Overflow)?;245246 for (user, amount) in data.into_iter() {247 let balance = balances248 .entry(user.clone())249 .or_insert_with(|| <Balance<T>>::get((collection.id, user)));250 *balance = (*balance)251 .checked_add(amount)252 .ok_or(ArithmeticError::Overflow)?;253 }254255 // =========256257 <TotalSupply<T>>::insert(collection.id, total_supply);258 for (user, amount) in balances {259 <Balance<T>>::insert((collection.id, &user), amount);260261 collection.log(ERC20Events::Transfer {262 from: H160::default(),263 to: *user.as_eth(),264 value: amount.into(),265 });266 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(267 collection.id,268 TokenId::default(),269 user.clone(),270 amount,271 ));272 }273274 Ok(())275 }276277 fn set_allowance_unchecked(278 collection: &FungibleHandle<T>,279 owner: &T::CrossAccountId,280 spender: &T::CrossAccountId,281 amount: u128,282 ) {283 <Allowance<T>>::insert((collection.id, owner, spender), amount);284285 collection.log(ERC20Events::Approval {286 owner: *owner.as_eth(),287 spender: *spender.as_eth(),288 value: amount.into(),289 });290 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(291 collection.id,292 TokenId(0),293 owner.clone(),294 spender.clone(),295 amount,296 ));297 }298299 pub fn set_allowance(300 collection: &FungibleHandle<T>,301 owner: &T::CrossAccountId,302 spender: &T::CrossAccountId,303 amount: u128,304 ) -> DispatchResult {305 if collection.access == AccessMode::AllowList {306 collection.check_allowlist(owner)?;307 collection.check_allowlist(spender)?;308 }309310 if <Balance<T>>::get((collection.id, owner)) < amount {311 ensure!(312 collection.ignores_owned_amount(owner),313 <CommonError<T>>::CantApproveMoreThanOwned314 );315 }316317 // =========318319 Self::set_allowance_unchecked(collection, owner, spender, amount);320 Ok(())321 }322323 pub fn transfer_from(324 collection: &FungibleHandle<T>,325 spender: &T::CrossAccountId,326 from: &T::CrossAccountId,327 to: &T::CrossAccountId,328 amount: u128,329 ) -> DispatchResult {330 if spender.conv_eq(from) {331 return Self::transfer(collection, from, to, amount);332 }333 if collection.access == AccessMode::AllowList {334 // `from`, `to` checked in [`transfer`]335 collection.check_allowlist(spender)?;336 }337338 let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);339 if allowance.is_none() {340 ensure!(341 collection.ignores_allowance(spender),342 <CommonError<T>>::TokenValueNotEnough343 );344 }345346 // =========347348 Self::transfer(collection, from, to, amount)?;349 if let Some(allowance) = allowance {350 Self::set_allowance_unchecked(collection, from, spender, allowance);351 }352 Ok(())353 }354355 pub fn burn_from(356 collection: &FungibleHandle<T>,357 spender: &T::CrossAccountId,358 from: &T::CrossAccountId,359 amount: u128,360 ) -> DispatchResult {361 if spender.conv_eq(from) {362 return Self::burn(collection, from, amount);363 }364 if collection.access == AccessMode::AllowList {365 // `from` checked in [`burn`]366 collection.check_allowlist(spender)?;367 }368369 let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);370 if allowance.is_none() {371 ensure!(372 collection.ignores_allowance(spender),373 <CommonError<T>>::TokenValueNotEnough374 );375 }376377 // =========378379 Self::burn(collection, from, amount)?;380 if let Some(allowance) = allowance {381 Self::set_allowance_unchecked(collection, from, spender, allowance);382 }383 Ok(())384 }385386 /// Delegated to `create_multiple_items`387 pub fn create_item(388 collection: &FungibleHandle<T>,389 sender: &T::CrossAccountId,390 data: CreateItemData<T>,391 ) -> DispatchResult {392 Self::create_multiple_items(collection, sender, vec![data])393 }394}pallets/fungible/src/weights.rsdiffbeforeafterboth--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -25,6 +25,7 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
+#![allow(clippy::unnecessary_cast)]
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;
@@ -32,11 +33,11 @@
/// Weight functions needed for pallet_fungible.
pub trait WeightInfo {
fn create_item() -> Weight;
- fn burn_from() -> Weight;
fn burn_item() -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
fn transfer_from() -> Weight;
+ fn burn_from() -> Weight;
}
/// Weights for pallet_fungible using the Substrate node and recommended hardware.
pallets/nft/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nft/src/benchmarking.rs
+++ b/pallets/nft/src/benchmarking.rs
@@ -158,6 +158,7 @@
sponsored_data_size: Some(0),
token_limit: Some(1),
sponsor_transfer_timeout: Some(0),
+ sponsor_approve_timeout: None,
owner_can_destroy: Some(true),
owner_can_transfer: Some(true),
sponsored_data_rate_limit: None,
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -195,7 +195,7 @@
// Create new collection
let new_collection = Collection {
- owner: who.clone(),
+ owner: who,
name: collection_name,
mode: mode.clone(),
mint_mode: false,
pallets/nft/src/weights.rsdiffbeforeafterboth--- a/pallets/nft/src/weights.rs
+++ b/pallets/nft/src/weights.rs
@@ -25,6 +25,7 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
+#![allow(clippy::unnecessary_cast)]
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -100,7 +100,7 @@
ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);
if amount == 1 {
with_weight(
- <Pallet<T>>::burn(&self, &sender, token),
+ <Pallet<T>>::burn(self, &sender, token),
<CommonWeights<T>>::burn_item(),
)
} else {
@@ -118,7 +118,7 @@
ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);
if amount == 1 {
with_weight(
- <Pallet<T>>::transfer(&self, &from, &to, token),
+ <Pallet<T>>::transfer(self, &from, &to, token),
<CommonWeights<T>>::transfer(),
)
} else {
@@ -137,9 +137,9 @@
with_weight(
if amount == 1 {
- <Pallet<T>>::set_allowance(&self, &sender, token, Some(&spender))
+ <Pallet<T>>::set_allowance(self, &sender, token, Some(&spender))
} else {
- <Pallet<T>>::set_allowance(&self, &sender, token, None)
+ <Pallet<T>>::set_allowance(self, &sender, token, None)
},
<CommonWeights<T>>::approve(),
)
@@ -157,7 +157,7 @@
if amount == 1 {
with_weight(
- <Pallet<T>>::transfer_from(&self, &sender, &from, &to, token),
+ <Pallet<T>>::transfer_from(self, &sender, &from, &to, token),
<CommonWeights<T>>::transfer_from(),
)
} else {
@@ -176,7 +176,7 @@
if amount == 1 {
with_weight(
- <Pallet<T>>::burn_from(&self, &sender, &from, token),
+ <Pallet<T>>::burn_from(self, &sender, &from, token),
<CommonWeights<T>>::burn_from(),
)
} else {
@@ -192,7 +192,7 @@
) -> DispatchResultWithPostInfo {
let len = data.len();
with_weight(
- <Pallet<T>>::set_variable_metadata(&self, &sender, token, data),
+ <Pallet<T>>::set_variable_metadata(self, &sender, token, data),
<CommonWeights<T>>::set_variable_metadata(len as u32),
)
}
@@ -218,12 +218,12 @@
}
fn const_metadata(&self, token: TokenId) -> Vec<u8> {
<TokenData<T>>::get((self.id, token))
- .map(|t| t.const_data.clone())
+ .map(|t| t.const_data)
.unwrap_or_default()
}
fn variable_metadata(&self, token: TokenId) -> Vec<u8> {
<TokenData<T>>::get((self.id, token))
- .map(|t| t.variable_data.clone())
+ .map(|t| t.variable_data)
.unwrap_or_default()
}
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -13,7 +13,6 @@
erc::{CommonEvmHandler, PrecompileResult},
};
use pallet_evm_coder_substrate::call;
-use pallet_common::erc::PrecompileOutput;
use crate::{
AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -169,8 +169,8 @@
sender: &T::CrossAccountId,
token: TokenId,
) -> DispatchResult {
- let token_data = <TokenData<T>>::get((collection.id, token))
- .ok_or_else(|| <CommonError<T>>::TokenNotFound)?;
+ let token_data =
+ <TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
ensure!(
&token_data.owner == sender
|| (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(sender)),
@@ -197,7 +197,7 @@
collection.id,
token,
sender.clone(),
- old_spender.clone(),
+ old_spender,
0,
));
}
@@ -213,7 +213,7 @@
token_data.owner,
1,
));
- return Ok(());
+ Ok(())
}
pub fn transfer(
@@ -227,8 +227,8 @@
<CommonError<T>>::TransferNotAllowed
);
- let token_data = <TokenData<T>>::get((collection.id, token))
- .ok_or_else(|| <CommonError<T>>::TokenNotFound)?;
+ let token_data =
+ <TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
ensure!(
&token_data.owner == from
|| (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(from)),
@@ -399,7 +399,7 @@
collection.id,
token,
sender.clone(),
- old_owner.clone(),
+ old_owner,
0,
));
}
@@ -429,7 +429,7 @@
collection.id,
token,
sender.clone(),
- old_spender.clone(),
+ old_spender,
0,
));
}
@@ -443,9 +443,9 @@
spender: Option<&T::CrossAccountId>,
) -> DispatchResult {
if collection.access == AccessMode::AllowList {
- collection.check_allowlist(&sender)?;
+ collection.check_allowlist(sender)?;
if let Some(spender) = spender {
- collection.check_allowlist(&spender)?;
+ collection.check_allowlist(spender)?;
}
}
@@ -491,7 +491,7 @@
// =========
- Self::transfer(collection, &from, to, token)?;
+ Self::transfer(collection, from, to, token)?;
// Allowance is reset in [`transfer`]
Ok(())
}
@@ -519,7 +519,7 @@
// =========
- Self::burn(collection, &from, token)
+ Self::burn(collection, from, token)
}
pub fn set_variable_metadata(
pallets/nonfungible/src/weights.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -25,6 +25,7 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
+#![allow(clippy::unnecessary_cast)]
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;
@@ -33,11 +34,11 @@
pub trait WeightInfo {
fn create_item() -> Weight;
fn create_multiple_items(b: u32, ) -> Weight;
- fn burn_from() -> Weight;
fn burn_item() -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
fn transfer_from() -> Weight;
+ fn burn_from() -> Weight;
fn set_variable_metadata(b: u32, ) -> Weight;
}
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -135,7 +135,7 @@
amount: u128,
) -> DispatchResultWithPostInfo {
with_weight(
- <Pallet<T>>::transfer(&self, &from, &to, token, amount),
+ <Pallet<T>>::transfer(self, &from, &to, token, amount),
<CommonWeights<T>>::transfer(),
)
}
@@ -148,7 +148,7 @@
amount: u128,
) -> DispatchResultWithPostInfo {
with_weight(
- <Pallet<T>>::set_allowance(&self, &sender, &spender, token, amount),
+ <Pallet<T>>::set_allowance(self, &sender, &spender, token, amount),
<CommonWeights<T>>::approve(),
)
}
@@ -162,7 +162,7 @@
amount: u128,
) -> DispatchResultWithPostInfo {
with_weight(
- <Pallet<T>>::transfer_from(&self, &sender, &from, &to, token, amount),
+ <Pallet<T>>::transfer_from(self, &sender, &from, &to, token, amount),
<CommonWeights<T>>::transfer_from(),
)
}
@@ -175,7 +175,7 @@
amount: u128,
) -> DispatchResultWithPostInfo {
with_weight(
- <Pallet<T>>::burn_from(&self, &sender, &from, token, amount),
+ <Pallet<T>>::burn_from(self, &sender, &from, token, amount),
<CommonWeights<T>>::burn_from(),
)
}
@@ -188,7 +188,7 @@
) -> DispatchResultWithPostInfo {
let len = data.len();
with_weight(
- <Pallet<T>>::set_variable_metadata(&self, &sender, token, data),
+ <Pallet<T>>::set_variable_metadata(self, &sender, token, data),
<CommonWeights<T>>::set_variable_metadata(len as u32),
)
}
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -189,7 +189,7 @@
<Balance<T>>::remove_prefix((collection.id, token_id), None);
<Allowance<T>>::remove_prefix((collection.id, token_id), None);
// TODO: ERC721 transfer event
- return Ok(());
+ Ok(())
}
pub fn burn(
@@ -367,8 +367,8 @@
collection.check_allowlist(sender)?;
for item in data.iter() {
- for (user, _) in &item.users {
- collection.check_allowlist(&user)?;
+ for user in item.users.keys() {
+ collection.check_allowlist(user)?;
}
}
}
@@ -409,7 +409,7 @@
let mut balances = BTreeMap::new();
for data in &data {
- for (owner, _) in &data.users {
+ for owner in data.users.keys() {
let balance = balances
.entry(owner)
.or_insert_with(|| <AccountBalance<T>>::get((collection.id, owner)));
@@ -483,8 +483,8 @@
amount: u128,
) -> DispatchResult {
if collection.access == AccessMode::AllowList {
- collection.check_allowlist(&sender)?;
- collection.check_allowlist(&spender)?;
+ collection.check_allowlist(sender)?;
+ collection.check_allowlist(spender)?;
}
<PalletCommon<T>>::ensure_correct_receiver(spender)?;
pallets/refungible/src/weights.rsdiffbeforeafterboth--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -25,6 +25,7 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
+#![allow(clippy::unnecessary_cast)]
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;
@@ -33,7 +34,6 @@
pub trait WeightInfo {
fn create_item() -> Weight;
fn create_multiple_items(b: u32, ) -> Weight;
- fn burn_from() -> Weight;
fn burn_item_partial() -> Weight;
fn burn_item_fully() -> Weight;
fn transfer_normal() -> Weight;
@@ -45,6 +45,7 @@
fn transfer_from_creating() -> Weight;
fn transfer_from_removing() -> Weight;
fn transfer_from_creating_removing() -> Weight;
+ fn burn_from() -> Weight;
fn set_variable_metadata(b: u32, ) -> Weight;
}
primitives/nft/src/lib.rsdiffbeforeafterboth--- a/primitives/nft/src/lib.rs
+++ b/primitives/nft/src/lib.rs
@@ -327,8 +327,7 @@
D: ser::Serializer,
V: Serialize,
{
- let vec: &Vec<_> = &value;
- vec.serialize(serializer)
+ (value as &Vec<_>).serialize(serializer)
}
pub fn deserialize<'de, D, V, S>(deserializer: D) -> Result<BoundedVec<V, S>, D::Error>
runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -1177,6 +1177,7 @@
EVM::account_storages(address, H256::from_slice(&tmp[..]))
}
+ #[allow(clippy::redundant_closure)]
fn call(
from: H160,
to: H160,
@@ -1207,6 +1208,7 @@
).map_err(|err| err.into())
}
+ #[allow(clippy::redundant_closure)]
fn create(
from: H160,
data: Vec<u8>,