Skip to content

Commit e523b12

Browse files
committed
clippy: fix needless_pass_by_value lint
This has some API-breaking changes but they're worthwhile (and eliminate a bunch of clones even in this codebase).
1 parent c19097a commit e523b12

7 files changed

Lines changed: 18 additions & 18 deletions

File tree

examples/raw_blind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ fn main() {
184184
&mut rng,
185185
&secp,
186186
dest_amt,
187-
Address::p2wsh(
187+
&Address::p2wsh(
188188
&Script::new_v0_wsh(&dest_wsh),
189189
Some(dest_blind_pk.inner),
190190
&PARAMS,
@@ -206,7 +206,7 @@ fn main() {
206206
&mut rng,
207207
&secp,
208208
change_amt,
209-
Address::p2wsh(
209+
&Address::p2wsh(
210210
&Script::new_v0_wsh(&change_wsh),
211211
Some(change_blind_pk.inner),
212212
&PARAMS,

src/blind.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ impl TxOut {
487487
rng: &mut R,
488488
secp: &Secp256k1<C>,
489489
value: u64,
490-
address: Address,
490+
address: &Address,
491491
asset: AssetId,
492492
spent_utxo_secrets: &[S],
493493
) -> Result<(Self, AssetBlindingFactor, ValueBlindingFactor, SecretKey), ConfidentialTxOutError>
@@ -599,7 +599,7 @@ impl TxOut {
599599
self.value
600600
.explicit()
601601
.ok_or(ConfidentialTxOutError::ExpectedExplicitValue)?,
602-
Address::from_script(&self.script_pubkey, Some(blinder), &AddressParams::ELEMENTS)
602+
&Address::from_script(&self.script_pubkey, Some(blinder), &AddressParams::ELEMENTS)
603603
.ok_or(ConfidentialTxOutError::InvalidAddress)?,
604604
self.asset
605605
.explicit()
@@ -1139,7 +1139,7 @@ impl Transaction {
11391139
rng,
11401140
secp,
11411141
out.value.explicit().unwrap(),
1142-
address,
1142+
&address,
11431143
out.asset.explicit().unwrap(),
11441144
spent_utxo_secrets,
11451145
)?;
@@ -1510,7 +1510,7 @@ mod tests {
15101510
&mut thread_rng(),
15111511
SECP256K1,
15121512
value,
1513-
address,
1513+
&address,
15141514
asset,
15151515
&spent_utxo_secrets,
15161516
)

src/pset/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ macro_rules! impl_psetmap_consensus_encoding {
7777
#[rustfmt::skip]
7878
macro_rules! impl_pset_prop_insert_pair {
7979
($slf:ident.$unkeyed_name:ident <= <$raw_key:ident: _>|<$raw_value:ident: $unkeyed_value_type:ty>) => {
80-
if $crate::pset::raw::ProprietaryKey::<u8>::from_key($raw_key.clone())?.key.is_empty() {
80+
if $crate::pset::raw::ProprietaryKey::<u8>::from_key(&$raw_key)?.key.is_empty() {
8181
if $slf.$unkeyed_name.is_none() {
8282
let val: $unkeyed_value_type = $crate::pset::serialize::Deserialize::deserialize(&$raw_value)?;
8383
$slf.$unkeyed_name = Some(val)

src/pset/map/global.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl Map for Global {
165165
| PSET_GLOBAL_TX_MODIFIABLE
166166
| PSET_GLOBAL_TX_VERSION => return Err(Error::DuplicateKey(raw_key).into()),
167167
PSET_GLOBAL_PROPRIETARY => {
168-
let prop_key = raw::ProprietaryKey::from_key(raw_key.clone())?;
168+
let prop_key = raw::ProprietaryKey::from_key(&raw_key)?;
169169
if prop_key.is_pset_key() && prop_key.subtype == PSBT_ELEMENTS_GLOBAL_SCALAR {
170170
if raw_value.is_empty() && prop_key.key.len() == 32 {
171171
let scalar = Tweak::from_slice(&prop_key.key)?;
@@ -456,7 +456,7 @@ impl Decodable for Global {
456456
}
457457
}
458458
PSET_GLOBAL_PROPRIETARY => {
459-
let prop_key = raw::ProprietaryKey::from_key(raw_key.clone())?;
459+
let prop_key = raw::ProprietaryKey::from_key(&raw_key)?;
460460
if prop_key.is_pset_key()
461461
&& prop_key.subtype == PSBT_ELEMENTS_GLOBAL_SCALAR
462462
{

src/pset/map/input.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -658,31 +658,31 @@ impl Map for Input {
658658
pset_insert_hash_pair(
659659
&mut self.ripemd160_preimages,
660660
raw_key,
661-
raw_value,
661+
&raw_value,
662662
error::PsetHash::Ripemd,
663663
)?;
664664
}
665665
PSET_IN_SHA256 => {
666666
pset_insert_hash_pair(
667667
&mut self.sha256_preimages,
668668
raw_key,
669-
raw_value,
669+
&raw_value,
670670
error::PsetHash::Sha256,
671671
)?;
672672
}
673673
PSET_IN_HASH160 => {
674674
pset_insert_hash_pair(
675675
&mut self.hash160_preimages,
676676
raw_key,
677-
raw_value,
677+
&raw_value,
678678
error::PsetHash::Hash160,
679679
)?;
680680
}
681681
PSET_IN_HASH256 => {
682682
pset_insert_hash_pair(
683683
&mut self.hash256_preimages,
684684
raw_key,
685-
raw_value,
685+
&raw_value,
686686
error::PsetHash::Hash256,
687687
)?;
688688
}
@@ -735,7 +735,7 @@ impl Map for Input {
735735
}
736736
}
737737
PSET_IN_PROPRIETARY => {
738-
let prop_key = raw::ProprietaryKey::from_key(raw_key.clone())?;
738+
let prop_key = raw::ProprietaryKey::from_key(&raw_key)?;
739739
if prop_key.is_pset_key() {
740740
match prop_key.subtype {
741741
PSBT_ELEMENTS_IN_ISSUANCE_VALUE => {
@@ -1173,7 +1173,7 @@ impl Decodable for Input {
11731173
fn pset_insert_hash_pair<H>(
11741174
map: &mut BTreeMap<H, Vec<u8>>,
11751175
raw_key: raw::Key,
1176-
raw_value: Vec<u8>,
1176+
raw_value: &[u8],
11771177
hash_type: error::PsetHash,
11781178
) -> Result<(), encode::Error>
11791179
where
@@ -1185,7 +1185,7 @@ where
11851185
let key_val: H = serialize::Deserialize::deserialize(&raw_key.key)?;
11861186
match map.entry(key_val) {
11871187
Entry::Vacant(empty_key) => {
1188-
let val: Vec<u8> = serialize::Deserialize::deserialize(&raw_value)?;
1188+
let val: Vec<u8> = serialize::Deserialize::deserialize(raw_value)?;
11891189
if <H as hashes::Hash>::hash(&val) != key_val {
11901190
return Err(pset::Error::InvalidPreimageHashPair {
11911191
preimage: val,

src/pset/map/output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl Map for Output {
341341
}
342342

343343
PSET_OUT_PROPRIETARY => {
344-
let prop_key = raw::ProprietaryKey::from_key(raw_key.clone())?;
344+
let prop_key = raw::ProprietaryKey::from_key(&raw_key)?;
345345
if prop_key.is_pset_key() {
346346
match prop_key.subtype {
347347
PSBT_ELEMENTS_OUT_VALUE_COMMITMENT => {

src/pset/raw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ where
212212
{
213213
/// Constructs [`ProprietaryKey`] from [Key]; returns
214214
/// [`Error::InvalidProprietaryKey`] if `key` do not starts with 0xFC byte
215-
pub fn from_key(key: Key) -> Result<Self, Error> {
215+
pub fn from_key(key: &Key) -> Result<Self, Error> {
216216
if key.type_value != 0xFC {
217217
return Err(Error::InvalidProprietaryKey);
218218
}

0 commit comments

Comments
 (0)