Skip to content

Commit

Permalink
chore: fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Aug 18, 2024
1 parent fbb3710 commit 585e546
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
24 changes: 13 additions & 11 deletions derive/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use core::str::FromStr;
use std::collections::BTreeSet;

use amplify::confinement;
use amplify::confinement::Confined;
use amplify::confinement::{Confined, NonEmptyOrdSet};

use crate::{DerivationIndex, Idx, IdxBase, IndexParseError, NormalIndex, Terminal};

Expand All @@ -41,28 +41,28 @@ pub enum DerivationParseError {
}

#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub struct DerivationSeg<I: IdxBase = NormalIndex>(Confined<BTreeSet<I>, 1, 8>);
pub struct DerivationSeg<I: IdxBase = NormalIndex>(NonEmptyOrdSet<I, 8>);

impl<I: IdxBase> From<&'static [I]> for DerivationSeg<I> {
fn from(indexes: &'static [I]) -> Self {
Self(Confined::from_iter_unsafe(indexes.iter().copied()))
Self(Confined::from_iter_checked(indexes.iter().copied()))

Check warning on line 48 in derive/src/path.rs

View check run for this annotation

Codecov / codecov/patch

derive/src/path.rs#L48

Added line #L48 was not covered by tests
}
}

impl<I: IdxBase> From<[I; 2]> for DerivationSeg<I> {
fn from(indexes: [I; 2]) -> Self { Self(Confined::from_iter_unsafe(indexes)) }
fn from(indexes: [I; 2]) -> Self { Self(Confined::from_iter_checked(indexes)) }

Check warning on line 53 in derive/src/path.rs

View check run for this annotation

Codecov / codecov/patch

derive/src/path.rs#L53

Added line #L53 was not covered by tests
}

impl<I: IdxBase> From<[I; 3]> for DerivationSeg<I> {
fn from(indexes: [I; 3]) -> Self { Self(Confined::from_iter_unsafe(indexes)) }
fn from(indexes: [I; 3]) -> Self { Self(Confined::from_iter_checked(indexes)) }

Check warning on line 57 in derive/src/path.rs

View check run for this annotation

Codecov / codecov/patch

derive/src/path.rs#L57

Added line #L57 was not covered by tests
}

impl<I: IdxBase> From<[I; 4]> for DerivationSeg<I> {
fn from(indexes: [I; 4]) -> Self { Self(Confined::from_iter_unsafe(indexes)) }
fn from(indexes: [I; 4]) -> Self { Self(Confined::from_iter_checked(indexes)) }

Check warning on line 61 in derive/src/path.rs

View check run for this annotation

Codecov / codecov/patch

derive/src/path.rs#L61

Added line #L61 was not covered by tests
}

