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

bitcoindevkit / bdk / 9519613010

14 Jun 2024 04:52PM UTC coverage: 83.312% (+0.2%) from 83.064%
9519613010

Pull #1473

github

web-flow
Merge feb27df18 into bc420923c
Pull Request #1473: Remove `persist` submodule

58 of 64 new or added lines in 5 files covered. (90.63%)

1 existing line in 1 file now uncovered.

11128 of 13357 relevant lines covered (83.31%)

17626.96 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 {
11,024✔
39
        let desc = self.to_string();
11,024✔
40
        let desc_without_checksum = desc.split('#').next().expect("Must be here");
11,024✔
41
        let descriptor_bytes = <Vec<u8>>::from(desc_without_checksum.as_bytes());
11,024✔
42
        DescriptorId(sha256::Hash::hash(&descriptor_bytes))
11,024✔
43
    }
11,024✔
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