Minor tweaks suggested by clippy (#10673)

* Minor tweaks suggested by clippy

* Fix typo caused by last commit

* Apply review suggestions
This commit is contained in:
Nazar Mokrynskyi
2022-01-15 22:00:12 +02:00
committed by GitHub
parent a534274c6f
commit 0bca06a483
5 changed files with 27 additions and 35 deletions
+13 -18
View File
@@ -132,8 +132,7 @@ impl Transfer {
pub fn into_signed_tx(self) -> Extrinsic {
let signature = sp_keyring::AccountKeyring::from_public(&self.from)
.expect("Creates keyring from public key.")
.sign(&self.encode())
.into();
.sign(&self.encode());
Extrinsic::Transfer { transfer: self, signature, exhaust_resources_when_not_first: false }
}
@@ -144,8 +143,7 @@ impl Transfer {
pub fn into_resources_exhausting_tx(self) -> Extrinsic {
let signature = sp_keyring::AccountKeyring::from_public(&self.from)
.expect("Creates keyring from public key.")
.sign(&self.encode())
.into();
.sign(&self.encode());
Extrinsic::Transfer { transfer: self, signature, exhaust_resources_when_not_first: true }
}
}
@@ -277,9 +275,9 @@ pub fn run_tests(mut input: &[u8]) -> Vec<u8> {
print("run_tests...");
let block = Block::decode(&mut input).unwrap();
print("deserialized block.");
let stxs = block.extrinsics.iter().map(Encode::encode).collect::<Vec<_>>();
let stxs = block.extrinsics.iter().map(Encode::encode);
print("reserialized transactions.");
[stxs.len() as u8].encode()
[stxs.count() as u8].encode()
}
/// A type that can not be decoded.
@@ -296,9 +294,9 @@ impl<B: BlockT> Encode for DecodeFails<B> {
impl<B: BlockT> codec::EncodeLike for DecodeFails<B> {}
impl<B: BlockT> DecodeFails<B> {
/// Create a new instance.
pub fn new() -> DecodeFails<B> {
impl<B: BlockT> Default for DecodeFails<B> {
/// Create a default instance.
fn default() -> DecodeFails<B> {
DecodeFails { _phantom: Default::default() }
}
}
@@ -436,8 +434,8 @@ impl From<frame_system::Origin<Runtime>> for Origin {
unimplemented!("Not required in tests!")
}
}
impl Into<Result<frame_system::Origin<Runtime>, Origin>> for Origin {
fn into(self) -> Result<frame_system::Origin<Runtime>, Origin> {
impl From<Origin> for Result<frame_system::Origin<Runtime>, Origin> {
fn from(_origin: Origin) -> Result<frame_system::Origin<Runtime>, Origin> {
unimplemented!("Not required in tests!")
}
}
@@ -651,12 +649,9 @@ fn code_using_trie() -> u64 {
let mut mdb = PrefixedMemoryDB::default();
let mut root = sp_std::default::Default::default();
let _ = {
let v = &pairs;
let mut t = TrieDBMut::<Hashing>::new(&mut mdb, &mut root);
for i in 0..v.len() {
let key: &[u8] = &v[i].0;
let val: &[u8] = &v[i].1;
if !t.insert(key, val).is_ok() {
for (key, value) in &pairs {
if t.insert(key, value).is_err() {
return 101
}
}
@@ -761,7 +756,7 @@ cfg_if! {
fn fail_convert_parameter(_: DecodeFails<Block>) {}
fn fail_convert_return_value() -> DecodeFails<Block> {
DecodeFails::new()
DecodeFails::default()
}
fn function_signature_changed() -> u64 {
@@ -1015,7 +1010,7 @@ cfg_if! {
fn fail_convert_parameter(_: DecodeFails<Block>) {}
fn fail_convert_return_value() -> DecodeFails<Block> {
DecodeFails::new()
DecodeFails::default()
}
fn function_signature_changed() -> Vec<u64> {
+5 -5
View File
@@ -197,7 +197,7 @@ pub fn finalize_block() -> Header {
use sp_core::storage::StateVersion;
let extrinsic_index: u32 = storage::unhashed::take(well_known_keys::EXTRINSIC_INDEX).unwrap();
let txs: Vec<_> = (0..extrinsic_index).map(ExtrinsicData::take).collect();
let extrinsics_root = trie::blake2_256_ordered_root(txs, StateVersion::V0).into();
let extrinsics_root = trie::blake2_256_ordered_root(txs, StateVersion::V0);
let number = <Number>::take().expect("Number is set by `initialize_block`");
let parent_hash = <ParentHash>::take();
let mut digest = <StorageDigest>::take().expect("StorageDigest is set by `initialize_block`");
@@ -235,11 +235,11 @@ fn execute_transaction_backend(utx: &Extrinsic, extrinsic_index: u32) -> ApplyEx
Extrinsic::StorageChange(key, value) =>
execute_storage_change(key, value.as_ref().map(|v| &**v)),
Extrinsic::OffchainIndexSet(key, value) => {
sp_io::offchain_index::set(&key, &value);
sp_io::offchain_index::set(key, value);
Ok(Ok(()))
},
Extrinsic::OffchainIndexClear(key) => {
sp_io::offchain_index::clear(&key);
sp_io::offchain_index::clear(key);
Ok(Ok(()))
},
Extrinsic::Store(data) => execute_store(data.clone()),
@@ -250,7 +250,7 @@ fn execute_transfer_backend(tx: &Transfer) -> ApplyExtrinsicResult {
// check nonce
let nonce_key = tx.from.to_keyed_vec(NONCE_OF);
let expected_nonce: u64 = storage::hashed::get_or(&blake2_256, &nonce_key, 0);
if !(tx.nonce == expected_nonce) {
if tx.nonce != expected_nonce {
return Err(InvalidTransaction::Stale.into())
}
@@ -262,7 +262,7 @@ fn execute_transfer_backend(tx: &Transfer) -> ApplyExtrinsicResult {
let from_balance: u64 = storage::hashed::get_or(&blake2_256, &from_balance_key, 0);
// enact transfer
if !(tx.amount <= from_balance) {
if tx.amount > from_balance {
return Err(InvalidTransaction::Payment.into())
}
let to_balance_key = tx.to.to_keyed_vec(BALANCE_OF);