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;16use pallet_common::erc::PrecompileOutput;1718use crate::{19 AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,20 SelfWeightOf, weights::WeightInfo,21};2223#[derive(ToLog)]24pub enum ERC721Events {25 Transfer {26 #[indexed]27 from: address,28 #[indexed]29 to: address,30 #[indexed]31 token_id: uint256,32 },33 Approval {34 #[indexed]35 owner: address,36 #[indexed]37 approved: address,38 #[indexed]39 token_id: uint256,40 },41 #[allow(dead_code)]42 ApprovalForAll {43 #[indexed]44 owner: address,45 #[indexed]46 operator: address,47 approved: bool,48 },49}5051#[derive(ToLog)]52pub enum ERC721MintableEvents {53 #[allow(dead_code)]54 MintingFinished {},55}5657#[solidity_interface(name = "ERC721Metadata")]58impl<T: Config> NonfungibleHandle<T> {59 fn name(&self) -> Result<string> {60 Ok(decode_utf16(self.name.iter().copied())61 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))62 .collect::<string>())63 }64 fn symbol(&self) -> Result<string> {65 Ok(string::from_utf8_lossy(&self.token_prefix).into())66 }6768 /// Returns token's const_metadata69 #[solidity(rename_selector = "tokenURI")]70 fn token_uri(&self, token_id: uint256) -> Result<string> {71 self.consume_store_reads(1)?;72 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;73 Ok(string::from_utf8_lossy(74 &<TokenData<T>>::get((self.id, token_id))75 .ok_or("token not found")?76 .const_data,77 )78 .into())79 }80}8182#[solidity_interface(name = "ERC721Enumerable")]83impl<T: Config> NonfungibleHandle<T> {84 fn token_by_index(&self, index: uint256) -> Result<uint256> {85 Ok(index)86 }8788 /// Not implemented89 fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {90 // TODO: Not implemetable91 Err("not implemented".into())92 }9394 fn total_supply(&self) -> Result<uint256> {95 self.consume_store_reads(1)?;96 Ok(<Pallet<T>>::total_supply(self).into())97 }98}99100#[solidity_interface(name = "ERC721", events(ERC721Events))]101impl<T: Config> NonfungibleHandle<T> {102 fn balance_of(&self, owner: address) -> Result<uint256> {103 self.consume_store_reads(1)?;104 let owner = T::CrossAccountId::from_eth(owner);105 let balance = <AccountBalance<T>>::get((self.id, owner));106 Ok(balance.into())107 }108 fn owner_of(&self, token_id: uint256) -> Result<address> {109 self.consume_store_reads(1)?;110 let token: TokenId = token_id.try_into()?;111 Ok(*<TokenData<T>>::get((self.id, token))112 .ok_or("token not found")?113 .owner114 .as_eth())115 }116 /// Not implemented117 fn safe_transfer_from_with_data(118 &mut self,119 _from: address,120 _to: address,121 _token_id: uint256,122 _data: bytes,123 _value: value,124 ) -> Result<void> {125 // TODO: Not implemetable126 Err("not implemented".into())127 }128 /// Not implemented129 fn safe_transfer_from(130 &mut self,131 _from: address,132 _to: address,133 _token_id: uint256,134 _value: value,135 ) -> Result<void> {136 // TODO: Not implemetable137 Err("not implemented".into())138 }139140 #[weight(<SelfWeightOf<T>>::transfer_from())]141 fn transfer_from(142 &mut self,143 caller: caller,144 from: address,145 to: address,146 token_id: uint256,147 _value: value,148 ) -> Result<void> {149 let caller = T::CrossAccountId::from_eth(caller);150 let from = T::CrossAccountId::from_eth(from);151 let to = T::CrossAccountId::from_eth(to);152 let token = token_id.try_into()?;153154 <Pallet<T>>::transfer_from(self, &caller, &from, &to, token)155 .map_err(dispatch_to_evm::<T>)?;156 Ok(())157 }158159 #[weight(<SelfWeightOf<T>>::approve())]160 fn approve(161 &mut self,162 caller: caller,163 approved: address,164 token_id: uint256,165 _value: value,166 ) -> Result<void> {167 let caller = T::CrossAccountId::from_eth(caller);168 let approved = T::CrossAccountId::from_eth(approved);169 let token = token_id.try_into()?;170171 <Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))172 .map_err(dispatch_to_evm::<T>)?;173 Ok(())174 }175176 /// Not implemented177 fn set_approval_for_all(178 &mut self,179 _caller: caller,180 _operator: address,181 _approved: bool,182 ) -> Result<void> {183 // TODO: Not implemetable184 Err("not implemented".into())185 }186187 /// Not implemented188 fn get_approved(&self, _token_id: uint256) -> Result<address> {189 // TODO: Not implemetable190 Err("not implemented".into())191 }192193 /// Not implemented194 fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {195 // TODO: Not implemetable196 Err("not implemented".into())197 }198}199200#[solidity_interface(name = "ERC721Burnable")]201impl<T: Config> NonfungibleHandle<T> {202 #[weight(<SelfWeightOf<T>>::burn_item())]203 fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {204 let caller = T::CrossAccountId::from_eth(caller);205 let token = token_id.try_into()?;206207 <Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;208 Ok(())209 }210}211212#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]213impl<T: Config> NonfungibleHandle<T> {214 fn minting_finished(&self) -> Result<bool> {215 Ok(false)216 }217218 /// `token_id` should be obtained with `next_token_id` method,219 /// unlike standard, you can't specify it manually220 #[weight(<SelfWeightOf<T>>::create_item())]221 fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {222 let caller = T::CrossAccountId::from_eth(caller);223 let to = T::CrossAccountId::from_eth(to);224 let token_id: u32 = token_id.try_into()?;225 if <TokensMinted<T>>::get(self.id)226 .checked_add(1)227 .ok_or("item id overflow")?228 != token_id229 {230 return Err("item id should be next".into());231 }232233 <Pallet<T>>::create_item(234 self,235 &caller,236 CreateItemData {237 const_data: BoundedVec::default(),238 variable_data: BoundedVec::default(),239 owner: to,240 },241 )242 .map_err(dispatch_to_evm::<T>)?;243244 Ok(true)245 }246247 /// `token_id` should be obtained with `next_token_id` method,248 /// unlike standard, you can't specify it manually249 #[solidity(rename_selector = "mintWithTokenURI")]250 #[weight(<SelfWeightOf<T>>::create_item())]251 fn mint_with_token_uri(252 &mut self,253 caller: caller,254 to: address,255 token_id: uint256,256 token_uri: string,257 ) -> Result<bool> {258 let caller = T::CrossAccountId::from_eth(caller);259 let to = T::CrossAccountId::from_eth(to);260 let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;261 if <TokensMinted<T>>::get(self.id)262 .checked_add(1)263 .ok_or("item id overflow")?264 != token_id265 {266 return Err("item id should be next".into());267 }268269 <Pallet<T>>::create_item(270 self,271 &caller,272 CreateItemData {273 const_data: Vec::<u8>::from(token_uri)274 .try_into()275 .map_err(|_| "token uri is too long")?,276 variable_data: BoundedVec::default(),277 owner: to,278 },279 )280 .map_err(dispatch_to_evm::<T>)?;281 Ok(true)282 }283284 /// Not implemented285 fn finish_minting(&mut self, _caller: caller) -> Result<bool> {286 Err("not implementable".into())287 }288}289290#[solidity_interface(name = "ERC721UniqueExtensions")]291impl<T: Config> NonfungibleHandle<T> {292 #[weight(<SelfWeightOf<T>>::transfer())]293 fn transfer(294 &mut self,295 caller: caller,296 to: address,297 token_id: uint256,298 _value: value,299 ) -> Result<void> {300 let caller = T::CrossAccountId::from_eth(caller);301 let to = T::CrossAccountId::from_eth(to);302 let token = token_id.try_into()?;303304 <Pallet<T>>::transfer(self, &caller, &to, token).map_err(dispatch_to_evm::<T>)?;305 Ok(())306 }307308 #[weight(<SelfWeightOf<T>>::burn_from())]309 fn burn_from(310 &mut self,311 caller: caller,312 from: address,313 token_id: uint256,314 _value: value,315 ) -> Result<void> {316 let caller = T::CrossAccountId::from_eth(caller);317 let from = T::CrossAccountId::from_eth(from);318 let token = token_id.try_into()?;319320 <Pallet<T>>::burn_from(self, &caller, &from, token).map_err(dispatch_to_evm::<T>)?;321 Ok(())322 }323324 fn next_token_id(&self) -> Result<uint256> {325 self.consume_store_reads(1)?;326 Ok(<TokensMinted<T>>::get(self.id)327 .checked_add(1)328 .ok_or("item id overflow")?329 .into())330 }331332 #[weight(<SelfWeightOf<T>>::set_variable_metadata(data.len() as u32))]333 fn set_variable_metadata(334 &mut self,335 caller: caller,336 token_id: uint256,337 data: bytes,338 ) -> Result<void> {339 let caller = T::CrossAccountId::from_eth(caller);340 let token = token_id.try_into()?;341342 <Pallet<T>>::set_variable_metadata(self, &caller, token, data)343 .map_err(dispatch_to_evm::<T>)?;344 Ok(())345 }346347 fn get_variable_metadata(&self, token_id: uint256) -> Result<bytes> {348 self.consume_store_reads(1)?;349 let token: TokenId = token_id.try_into()?;350351 Ok(<TokenData<T>>::get((self.id, token))352 .ok_or("token not found")?353 .variable_data)354 }355356 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]357 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {358 let caller = T::CrossAccountId::from_eth(caller);359 let to = T::CrossAccountId::from_eth(to);360 let mut expected_index = <TokensMinted<T>>::get(self.id)361 .checked_add(1)362 .ok_or("item id overflow")?;363364 let total_tokens = token_ids.len();365 for id in token_ids.into_iter() {366 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;367 if id != expected_index {368 return Err("item id should be next".into());369 }370 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;371 }372 let data = (0..total_tokens)373 .map(|_| CreateItemData {374 const_data: BoundedVec::default(),375 variable_data: BoundedVec::default(),376 owner: to.clone(),377 })378 .collect();379380 <Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;381 Ok(true)382 }383384 #[solidity(rename_selector = "mintBulkWithTokenURI")]385 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]386 fn mint_bulk_with_token_uri(387 &mut self,388 caller: caller,389 to: address,390 tokens: Vec<(uint256, string)>,391 ) -> Result<bool> {392 let caller = T::CrossAccountId::from_eth(caller);393 let to = T::CrossAccountId::from_eth(to);394 let mut expected_index = <TokensMinted<T>>::get(self.id)395 .checked_add(1)396 .ok_or("item id overflow")?;397398 let mut data = Vec::with_capacity(tokens.len());399 for (id, token_uri) in tokens {400 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;401 if id != expected_index {402 panic!("item id should be next ({}) but got {}", expected_index, id);403 }404 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;405406 data.push(CreateItemData {407 const_data: Vec::<u8>::from(token_uri)408 .try_into()409 .map_err(|_| "token uri is too long")?,410 variable_data: vec![].try_into().unwrap(),411 owner: to.clone(),412 });413 }414415 <Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;416 Ok(true)417 }418}419420#[solidity_interface(421 name = "UniqueNFT",422 is(423 ERC721,424 ERC721Metadata,425 ERC721Enumerable,426 ERC721UniqueExtensions,427 ERC721Mintable,428 ERC721Burnable,429 )430)]431impl<T: Config> NonfungibleHandle<T> {}432433// Not a tests, but code generators434generate_stubgen!(gen_impl, UniqueNFTCall<()>, true);435generate_stubgen!(gen_iface, UniqueNFTCall<()>, false);436437impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {438 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");439440 fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult> {441 call::<T, UniqueNFTCall<T>, _>(*source, self, value, input)442 }443}1use 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>,