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

bitcoindevkit / bdk / 9620632668

21 Jun 2024 10:43PM UTC coverage: 83.295% (-0.01%) from 83.305%
9620632668

Pull #1468

github

web-flow
Merge 729fec62d into e406675f4
Pull Request #1468: feat: use `Weight` type instead of `usize`

17 of 20 new or added lines in 3 files covered. (85.0%)

2 existing lines in 1 file now uncovered.

11119 of 13349 relevant lines covered (83.29%)

17387.58 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