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.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -303,8 +303,8 @@
amount: u128,
) -> DispatchResult {
if collection.access == AccessMode::AllowList {
- collection.check_allowlist(&owner)?;
- collection.check_allowlist(&spender)?;
+ collection.check_allowlist(owner)?;
+ collection.check_allowlist(spender)?;
}
if <Balance<T>>::get((collection.id, owner)) < amount {
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.rsdiffbeforeafterboth1use core::{2 char::{REPLACEMENT_CHARACTER, decode_utf16},3 convert::TryInto,4};5use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};6use frame_support::BoundedVec;7use nft_data_structs::TokenId;8use pallet_evm_coder_substrate::dispatch_to_evm;9use sp_core::{H160, U256};10use sp_std::{vec::Vec, vec};11use pallet_common::{12 account::CrossAccountId,13 erc::{CommonEvmHandler, PrecompileResult},14};15use pallet_evm_coder_substrate::call;1617use crate::{18 AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,19 SelfWeightOf, weights::WeightInfo,20};2122#[derive(ToLog)]23pub enum ERC721Events {24 Transfer {25 #[indexed]26 from: address,27 #[indexed]28 to: address,29 #[indexed]30 token_id: uint256,31 },32 Approval {33 #[indexed]34 owner: address,35 #[indexed]36 approved: address,37 #[indexed]38 token_id: uint256,39 },40 #[allow(dead_code)]41 ApprovalForAll {42 #[indexed]43 owner: address,44 #[indexed]45 operator: address,46 approved: bool,47 },48}4950#[derive(ToLog)]51pub enum ERC721MintableEvents {52 #[allow(dead_code)]53 MintingFinished {},54}5556#[solidity_interface(name = "ERC721Metadata")]57impl<T: Config> NonfungibleHandle<T> {58 fn name(&self) -> Result<string> {59 Ok(decode_utf16(self.name.iter().copied())60 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))61 .collect::<string>())62 }63 fn symbol(&self) -> Result<string> {64 Ok(string::from_utf8_lossy(&self.token_prefix).into())65 }6667 /// Returns token's const_metadata68 #[solidity(rename_selector = "tokenURI")]69 fn token_uri(&self, token_id: uint256) -> Result<string> {70 self.consume_store_reads(1)?;71 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;72 Ok(string::from_utf8_lossy(73 &<TokenData<T>>::get((self.id, token_id))74 .ok_or("token not found")?75 .const_data,76 )77 .into())78 }79}8081#[solidity_interface(name = "ERC721Enumerable")]82impl<T: Config> NonfungibleHandle<T> {83 fn token_by_index(&self, index: uint256) -> Result<uint256> {84 Ok(index)85 }8687 /// Not implemented88 fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {89 // TODO: Not implemetable90 Err("not implemented".into())91 }9293 fn total_supply(&self) -> Result<uint256> {94 self.consume_store_reads(1)?;95 Ok(<Pallet<T>>::total_supply(self).into())96 }97}9899#[solidity_interface(name = "ERC721", events(ERC721Events))]100impl<T: Config> NonfungibleHandle<T> {101 fn balance_of(&self, owner: address) -> Result<uint256> {102 self.consume_store_reads(1)?;103 let owner = T::CrossAccountId::from_eth(owner);104 let balance = <AccountBalance<T>>::get((self.id, owner));105 Ok(balance.into())106 }107 fn owner_of(&self, token_id: uint256) -> Result<address> {108 self.consume_store_reads(1)?;109 let token: TokenId = token_id.try_into()?;110 Ok(*<TokenData<T>>::get((self.id, token))111 .ok_or("token not found")?112 .owner113 .as_eth())114 }115 /// Not implemented116 fn safe_transfer_from_with_data(117 &mut self,118 _from: address,119 _to: address,120 _token_id: uint256,121 _data: bytes,122 _value: value,123 ) -> Result<void> {124 // TODO: Not implemetable125 Err("not implemented".into())126 }127 /// Not implemented128 fn safe_transfer_from(129 &mut self,130 _from: address,131 _to: address,132 _token_id: uint256,133 _value: value,134 ) -> Result<void> {135 // TODO: Not implemetable136 Err("not implemented".into())137 }138139 #[weight(<SelfWeightOf<T>>::transfer_from())]140 fn transfer_from(141 &mut self,142 caller: caller,143 from: address,144 to: address,145 token_id: uint256,146 _value: value,147 ) -> Result<void> {148 let caller = T::CrossAccountId::from_eth(caller);149 let from = T::CrossAccountId::from_eth(from);150 let to = T::CrossAccountId::from_eth(to);151 let token = token_id.try_into()?;152153 <Pallet<T>>::transfer_from(self, &caller, &from, &to, token)154 .map_err(dispatch_to_evm::<T>)?;155 Ok(())156 }157158 #[weight(<SelfWeightOf<T>>::approve())]159 fn approve(160 &mut self,161 caller: caller,162 approved: address,163 token_id: uint256,164 _value: value,165 ) -> Result<void> {166 let caller = T::CrossAccountId::from_eth(caller);167 let approved = T::CrossAccountId::from_eth(approved);168 let token = token_id.try_into()?;169170 <Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))171 .map_err(dispatch_to_evm::<T>)?;172 Ok(())173 }174175 /// Not implemented176 fn set_approval_for_all(177 &mut self,178 _caller: caller,179 _operator: address,180 _approved: bool,181 ) -> Result<void> {182 // TODO: Not implemetable183 Err("not implemented".into())184 }185186 /// Not implemented187 fn get_approved(&self, _token_id: uint256) -> Result<address> {188 // TODO: Not implemetable189 Err("not implemented".into())190 }191192 /// Not implemented193 fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {194 // TODO: Not implemetable195 Err("not implemented".into())196 }197}198199#[solidity_interface(name = "ERC721Burnable")]200impl<T: Config> NonfungibleHandle<T> {201 #[weight(<SelfWeightOf<T>>::burn_item())]202 fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {203 let caller = T::CrossAccountId::from_eth(caller);204 let token = token_id.try_into()?;205206 <Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;207 Ok(())208 }209}210211#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]212impl<T: Config> NonfungibleHandle<T> {213 fn minting_finished(&self) -> Result<bool> {214 Ok(false)215 }216217 /// `token_id` should be obtained with `next_token_id` method,218 /// unlike standard, you can't specify it manually219 #[weight(<SelfWeightOf<T>>::create_item())]220 fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {221 let caller = T::CrossAccountId::from_eth(caller);222 let to = T::CrossAccountId::from_eth(to);223 let token_id: u32 = token_id.try_into()?;224 if <TokensMinted<T>>::get(self.id)225 .checked_add(1)226 .ok_or("item id overflow")?227 != token_id228 {229 return Err("item id should be next".into());230 }231232 <Pallet<T>>::create_item(233 self,234 &caller,235 CreateItemData {236 const_data: BoundedVec::default(),237 variable_data: BoundedVec::default(),238 owner: to,239 },240 )241 .map_err(dispatch_to_evm::<T>)?;242243 Ok(true)244 }245246 /// `token_id` should be obtained with `next_token_id` method,247 /// unlike standard, you can't specify it manually248 #[solidity(rename_selector = "mintWithTokenURI")]249 #[weight(<SelfWeightOf<T>>::create_item())]250 fn mint_with_token_uri(251 &mut self,252 caller: caller,253 to: address,254 token_id: uint256,255 token_uri: string,256 ) -> Result<bool> {257 let caller = T::CrossAccountId::from_eth(caller);258 let to = T::CrossAccountId::from_eth(to);259 let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;260 if <TokensMinted<T>>::get(self.id)261 .checked_add(1)262 .ok_or("item id overflow")?263 != token_id264 {265 return Err("item id should be next".into());266 }267268 <Pallet<T>>::create_item(269 self,270 &caller,271 CreateItemData {272 const_data: Vec::<u8>::from(token_uri)273 .try_into()274 .map_err(|_| "token uri is too long")?,275 variable_data: BoundedVec::default(),276 owner: to,277 },278 )279 .map_err(dispatch_to_evm::<T>)?;280 Ok(true)281 }282283 /// Not implemented284 fn finish_minting(&mut self, _caller: caller) -> Result<bool> {285 Err("not implementable".into())286 }287}288289#[solidity_interface(name = "ERC721UniqueExtensions")]290impl<T: Config> NonfungibleHandle<T> {291 #[weight(<SelfWeightOf<T>>::transfer())]292 fn transfer(293 &mut self,294 caller: caller,295 to: address,296 token_id: uint256,297 _value: value,298 ) -> Result<void> {299 let caller = T::CrossAccountId::from_eth(caller);300 let to = T::CrossAccountId::from_eth(to);301 let token = token_id.try_into()?;302303 <Pallet<T>>::transfer(self, &caller, &to, token).map_err(dispatch_to_evm::<T>)?;304 Ok(())305 }306307 #[weight(<SelfWeightOf<T>>::burn_from())]308 fn burn_from(309 &mut self,310 caller: caller,311 from: address,312 token_id: uint256,313 _value: value,314 ) -> Result<void> {315 let caller = T::CrossAccountId::from_eth(caller);316 let from = T::CrossAccountId::from_eth(from);317 let token = token_id.try_into()?;318319 <Pallet<T>>::burn_from(self, &caller, &from, token).map_err(dispatch_to_evm::<T>)?;320 Ok(())321 }322323 fn next_token_id(&self) -> Result<uint256> {324 self.consume_store_reads(1)?;325 Ok(<TokensMinted<T>>::get(self.id)326 .checked_add(1)327 .ok_or("item id overflow")?328 .into())329 }330331 #[weight(<SelfWeightOf<T>>::set_variable_metadata(data.len() as u32))]332 fn set_variable_metadata(333 &mut self,334 caller: caller,335 token_id: uint256,336 data: bytes,337 ) -> Result<void> {338 let caller = T::CrossAccountId::from_eth(caller);339 let token = token_id.try_into()?;340341 <Pallet<T>>::set_variable_metadata(self, &caller, token, data)342 .map_err(dispatch_to_evm::<T>)?;343 Ok(())344 }345346 fn get_variable_metadata(&self, token_id: uint256) -> Result<bytes> {347 self.consume_store_reads(1)?;348 let token: TokenId = token_id.try_into()?;349350 Ok(<TokenData<T>>::get((self.id, token))351 .ok_or("token not found")?352 .variable_data)353 }354355 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]356 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {357 let caller = T::CrossAccountId::from_eth(caller);358 let to = T::CrossAccountId::from_eth(to);359 let mut expected_index = <TokensMinted<T>>::get(self.id)360 .checked_add(1)361 .ok_or("item id overflow")?;362363 let total_tokens = token_ids.len();364 for id in token_ids.into_iter() {365 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;366 if id != expected_index {367 return Err("item id should be next".into());368 }369 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;370 }371 let data = (0..total_tokens)372 .map(|_| CreateItemData {373 const_data: BoundedVec::default(),374 variable_data: BoundedVec::default(),375 owner: to.clone(),376 })377 .collect();378379 <Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;380 Ok(true)381 }382383 #[solidity(rename_selector = "mintBulkWithTokenURI")]384 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]385 fn mint_bulk_with_token_uri(386 &mut self,387 caller: caller,388 to: address,389 tokens: Vec<(uint256, string)>,390 ) -> Result<bool> {391 let caller = T::CrossAccountId::from_eth(caller);392 let to = T::CrossAccountId::from_eth(to);393 let mut expected_index = <TokensMinted<T>>::get(self.id)394 .checked_add(1)395 .ok_or("item id overflow")?;396397 let mut data = Vec::with_capacity(tokens.len());398 for (id, token_uri) in tokens {399 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;400 if id != expected_index {401 panic!("item id should be next ({}) but got {}", expected_index, id);402 }403 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;404405 data.push(CreateItemData {406 const_data: Vec::<u8>::from(token_uri)407 .try_into()408 .map_err(|_| "token uri is too long")?,409 variable_data: vec![].try_into().unwrap(),410 owner: to.clone(),411 });412 }413414 <Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;415 Ok(true)416 }417}418419#[solidity_interface(420 name = "UniqueNFT",421 is(422 ERC721,423 ERC721Metadata,424 ERC721Enumerable,425 ERC721UniqueExtensions,426 ERC721Mintable,427 ERC721Burnable,428 )429)]430impl<T: Config> NonfungibleHandle<T> {}431432// Not a tests, but code generators433generate_stubgen!(gen_impl, UniqueNFTCall<()>, true);434generate_stubgen!(gen_iface, UniqueNFTCall<()>, false);435436impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {437 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");438439 fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult> {440 call::<T, UniqueNFTCall<T>, _>(*source, self, value, input)441 }442}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>,