impl<I: IdxBase> DerivationSeg<I> {
pub fn new(index: I) -> Self { DerivationSeg(confined_bset![index]) }
pub fn new(index: I) -> Self { DerivationSeg(NonEmptyOrdSet::with(index)) }

Check warning on line 65 in derive/src/path.rs

View check run for this annotation

Codecov / codecov/patch

derive/src/path.rs#L65

Added line #L65 was not covered by tests

pub fn with(iter: impl IntoIterator<Item = I>) -> Result<Self, confinement::Error> {
Confined::try_from_iter(iter).map(DerivationSeg)
Expand All @@ -86,17 +86,19 @@ impl<I: IdxBase> DerivationSeg<I> {
}

#[inline]
pub fn into_set(self) -> BTreeSet<I> { self.0.into_inner() }
pub fn into_set(self) -> BTreeSet<I> { self.0.release() }

Check warning on line 89 in derive/src/path.rs

View check run for this annotation

Codecov / codecov/patch

derive/src/path.rs#L89

Added line #L89 was not covered by tests

#[inline]
pub fn to_set(&self) -> BTreeSet<I> { self.0.to_inner() }
pub fn to_set(&self) -> BTreeSet<I> { self.0.to_unconfined() }

Check warning on line 92 in derive/src/path.rs

View check run for this annotation

Codecov / codecov/patch

derive/src/path.rs#L92

Added line #L92 was not covered by tests

#[inline]
pub fn as_set(&self) -> &BTreeSet<I> { self.0.as_inner() }
pub fn as_set(&self) -> &BTreeSet<I> { self.0.as_unconfined() }

Check warning on line 95 in derive/src/path.rs

View check run for this annotation

Codecov / codecov/patch

derive/src/path.rs#L95

Added line #L95 was not covered by tests
}

impl DerivationSeg<NormalIndex> {
pub fn standard() -> Self { DerivationSeg(confined_bset![NormalIndex::ZERO, NormalIndex::ONE]) }
pub fn standard() -> Self {
DerivationSeg(NonEmptyOrdSet::from_iter_checked([NormalIndex::ZERO, NormalIndex::ONE]))
}

Check warning on line 101 in derive/src/path.rs

View check run for this annotation

Codecov / codecov/patch

derive/src/path.rs#L99-L101

Added lines #L99 - L101 were not covered by tests
}

impl<I: IdxBase> Index<u8> for DerivationSeg<I> {
Expand Down
4 changes: 2 additions & 2 deletions derive/src/xkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::str::FromStr;
use amplify::{confinement, hex, ByteArray, Bytes20, Bytes32, Bytes4, Wrapper};
use bc::secp256k1::{Keypair, PublicKey, SecretKey, SECP256K1};
use bc::{secp256k1, CompressedPk, InvalidPubkey, LegacyPk, XOnlyPk};
use commit_verify::{Digest, Ripemd160, Sha256};
use commit_verify::{Digest, Ripemd160};
use hmac::{Hmac, Mac};
use sha2::Sha512;

Expand Down Expand Up @@ -276,7 +276,7 @@ impl Xpub {

/// Returns the HASH160 of the chaincode
pub fn identifier(&self) -> XpubId {
let hash = Ripemd160::digest(&self.core.public_key.serialize());
let hash = Ripemd160::digest(self.core.public_key.serialize());
XpubId::from_slice_unsafe(hash)

Check warning on line 280 in derive/src/xkey.rs

View check run for this annotation

Codecov / codecov/patch

derive/src/xkey.rs#L279-L280

Added lines #L279 - L280 were not covered by tests
}

Expand Down
20 changes: 6 additions & 14 deletions psbt/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl From<UnsignedTx> for Tx {
fn from(unsigned_tx: UnsignedTx) -> Tx {
Tx {
version: unsigned_tx.version,
inputs: VarIntArray::from_collection_unsafe(
inputs: VarIntArray::from_checked(

Check warning on line 106 in psbt/src/data.rs

View check run for this annotation

Codecov / codecov/patch

psbt/src/data.rs#L106

Added line #L106 was not covered by tests
unsigned_tx.inputs.into_iter().map(TxIn::from).collect(),
),
outputs: unsigned_tx.outputs,
Expand All @@ -117,7 +117,7 @@ impl UnsignedTx {
pub fn with_sigs_removed(tx: Tx) -> UnsignedTx {
UnsignedTx {
version: tx.version,
inputs: VarIntArray::from_collection_unsafe(
inputs: VarIntArray::from_checked(

Check warning on line 120 in psbt/src/data.rs

View check run for this annotation

Codecov / codecov/patch

psbt/src/data.rs#L120

Added line #L120 was not covered by tests
tx.inputs.into_iter().map(UnsignedTxIn::with_sigs_removed).collect(),
),
outputs: tx.outputs,
Expand Down Expand Up @@ -257,12 +257,8 @@ impl Psbt {
pub fn to_unsigned_tx(&self) -> UnsignedTx {
UnsignedTx {
version: self.tx_version,
inputs: VarIntArray::from_collection_unsafe(
self.inputs().map(Input::to_unsigned_txin).collect(),
),
outputs: VarIntArray::from_collection_unsafe(
self.outputs().map(Output::to_txout).collect(),
),
inputs: VarIntArray::from_iter_checked(self.inputs().map(Input::to_unsigned_txin)),
outputs: VarIntArray::from_iter_checked(self.outputs().map(Output::to_txout)),
lock_time: self.lock_time(),
}
}
Expand Down Expand Up @@ -479,12 +475,8 @@ impl Psbt {

Ok(Tx {
version: self.tx_version,
inputs: VarIntArray::from_collection_unsafe(
self.inputs.iter().map(Input::to_signed_txin).collect(),
),
outputs: VarIntArray::from_collection_unsafe(
self.outputs.iter().map(Output::to_txout).collect(),
),
inputs: VarIntArray::from_iter_checked(self.inputs.iter().map(Input::to_signed_txin)),
outputs: VarIntArray::from_iter_checked(self.outputs.iter().map(Output::to_txout)),

Check warning on line 479 in psbt/src/data.rs

View check run for this annotation

Codecov / codecov/patch

psbt/src/data.rs#L478-L479

Added lines #L478 - L479 were not covered by tests
lock_time: self.lock_time(),
})
}
Expand Down

0 comments on commit 585e546

Please sign in to comment.