mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 22:11:06 +00:00
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:
@@ -378,6 +378,7 @@ fn generate_call_api_at_calls(decl: &ItemTrait) -> Result<TokenStream> {
|
||||
// Generate the generator function
|
||||
result.push(quote!(
|
||||
#[cfg(any(feature = "std", test))]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn #fn_name<
|
||||
R: #crate_::Encode + #crate_::Decode + PartialEq,
|
||||
NC: FnOnce() -> std::result::Result<R, #crate_::ApiError> + std::panic::UnwindSafe,
|
||||
|
||||
@@ -59,7 +59,7 @@ fn calling_native_runtime_function_with_non_decodable_parameter() {
|
||||
.build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.chain_info().best_number);
|
||||
runtime_api.fail_convert_parameter(&block_id, DecodeFails::new()).unwrap();
|
||||
runtime_api.fail_convert_parameter(&block_id, DecodeFails::default()).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -179,13 +179,13 @@ impl TestApi {
|
||||
/// Add a block to the internal state.
|
||||
pub fn add_block(&self, block: Block, is_best_block: bool) {
|
||||
let hash = block.header.hash();
|
||||
let block_number = block.header.number().clone();
|
||||
let block_number = block.header.number();
|
||||
|
||||
let mut chain = self.chain.write();
|
||||
chain.block_by_hash.insert(hash, block.clone());
|
||||
chain
|
||||
.block_by_number
|
||||
.entry(block_number)
|
||||
.entry(*block_number)
|
||||
.or_default()
|
||||
.push((block, is_best_block.into()));
|
||||
}
|
||||
@@ -259,15 +259,13 @@ impl sc_transaction_pool::ChainApi for TestApi {
|
||||
if !found_best {
|
||||
return ready(Ok(Err(TransactionValidityError::Invalid(
|
||||
InvalidTransaction::Custom(1),
|
||||
)
|
||||
.into())))
|
||||
))))
|
||||
}
|
||||
},
|
||||
Ok(None) =>
|
||||
return ready(Ok(Err(TransactionValidityError::Invalid(
|
||||
InvalidTransaction::Custom(2),
|
||||
)
|
||||
.into()))),
|
||||
)))),
|
||||
Err(e) => return ready(Err(e)),
|
||||
}
|
||||
|
||||
@@ -283,9 +281,7 @@ impl sc_transaction_pool::ChainApi for TestApi {
|
||||
};
|
||||
|
||||
if self.chain.read().invalid_hashes.contains(&self.hash_and_length(&uxt).0) {
|
||||
return ready(Ok(Err(
|
||||
TransactionValidityError::Invalid(InvalidTransaction::Custom(0)).into()
|
||||
)))
|
||||
return ready(Ok(Err(TransactionValidityError::Invalid(InvalidTransaction::Custom(0)))))
|
||||
}
|
||||
|
||||
let mut validity =
|
||||
@@ -312,7 +308,7 @@ impl sc_transaction_pool::ChainApi for TestApi {
|
||||
at: &BlockId<Self::Block>,
|
||||
) -> Result<Option<<Self::Block as BlockT>::Hash>, Error> {
|
||||
Ok(match at {
|
||||
generic::BlockId::Hash(x) => Some(x.clone()),
|
||||
generic::BlockId::Hash(x) => Some(*x),
|
||||
generic::BlockId::Number(num) =>
|
||||
self.chain.read().block_by_number.get(num).and_then(|blocks| {
|
||||
blocks.iter().find(|b| b.1.is_best()).map(|b| b.0.header().hash())
|
||||
@@ -371,6 +367,6 @@ impl sp_blockchain::HeaderMetadata<Block> for TestApi {
|
||||
pub fn uxt(who: AccountKeyring, nonce: Index) -> Extrinsic {
|
||||
let dummy = codec::Decode::decode(&mut TrailingZeroInput::zeroes()).unwrap();
|
||||
let transfer = Transfer { from: who.into(), to: dummy, nonce, amount: 1 };
|
||||
let signature = transfer.using_encoded(|e| who.sign(e)).into();
|
||||
let signature = transfer.using_encoded(|e| who.sign(e));
|
||||
Extrinsic::Transfer { transfer, signature, exhaust_resources_when_not_first: false }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user