• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bitcoindevkit / bdk / 9713429358

28 Jun 2024 01:15PM UTC coverage: 83.028% (+0.004%) from 83.024%
9713429358

Pull #1493

github

web-flow
Merge eae3ffe96 into 5c7cc3097
Pull Request #1493: [chain] Create module `keychain_txout_index`

15 of 17 new or added lines in 5 files covered. (88.24%)

1 existing line in 1 file now uncovered.

11051 of 13310 relevant lines covered (83.03%)

16853.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.15
/crates/chain/src/descriptor_ext.rs
1
use crate::{
2
    alloc::{string::ToString, vec::Vec},
3
    miniscript::{Descriptor, DescriptorPublicKey},
4
};
5
use bitcoin::hashes::{hash_newtype, sha256, Hash};
6

7
hash_newtype! {
8
    /// Represents the ID of a descriptor, defined as the sha256 hash of
9
    /// the descriptor string, checksum excluded.
10
    ///
11
    /// This is useful for having a fixed-length unique representation of a descriptor,
12
    /// in particular, we use it to persist application state changes related to the
13
    /// descriptor without having to re-write the whole descriptor each time.
14
    ///
15
    pub struct DescriptorId(pub sha256::Hash);
16
}
17

18
/// A trait to extend the functionality of a miniscript descriptor.
19
pub trait DescriptorExt {
20
    /// Returns the minimum value (in satoshis) at which an output is broadcastable.
21
    /// Panics if the descriptor wildcard is hardened.
22
    fn dust_value(&self) -> u64;
23

24
    /// Returns the descriptor id, calculated as the sha256 of the descriptor, checksum not
25
    /// included.
26
    fn descriptor_id(&self) -> DescriptorId;
27
}
28

29
impl DescriptorExt for Descriptor<DescriptorPublicKey> {
30
    fn dust_value(&self) -> u64 {
×
31
        self.at_derivation_index(0)
×
32
            .expect("descriptor can't have hardened derivation")
×
33
            .script_pubkey()
×
34
            .minimal_non_dust()
×
35
            .to_sat()
×
36
    }
×
37

38
    fn descriptor_id(&self) -> DescriptorId {
10,980✔
39
        let desc = self.to_string();
10,980✔
40
        let desc_without_checksum = desc.split('#').next().expect("Must be here");
10,980✔
41
        let descriptor_bytes = <Vec<u8>>::from(desc_without_checksum.as_bytes());
10,980✔
42
        DescriptorId(sha256::Hash::hash(&descriptor_bytes))
10,980✔
43
    }
10,980✔
44
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc