Remove unnecessary explicit reference

Clippy warns about creating a reference that is immediately
de-referenced.

Remove unnecessary explicit `&`, while we are at it remove unnecessary
explicit types that appear on the same lines of code.
This commit is contained in:
Tobin C. Harding 2022-06-07 15:07:59 +10:00
parent ef90e3d4ed
commit 2b8d93ec4b
6 changed files with 21 additions and 21 deletions

View File

@ -988,7 +988,7 @@ mod tests {
let addr = Address::p2pkh(&key, Bitcoin); let addr = Address::p2pkh(&key, Bitcoin);
assert_eq!(&addr.to_string(), "1QJVDzdqb1VpbDK7uDeyVXy9mR27CJiyhY"); assert_eq!(&addr.to_string(), "1QJVDzdqb1VpbDK7uDeyVXy9mR27CJiyhY");
let key = hex_key!(&"03df154ebfcf29d29cc10d5c2565018bce2d9edbab267c31d2caf44a63056cf99f"); let key = hex_key!("03df154ebfcf29d29cc10d5c2565018bce2d9edbab267c31d2caf44a63056cf99f");
let addr = Address::p2pkh(&key, Testnet); let addr = Address::p2pkh(&key, Testnet);
assert_eq!(&addr.to_string(), "mqkhEMH6NCeYjFybv7pvFC22MFeaNT9AQC"); assert_eq!(&addr.to_string(), "mqkhEMH6NCeYjFybv7pvFC22MFeaNT9AQC");
assert_eq!(addr.address_type(), Some(AddressType::P2pkh)); assert_eq!(addr.address_type(), Some(AddressType::P2pkh));
@ -1108,7 +1108,7 @@ mod tests {
("bc1zw508d6qejxtdg4y5r3zarvaryvaxxpcs", None), ("bc1zw508d6qejxtdg4y5r3zarvaryvaxxpcs", None),
]; ];
for (address, expected_type) in &addresses { for (address, expected_type) in &addresses {
let addr = Address::from_str(&address).unwrap(); let addr = Address::from_str(address).unwrap();
assert_eq!(&addr.address_type(), expected_type); assert_eq!(&addr.address_type(), expected_type);
} }
} }

View File

@ -299,7 +299,7 @@ mod tests {
assert_eq!(&encode_slice(&[0, 0, 0, 0, 13, 36][..]), "1111211"); assert_eq!(&encode_slice(&[0, 0, 0, 0, 13, 36][..]), "1111211");
// Long input (>100 bytes => has to use heap) // Long input (>100 bytes => has to use heap)
let res = encode_slice(&"BitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBit\ let res = encode_slice("BitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBit\
coinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoin".as_bytes()); coinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoinBitcoin".as_bytes());
let exp = "ZqC5ZdfpZRi7fjA8hbhX5pEE96MdH9hEaC1YouxscPtbJF16qVWksHWR4wwvx7MotFcs2ChbJqK8KJ9X\ let exp = "ZqC5ZdfpZRi7fjA8hbhX5pEE96MdH9hEaC1YouxscPtbJF16qVWksHWR4wwvx7MotFcs2ChbJqK8KJ9X\
wZznwWn1JFDhhTmGo9v6GjAVikzCsBWZehu7bm22xL8b5zBR5AsBygYRwbFJsNwNkjpyFuDKwmsUTKvkULCvucPJrN5\ wZznwWn1JFDhhTmGo9v6GjAVikzCsBWZehu7bm22xL8b5zBR5AsBygYRwbFJsNwNkjpyFuDKwmsUTKvkULCvucPJrN5\

View File

@ -542,13 +542,13 @@ mod test {
let testdata = serde_json::from_str::<Value>(data).unwrap().as_array().unwrap().clone(); let testdata = serde_json::from_str::<Value>(data).unwrap().as_array().unwrap().clone();
for t in testdata.iter().skip(1) { for t in testdata.iter().skip(1) {
let block_hash = BlockHash::from_hex(&t.get(1).unwrap().as_str().unwrap()).unwrap(); let block_hash = BlockHash::from_hex(t.get(1).unwrap().as_str().unwrap()).unwrap();
let block: Block = deserialize(&Vec::from_hex(&t.get(2).unwrap().as_str().unwrap()).unwrap()).unwrap(); let block: Block = deserialize(&Vec::from_hex(t.get(2).unwrap().as_str().unwrap()).unwrap()).unwrap();
assert_eq!(block.block_hash(), block_hash); assert_eq!(block.block_hash(), block_hash);
let scripts = t.get(3).unwrap().as_array().unwrap(); let scripts = t.get(3).unwrap().as_array().unwrap();
let previous_filter_header = FilterHeader::from_hex(&t.get(4).unwrap().as_str().unwrap()).unwrap(); let previous_filter_header = FilterHeader::from_hex(t.get(4).unwrap().as_str().unwrap()).unwrap();
let filter_content = Vec::from_hex(&t.get(5).unwrap().as_str().unwrap()).unwrap(); let filter_content = Vec::from_hex(t.get(5).unwrap().as_str().unwrap()).unwrap();
let filter_header = FilterHeader::from_hex(&t.get(6).unwrap().as_str().unwrap()).unwrap(); let filter_header = FilterHeader::from_hex(t.get(6).unwrap().as_str().unwrap()).unwrap();
let mut txmap = HashMap::new(); let mut txmap = HashMap::new();
let mut si = scripts.iter(); let mut si = scripts.iter();
@ -576,7 +576,7 @@ mod test {
for (_, script) in &txmap { for (_, script) in &txmap {
let query = vec![script]; let query = vec![script];
if !script.is_empty () { if !script.is_empty () {
assert!(filter.match_any(&block_hash, &mut query.iter() assert!(filter.match_any(block_hash, &mut query.iter()
.map(|s| s.as_bytes())).unwrap()); .map(|s| s.as_bytes())).unwrap());
} }
} }

View File

@ -358,7 +358,7 @@ mod tests {
use crate::blockdata::transaction::{Transaction, TxIn, TxOut, OutPoint}; use crate::blockdata::transaction::{Transaction, TxIn, TxOut, OutPoint};
use crate::network::constants::Network::Bitcoin; use crate::network::constants::Network::Bitcoin;
use crate::consensus::encode::{deserialize, serialize, serialize_hex}; use crate::consensus::encode::{deserialize, serialize, serialize_hex};
use crate::util::bip32::{ChildNumber, ExtendedPrivKey, ExtendedPubKey, Fingerprint, KeySource}; use crate::util::bip32::{ChildNumber, ExtendedPrivKey, ExtendedPubKey, KeySource};
use crate::util::psbt::map::{Output, Input}; use crate::util::psbt::map::{Output, Input};
use crate::util::psbt::raw; use crate::util::psbt::raw;
@ -404,7 +404,7 @@ mod tests {
let mut sk: ExtendedPrivKey = ExtendedPrivKey::new_master(Bitcoin, &seed).unwrap(); let mut sk: ExtendedPrivKey = ExtendedPrivKey::new_master(Bitcoin, &seed).unwrap();
let fprint: Fingerprint = sk.fingerprint(&secp); let fprint = sk.fingerprint(secp);
let dpath: Vec<ChildNumber> = vec![ let dpath: Vec<ChildNumber> = vec![
ChildNumber::from_normal_idx(0).unwrap(), ChildNumber::from_normal_idx(0).unwrap(),
@ -419,7 +419,7 @@ mod tests {
sk = sk.derive_priv(secp, &dpath).unwrap(); sk = sk.derive_priv(secp, &dpath).unwrap();
let pk: ExtendedPubKey = ExtendedPubKey::from_priv(&secp, &sk); let pk = ExtendedPubKey::from_priv(secp, &sk);
hd_keypaths.insert(pk.public_key, (fprint, dpath.into())); hd_keypaths.insert(pk.public_key, (fprint, dpath.into()));
@ -803,7 +803,7 @@ mod tests {
assert!(&psbt.inputs[0].final_script_sig.is_some()); assert!(&psbt.inputs[0].final_script_sig.is_some());
let redeem_script: &Script = &psbt.inputs[1].redeem_script.as_ref().unwrap(); let redeem_script = psbt.inputs[1].redeem_script.as_ref().unwrap();
let expected_out = hex_script!("a9143545e6e33b832c47050f24d3eeb93c9c03948bc787"); let expected_out = hex_script!("a9143545e6e33b832c47050f24d3eeb93c9c03948bc787");
assert!(redeem_script.is_v0_p2wpkh()); assert!(redeem_script.is_v0_p2wpkh());
@ -849,7 +849,7 @@ mod tests {
assert!(&psbt.inputs[0].final_script_sig.is_none()); assert!(&psbt.inputs[0].final_script_sig.is_none());
assert!(&psbt.inputs[1].final_script_sig.is_none()); assert!(&psbt.inputs[1].final_script_sig.is_none());
let redeem_script: &Script = &psbt.inputs[1].redeem_script.as_ref().unwrap(); let redeem_script = psbt.inputs[1].redeem_script.as_ref().unwrap();
let expected_out = hex_script!("a9143545e6e33b832c47050f24d3eeb93c9c03948bc787"); let expected_out = hex_script!("a9143545e6e33b832c47050f24d3eeb93c9c03948bc787");
assert!(redeem_script.is_v0_p2wpkh()); assert!(redeem_script.is_v0_p2wpkh());
@ -873,7 +873,7 @@ mod tests {
assert!(&psbt.inputs[0].final_script_sig.is_none()); assert!(&psbt.inputs[0].final_script_sig.is_none());
let redeem_script: &Script = &psbt.inputs[0].redeem_script.as_ref().unwrap(); let redeem_script = psbt.inputs[0].redeem_script.as_ref().unwrap();
let expected_out = hex_script!("a9146345200f68d189e1adc0df1c4d16ea8f14c0dbeb87"); let expected_out = hex_script!("a9146345200f68d189e1adc0df1c4d16ea8f14c0dbeb87");
assert!(redeem_script.is_v0_p2wsh()); assert!(redeem_script.is_v0_p2wsh());

View File

@ -1115,11 +1115,11 @@ mod tests {
}; };
// tests // tests
let keypair = secp256k1::KeyPair::from_secret_key(&secp, internal_priv_key); let keypair = secp256k1::KeyPair::from_secret_key(secp, internal_priv_key);
let internal_key = XOnlyPublicKey::from_keypair(&keypair); let internal_key = XOnlyPublicKey::from_keypair(&keypair);
let tweak = TapTweakHash::from_key_and_tweak(internal_key, merkle_root); let tweak = TapTweakHash::from_key_and_tweak(internal_key, merkle_root);
let mut tweaked_keypair = keypair; let mut tweaked_keypair = keypair;
tweaked_keypair.tweak_add_assign(&secp, &tweak).unwrap(); tweaked_keypair.tweak_add_assign(secp, &tweak).unwrap();
let mut sig_msg = Vec::new(); let mut sig_msg = Vec::new();
cache.taproot_encode_signing_data_to( cache.taproot_encode_signing_data_to(
&mut sig_msg, &mut sig_msg,

View File

@ -1361,12 +1361,12 @@ mod test {
if script_tree.is_null() { if script_tree.is_null() {
assert!(arr["intermediary"]["merkleRoot"].is_null()); assert!(arr["intermediary"]["merkleRoot"].is_null());
} else { } else {
merkle_root = Some(TapBranchHash::from_str(&arr["intermediary"]["merkleRoot"].as_str().unwrap()).unwrap()); merkle_root = Some(TapBranchHash::from_str(arr["intermediary"]["merkleRoot"].as_str().unwrap()).unwrap());
let leaf_hashes = arr["intermediary"]["leafHashes"].as_array().unwrap(); let leaf_hashes = arr["intermediary"]["leafHashes"].as_array().unwrap();
let ctrl_blks = arr["expected"]["scriptPathControlBlocks"].as_array().unwrap(); let ctrl_blks = arr["expected"]["scriptPathControlBlocks"].as_array().unwrap();
let mut builder = TaprootBuilder::new(); let mut builder = TaprootBuilder::new();
let mut leaves = vec![]; let mut leaves = vec![];
builder = process_script_trees(&script_tree, builder, &mut leaves, 0); builder = process_script_trees(script_tree, builder, &mut leaves, 0);
let spend_info = builder.finalize(secp, internal_key).unwrap(); let spend_info = builder.finalize(secp, internal_key).unwrap();
for (i, script_ver) in leaves.iter().enumerate() { for (i, script_ver) in leaves.iter().enumerate() {
let expected_leaf_hash = leaf_hashes[i].as_str().unwrap(); let expected_leaf_hash = leaf_hashes[i].as_str().unwrap();
@ -1384,8 +1384,8 @@ mod test {
let expected_addr = Address::from_str(arr["expected"]["bip350Address"].as_str().unwrap()).unwrap(); let expected_addr = Address::from_str(arr["expected"]["bip350Address"].as_str().unwrap()).unwrap();
let tweak = TapTweakHash::from_key_and_tweak(internal_key, merkle_root); let tweak = TapTweakHash::from_key_and_tweak(internal_key, merkle_root);
let (output_key, _parity) = internal_key.tap_tweak(&secp, merkle_root); let (output_key, _parity) = internal_key.tap_tweak(secp, merkle_root);
let addr = Address::p2tr(&secp, internal_key, merkle_root, Network::Bitcoin); let addr = Address::p2tr(secp, internal_key, merkle_root, Network::Bitcoin);
let spk = addr.script_pubkey(); let spk = addr.script_pubkey();
assert_eq!(expected_output_key, output_key.to_inner()); assert_eq!(expected_output_key, output_key.to_inner());