Skip to content

Commit

Permalink
Implementing clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Aug 26, 2021
1 parent 4ec3e5a commit 169f0db
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 130 deletions.
4 changes: 2 additions & 2 deletions dbc/src/keyset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Container for KeysetContainer {
.into_iter()
.map(|pk| pk.key)
.collect(),
tag: supplement.clone(),
tag: *supplement,
tweaking_factor: None,
})
} else {
Expand Down Expand Up @@ -114,7 +114,7 @@ where
msg: &MSG,
) -> Result<Self, Self::Error> {
let mut keyset = keyset_container.keyset.clone();
let mut pubkey = keyset_container.pubkey.clone();
let mut pubkey = keyset_container.pubkey;
keyset.insert(pubkey);

let tweaking_factor = lnpbp1::commit(
Expand Down
8 changes: 4 additions & 4 deletions dbc/src/lnpbp1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub fn commit(
// is represented by itself
let pubkey_sum = keyset
.iter()
.try_fold(target_pubkey.clone(), |sum, pubkey| sum.combine(pubkey))
.try_fold(*target_pubkey, |sum, pubkey| sum.combine(pubkey))
.map_err(|_| Error::SumInfiniteResult)?;

// ! [CONSENSUS-CRITICAL]:
Expand Down Expand Up @@ -143,10 +143,10 @@ pub fn commit(

// Applying tweaking factor to public key
target_pubkey
.add_exp_assign(&secp256k1::SECP256K1, &tweaking_factor[..])
.add_exp_assign(secp256k1::SECP256K1, &tweaking_factor[..])
.map_err(|_| Error::InvalidTweak)?;

keyset.insert(target_pubkey.clone());
keyset.insert(*target_pubkey);

// Returning tweaked public key
Ok(tweaking_factor)
Expand Down Expand Up @@ -205,7 +205,7 @@ pub fn verify(
// commit with the provided data, meaning that the commitment was not
// created. Thus, we return that verification have not passed, and not
// a error.
Err(_) => return false,
Err(_) => false,

// Verification succeeds if the commitment procedure produces public key
// equivalent to the verified one
Expand Down
14 changes: 5 additions & 9 deletions dbc/src/lockscript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Container for LockscriptContainer {
Ok(Self {
pubkey: proof.pubkey,
script: script.clone(),
tag: supplement.clone(),
tag: *supplement,
tweaking_factor: None,
})
} else {
Expand All @@ -87,7 +87,7 @@ impl Container for LockscriptContainer {
fn to_proof(&self) -> Proof {
Proof {
source: ScriptEncodeData::LockScript(self.script.clone()),
pubkey: self.pubkey.clone(),
pubkey: self.pubkey,
}
}

Expand Down Expand Up @@ -160,7 +160,7 @@ where
let (keys, hashes) =
container.script.extract_pubkey_hash_set::<Segwitv0>()?;
if keys.is_empty() && hashes.is_empty() {
Err(Error::LockscriptContainsNoKeys)?;
return Err(Error::LockscriptContainsNoKeys);
}

let mut key_hashes: HashSet<PubkeyHash> =
Expand All @@ -171,12 +171,8 @@ where
if hashes.is_empty() {
keys.get(&container.pubkey)
.ok_or(Error::LockscriptKeyNotFound)?;
} else if hashes
.into_iter()
.find(|hash| !key_hashes.contains(hash))
.is_some()
{
Err(Error::LockscriptContainsUnknownHashes)?;
} else if hashes.into_iter().any(|hash| !key_hashes.contains(&hash)) {
return Err(Error::LockscriptContainsUnknownHashes);
}

let mut keyset_container = KeysetContainer {
Expand Down
8 changes: 4 additions & 4 deletions dbc/src/pubkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Container for PubkeyContainer {
) -> Result<Self, Error> {
Ok(Self {
pubkey: proof.pubkey,
tag: supplement.clone(),
tag: *supplement,
tweaking_factor: None,
})
}
Expand All @@ -78,7 +78,7 @@ impl Container for PubkeyContainer {
// value, so the commitment container (original public key) just returns a
// copy of itself
#[inline]
fn to_proof(&self) -> Proof { Proof::from(self.pubkey.clone()) }
fn to_proof(&self) -> Proof { Proof::from(self.pubkey) }

#[inline]
fn into_proof(self) -> Proof { Proof::from(self.pubkey) }
Expand All @@ -103,8 +103,8 @@ where
pubkey_container: &mut Self::Container,
msg: &MSG,
) -> Result<Self, Self::Error> {
let mut keyset = bset![pubkey_container.pubkey.clone()];
let mut pubkey = pubkey_container.pubkey.clone();
let mut keyset = bset![pubkey_container.pubkey];
let mut pubkey = pubkey_container.pubkey;

let tweaking_factor = lnpbp1::commit(
&mut keyset,
Expand Down
34 changes: 16 additions & 18 deletions dbc/src/spk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl SpkContainer {
pubkey,
source,
method,
tag: protocol_tag.clone(),
tag: *protocol_tag,
tweaking_factor: None,
}
}
Expand Down Expand Up @@ -148,16 +148,14 @@ impl Container for SpkContainer {
{
ScriptEncodeMethod::ShWScriptHash
} else {
Err(Error::InvalidProofStructure)?
return Err(Error::InvalidProofStructure);
}
} else if *proof.pubkey.to_pubkey_script(Category::Nested)
== script
{
ScriptEncodeMethod::ShWPubkeyHash
} else {
if *proof.pubkey.to_pubkey_script(Category::Nested)
== script
{
ScriptEncodeMethod::ShWPubkeyHash
} else {
Err(Error::InvalidProofStructure)?
}
return Err(Error::InvalidProofStructure);
}
}
descriptors::Compact::Bare(script)
Expand Down Expand Up @@ -188,7 +186,7 @@ impl Container for SpkContainer {
| ScriptEncodeMethod::OpReturn => {
if let ScriptEncodeData::SinglePubkey = proof.source {
} else {
Err(Error::InvalidProofStructure)?
return Err(Error::InvalidProofStructure);
}
}
ScriptEncodeMethod::Bare
Expand All @@ -197,13 +195,13 @@ impl Container for SpkContainer {
| ScriptEncodeMethod::ShWScriptHash => {
if let ScriptEncodeData::LockScript(_) = proof.source {
} else {
Err(Error::InvalidProofStructure)?
return Err(Error::InvalidProofStructure);
}
}
ScriptEncodeMethod::Taproot => {
if let ScriptEncodeData::Taproot(_) = proof.source {
} else {
Err(Error::InvalidProofStructure)?
return Err(Error::InvalidProofStructure);
}
}
}
Expand All @@ -212,7 +210,7 @@ impl Container for SpkContainer {
pubkey: proof.pubkey,
source: proof.source,
method,
tag: supplement.clone(),
tag: *supplement,
tweaking_factor: None,
})
}
Expand All @@ -229,7 +227,7 @@ impl Container for SpkContainer {

fn to_proof(&self) -> Proof {
Proof {
pubkey: self.pubkey.clone(),
pubkey: self.pubkey,
source: self.source.clone(),
}
}
Expand Down Expand Up @@ -289,13 +287,13 @@ where
ShWScriptHash => {
lockscript.to_pubkey_script(Category::Nested)
}
_ => Err(Error::InvalidProofStructure)?,
_ => return Err(Error::InvalidProofStructure),
}
} else if let ScriptEncodeData::Taproot(taproot_hash) =
container.source
{
if container.method != Taproot {
Err(Error::InvalidProofStructure)?
return Err(Error::InvalidProofStructure);
}
let mut taproot_container = TaprootContainer {
script_root: taproot_hash,
Expand Down Expand Up @@ -331,11 +329,11 @@ where
OpReturn => {
let ser = pubkey.serialize();
if ser[0] != 0x02 {
Err(Error::InvalidOpReturnKey)?
return Err(Error::InvalidOpReturnKey);
}
Script::new_op_return(&ser).into()
}
_ => Err(Error::InvalidProofStructure)?,
_ => return Err(Error::InvalidProofStructure),
}
};
Ok(SpkCommitment::from_inner(script_pubkey))
Expand Down
12 changes: 6 additions & 6 deletions dbc/src/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ impl Container for TaprootContainer {
) -> Result<Self, Error> {
if let ScriptEncodeData::Taproot(ref tapscript_root) = proof.source {
Ok(Self {
script_root: tapscript_root.clone(),
script_root: *tapscript_root,
intermediate_key: proof.pubkey,
tag: supplement.clone(),
tag: *supplement,
tweaking_factor: None,
})
} else {
Expand All @@ -69,8 +69,8 @@ impl Container for TaprootContainer {

fn to_proof(&self) -> Proof {
Proof {
pubkey: self.intermediate_key.clone(),
source: ScriptEncodeData::Taproot(self.script_root.clone()),
pubkey: self.intermediate_key,
source: ScriptEncodeData::Taproot(self.script_root),
}
}

Expand Down Expand Up @@ -101,8 +101,8 @@ where
msg: &MSG,
) -> Result<Self, Self::Error> {
let mut pubkey_container = PubkeyContainer {
pubkey: container.intermediate_key.clone(),
tag: container.tag.clone(),
pubkey: container.intermediate_key,
tag: container.tag,
tweaking_factor: None,
};

Expand Down
2 changes: 1 addition & 1 deletion dbc/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl DumbDefault for Proof {
fn dumb_default() -> Self {
Proof {
pubkey: secp256k1::PublicKey::from_secret_key(
&secp256k1::SECP256K1,
secp256k1::SECP256K1,
&secp256k1::key::ONE_KEY,
),
source: Default::default(),
Expand Down
2 changes: 0 additions & 2 deletions seals/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
// along with this software.
// If not, see <https://opensource.org/licenses/Apache-2.0>.

use dbc;

#[derive(Clone, PartialEq, Debug, Display, From, Error)]
#[display(doc_comments)]
pub enum Error {
Expand Down
4 changes: 2 additions & 2 deletions seals/src/txout_seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ where
&self,
msg: &Self::Message,
witness: &Self::Witness,
medium: &impl SealMedium<Self>,
_medium: &impl SealMedium<Self>,
) -> Result<bool, Self::Error> {
let (host, supplement) = self
.resolver
Expand All @@ -80,7 +80,7 @@ where
.iter()
.filter(|txin| txin.previous_output == self.seal_definition);
if found_seals.count() != 1 {
Err(Error::ResolverLying)?
return Err(Error::ResolverLying);
}
let container =
TxContainer::reconstruct(&witness.1, &supplement, &host)?;
Expand Down
Loading

0 comments on commit 169f0db

Please sign in to comment.