Skip to content

Commit

Permalink
descriptor: make keychains method returni owned set
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Nov 19, 2023
1 parent e3bf159 commit 72a734e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion descriptors/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<S: DeriveSet> Derive<DerivedScript> for StdDescr<S> {
}
}

fn keychains(&self) -> &BTreeSet<Keychain> {
fn keychains(&self) -> BTreeSet<Keychain> {

Check warning on line 150 in descriptors/src/descriptor.rs

View check run for this annotation

Codecov / codecov/patch

descriptors/src/descriptor.rs#L150

Added line #L150 was not covered by tests
match self {
StdDescr::Wpkh(d) => d.keychains(),
StdDescr::TrKey(d) => d.keychains(),

Check warning on line 153 in descriptors/src/descriptor.rs

View check run for this annotation

Codecov / codecov/patch

descriptors/src/descriptor.rs#L152-L153

Added lines #L152 - L153 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion descriptors/src/segwit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<K: DeriveCompr> Derive<DerivedScript> for Wpkh<K> {
fn default_keychain(&self) -> Keychain { self.0.default_keychain() }

Check warning on line 45 in descriptors/src/segwit.rs

View check run for this annotation

Codecov / codecov/patch

descriptors/src/segwit.rs#L45

Added line #L45 was not covered by tests

#[inline]
fn keychains(&self) -> &BTreeSet<Keychain> { self.0.keychains() }
fn keychains(&self) -> BTreeSet<Keychain> { self.0.keychains() }

Check warning on line 48 in descriptors/src/segwit.rs

View check run for this annotation

Codecov / codecov/patch

descriptors/src/segwit.rs#L48

Added line #L48 was not covered by tests

fn derive(
&self,
Expand Down
2 changes: 1 addition & 1 deletion descriptors/src/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<K: DeriveXOnly> Derive<DerivedScript> for TrKey<K> {
fn default_keychain(&self) -> Keychain { self.0.default_keychain() }

Check warning on line 45 in descriptors/src/taproot.rs

View check run for this annotation

Codecov / codecov/patch

descriptors/src/taproot.rs#L45

Added line #L45 was not covered by tests

#[inline]
fn keychains(&self) -> &BTreeSet<Keychain> { self.0.keychains() }
fn keychains(&self) -> BTreeSet<Keychain> { self.0.keychains() }

Check warning on line 48 in descriptors/src/taproot.rs

View check run for this annotation

Codecov / codecov/patch

descriptors/src/taproot.rs#L48

Added line #L48 was not covered by tests

fn derive(
&self,
Expand Down
8 changes: 4 additions & 4 deletions std/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl FromStr for DerivedAddr {
pub trait Derive<D> {
fn default_keychain(&self) -> Keychain;

fn keychains(&self) -> &BTreeSet<Keychain>;
fn keychains(&self) -> BTreeSet<Keychain>;

fn derive(&self, keychain: impl Into<Keychain>, index: impl Into<NormalIndex>) -> D;

Expand Down Expand Up @@ -364,7 +364,7 @@ impl Derive<LegacyPk> for XpubDerivable {
fn default_keychain(&self) -> Keychain { self.keychains.first() }

Check warning on line 364 in std/src/derive.rs

View check run for this annotation

Codecov / codecov/patch

std/src/derive.rs#L364

Added line #L364 was not covered by tests

#[inline]
fn keychains(&self) -> &BTreeSet<Keychain> { self.keychains.as_ref() }
fn keychains(&self) -> BTreeSet<Keychain> { self.keychains.to_set() }

Check warning on line 367 in std/src/derive.rs

View check run for this annotation

Codecov / codecov/patch

std/src/derive.rs#L367

Added line #L367 was not covered by tests

fn derive(&self, keychain: impl Into<Keychain>, index: impl Into<NormalIndex>) -> LegacyPk {
self.xpub().derive_pub([keychain.into().into(), index.into()]).to_legacy_pub()

Check warning on line 370 in std/src/derive.rs

View check run for this annotation

Codecov / codecov/patch

std/src/derive.rs#L369-L370

Added lines #L369 - L370 were not covered by tests
Expand All @@ -376,7 +376,7 @@ impl Derive<CompressedPk> for XpubDerivable {
fn default_keychain(&self) -> Keychain { self.keychains.first() }

Check warning on line 376 in std/src/derive.rs

View check run for this annotation

Codecov / codecov/patch

std/src/derive.rs#L376

Added line #L376 was not covered by tests

#[inline]
fn keychains(&self) -> &BTreeSet<Keychain> { self.keychains.as_ref() }
fn keychains(&self) -> BTreeSet<Keychain> { self.keychains.to_set() }

Check warning on line 379 in std/src/derive.rs

View check run for this annotation

Codecov / codecov/patch

std/src/derive.rs#L379

Added line #L379 was not covered by tests

fn derive(&self, keychain: impl Into<Keychain>, index: impl Into<NormalIndex>) -> CompressedPk {
self.xpub().derive_pub([keychain.into().into(), index.into()]).to_compr_pub()

Check warning on line 382 in std/src/derive.rs

View check run for this annotation

Codecov / codecov/patch

std/src/derive.rs#L381-L382

Added lines #L381 - L382 were not covered by tests
Expand All @@ -388,7 +388,7 @@ impl Derive<XOnlyPk> for XpubDerivable {
fn default_keychain(&self) -> Keychain { self.keychains.first() }

Check warning on line 388 in std/src/derive.rs

View check run for this annotation

Codecov / codecov/patch

std/src/derive.rs#L388

Added line #L388 was not covered by tests

#[inline]
fn keychains(&self) -> &BTreeSet<Keychain> { self.keychains.as_ref() }
fn keychains(&self) -> BTreeSet<Keychain> { self.keychains.to_set() }

Check warning on line 391 in std/src/derive.rs

View check run for this annotation

Codecov / codecov/patch

std/src/derive.rs#L391

Added line #L391 was not covered by tests

fn derive(&self, keychain: impl Into<Keychain>, index: impl Into<NormalIndex>) -> XOnlyPk {
self.xpub().derive_pub([keychain.into().into(), index.into()]).to_xonly_pub()

Check warning on line 394 in std/src/derive.rs

View check run for this annotation

Codecov / codecov/patch

std/src/derive.rs#L393-L394

Added lines #L393 - L394 were not covered by tests
Expand Down
14 changes: 9 additions & 5 deletions std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,21 @@ impl<I: IdxBase> DerivationSeg<I> {
.first()
.expect("confined type guarantees that there is at least one item in the collection")
}

Check warning on line 68 in std/src/path.rs

View check run for this annotation

Codecov / codecov/patch

std/src/path.rs#L63-L68

Added lines #L63 - L68 were not covered by tests

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

Check warning on line 71 in std/src/path.rs

View check run for this annotation

Codecov / codecov/patch

std/src/path.rs#L71

Added line #L71 was not covered by tests

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

Check warning on line 74 in std/src/path.rs

View check run for this annotation

Codecov / codecov/patch

std/src/path.rs#L74

Added line #L74 was not covered by tests

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

Check warning on line 77 in std/src/path.rs

View check run for this annotation

Codecov / codecov/patch

std/src/path.rs#L77

Added line #L77 was not covered by tests
}

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

impl<I: IdxBase> AsRef<BTreeSet<I>> for DerivationSeg<I> {
#[inline]
fn as_ref(&self) -> &BTreeSet<I> { &self.0.as_inner() }
}

impl<I: IdxBase> Index<u8> for DerivationSeg<I> {
type Output = I;

Expand Down

0 comments on commit 72a734e

Please sign in to comment.