chore(clippy): Cleanup nightly clippy warnings from 2023-10-30 (#7868)

* Use first() rather than get(0)

* Remove unused imports and silence test-related warnings

* More clippy fixes
This commit is contained in:
teor 2023-10-30 22:21:05 +10:00 committed by GitHub
parent 49a9e598bf
commit df55201c87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 20 deletions

View File

@ -4,6 +4,6 @@ mod sinsemilla;
mod tree; mod tree;
pub use group_hash::GROUP_HASHES; pub use group_hash::GROUP_HASHES;
pub use key_components::KEY_COMPONENTS;
pub use sinsemilla::SINSEMILLA; pub use sinsemilla::SINSEMILLA;
pub use tree::{COMMITMENTS, EMPTY_ROOTS, ROOTS}; pub use tree::{COMMITMENTS, EMPTY_ROOTS, ROOTS};

View File

@ -33,7 +33,7 @@ pub fn coinbase_is_first(block: &Block) -> Result<Arc<transaction::Transaction>,
// <https://zips.z.cash/protocol/protocol.pdf#blockheader> // <https://zips.z.cash/protocol/protocol.pdf#blockheader>
let first = block let first = block
.transactions .transactions
.get(0) .first()
.ok_or(BlockError::NoTransactions)?; .ok_or(BlockError::NoTransactions)?;
// > The first transaction in a block MUST be a coinbase transaction, // > The first transaction in a block MUST be a coinbase transaction,
// > and subsequent transactions MUST NOT be coinbase transactions. // > and subsequent transactions MUST NOT be coinbase transactions.
@ -142,7 +142,7 @@ pub fn equihash_solution_is_valid(header: &Header) -> Result<(), equihash::Error
/// [3.9]: https://zips.z.cash/protocol/protocol.pdf#subsidyconcepts /// [3.9]: https://zips.z.cash/protocol/protocol.pdf#subsidyconcepts
pub fn subsidy_is_valid(block: &Block, network: Network) -> Result<(), BlockError> { pub fn subsidy_is_valid(block: &Block, network: Network) -> Result<(), BlockError> {
let height = block.coinbase_height().ok_or(SubsidyError::NoCoinbase)?; let height = block.coinbase_height().ok_or(SubsidyError::NoCoinbase)?;
let coinbase = block.transactions.get(0).ok_or(SubsidyError::NoCoinbase)?; let coinbase = block.transactions.first().ok_or(SubsidyError::NoCoinbase)?;
// Validate funding streams // Validate funding streams
let Some(halving_div) = subsidy::general::halving_divisor(height, network) else { let Some(halving_div) = subsidy::general::halving_divisor(height, network) else {
@ -211,7 +211,7 @@ pub fn miner_fees_are_valid(
block_miner_fees: Amount<NonNegative>, block_miner_fees: Amount<NonNegative>,
) -> Result<(), BlockError> { ) -> Result<(), BlockError> {
let height = block.coinbase_height().ok_or(SubsidyError::NoCoinbase)?; let height = block.coinbase_height().ok_or(SubsidyError::NoCoinbase)?;
let coinbase = block.transactions.get(0).ok_or(SubsidyError::NoCoinbase)?; let coinbase = block.transactions.first().ok_or(SubsidyError::NoCoinbase)?;
let transparent_value_balance: Amount = subsidy::general::output_amounts(coinbase) let transparent_value_balance: Amount = subsidy::general::output_amounts(coinbase)
.iter() .iter()

View File

@ -103,7 +103,7 @@ static INVALID_COINBASE_TRANSCRIPT: Lazy<
assert_eq!(block3.transactions.len(), 1); assert_eq!(block3.transactions.len(), 1);
// Extract the coinbase transaction from the block // Extract the coinbase transaction from the block
let coinbase_transaction = block3.transactions.get(0).unwrap().clone(); let coinbase_transaction = block3.transactions.first().unwrap().clone();
// Add another coinbase transaction to block // Add another coinbase transaction to block
block3.transactions.push(coinbase_transaction); block3.transactions.push(coinbase_transaction);
@ -373,7 +373,7 @@ fn coinbase_validation_failure() -> Result<(), Report> {
block.transactions.push( block.transactions.push(
block block
.transactions .transactions
.get(0) .first()
.expect("block has coinbase") .expect("block has coinbase")
.clone(), .clone(),
); );
@ -436,7 +436,7 @@ fn funding_stream_validation_failure() -> Result<(), Report> {
// Build the new transaction with modified coinbase outputs // Build the new transaction with modified coinbase outputs
let tx = block let tx = block
.transactions .transactions
.get(0) .first()
.map(|transaction| { .map(|transaction| {
let mut output = transaction.outputs()[0].clone(); let mut output = transaction.outputs()[0].clone();
output.value = Amount::try_from(i32::MAX).unwrap(); output.value = Amount::try_from(i32::MAX).unwrap();

View File

@ -2791,7 +2791,7 @@ fn coinbase_outputs_are_decryptable_for_historical_blocks_for_network(
.unwrap(); .unwrap();
let coinbase_tx = block let coinbase_tx = block
.transactions .transactions
.get(0) .first()
.expect("must have coinbase transaction"); .expect("must have coinbase transaction");
// Check if the coinbase outputs are decryptable with an all-zero key. // Check if the coinbase outputs are decryptable with an all-zero key.

View File

@ -72,7 +72,7 @@ where
.collect(); .collect();
let parent_block = relevant_chain let parent_block = relevant_chain
.get(0) .first()
.expect("state must contain parent block to do contextual validation"); .expect("state must contain parent block to do contextual validation");
let parent_block = parent_block.borrow(); let parent_block = parent_block.borrow();
let parent_height = parent_block let parent_height = parent_block

View File

@ -16,7 +16,7 @@ pub mod upgrade;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
pub use block::{TransactionIndex, TransactionLocation, MAX_ON_DISK_HEIGHT}; pub use block::{TransactionLocation, MAX_ON_DISK_HEIGHT};
pub use transparent::{OutputIndex, OutputLocation}; pub use transparent::{OutputIndex, OutputLocation};
/// Helper type for writing types to disk as raw bytes. /// Helper type for writing types to disk as raw bytes.

View File

@ -28,21 +28,21 @@ mod tests;
pub use address::{ pub use address::{
balance::transparent_balance, balance::transparent_balance,
tx_id::transparent_tx_ids, tx_id::transparent_tx_ids,
utxo::{address_utxos, AddressUtxos, ADDRESS_HEIGHTS_FULL_RANGE}, utxo::{address_utxos, AddressUtxos},
}; };
pub use block::{ pub use block::{
any_utxo, block, block_header, mined_transaction, transaction_hashes_for_block, unspent_utxo, any_utxo, block, block_header, mined_transaction, transaction_hashes_for_block, unspent_utxo,
utxo,
}; };
pub use find::{ pub use find::{
best_tip, block_locator, chain_contains_hash, depth, finalized_state_contains_block_hash, best_tip, block_locator, depth, finalized_state_contains_block_hash, find_chain_hashes,
find_chain_hashes, find_chain_headers, hash_by_height, height_by_hash, next_median_time_past, find_chain_headers, hash_by_height, height_by_hash, next_median_time_past,
non_finalized_state_contains_block_hash, tip, tip_height, non_finalized_state_contains_block_hash, tip, tip_height,
}; };
pub use tree::{orchard_subtrees, orchard_tree, sapling_subtrees, sapling_tree}; pub use tree::{orchard_subtrees, orchard_tree, sapling_subtrees, sapling_tree};
#[cfg(feature = "getblocktemplate-rpcs")] #[cfg(any(test, feature = "proptest-impl"))]
pub use difficulty::get_block_template_chain_info; #[allow(unused_imports)]
pub use address::utxo::ADDRESS_HEIGHTS_FULL_RANGE;
/// If a finalized state query is interrupted by a new finalized block, /// If a finalized state query is interrupted by a new finalized block,
/// retry this many times. /// retry this many times.

View File

@ -143,20 +143,20 @@ async fn test_populated_state_responds_correctly(
transcript.push(( transcript.push((
Request::FindBlockHashes { Request::FindBlockHashes {
known_blocks: known_hashes.iter().rev().cloned().collect(), known_blocks: known_hashes.iter().rev().cloned().collect(),
stop: next_hashes.get(0).cloned(), stop: next_hashes.first().cloned(),
}, },
Ok(Response::BlockHashes( Ok(Response::BlockHashes(
next_hashes.get(0).iter().cloned().cloned().collect(), next_hashes.first().iter().cloned().cloned().collect(),
)), )),
)); ));
transcript.push(( transcript.push((
Request::FindBlockHeaders { Request::FindBlockHeaders {
known_blocks: known_hashes.iter().rev().cloned().collect(), known_blocks: known_hashes.iter().rev().cloned().collect(),
stop: next_hashes.get(0).cloned(), stop: next_hashes.first().cloned(),
}, },
Ok(Response::BlockHeaders( Ok(Response::BlockHeaders(
next_headers.get(0).iter().cloned().cloned().collect(), next_headers.first().iter().cloned().cloned().collect(),
)), )),
)); ));