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

bitcoindevkit / bdk / 5984736767

26 Aug 2023 12:20PM UTC coverage: 78.856% (+0.2%) from 78.694%
5984736767

Pull #1084

github

web-flow
Merge 8bdb5a43d into 8f978f86b
Pull Request #1084: Enhance bdk chain structures

86 of 86 new or added lines in 5 files covered. (100.0%)

8022 of 10173 relevant lines covered (78.86%)

5091.55 hits per line

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

17.14
/crates/chain/src/tx_data_traits.rs
1
use crate::collections::BTreeMap;
2
use crate::collections::BTreeSet;
3
use crate::BlockId;
4
use alloc::vec::Vec;
5

6
/// Trait that "anchors" blockchain data to a specific block of height and hash.
7
///
8
/// [`Anchor`] implementations must be [`Ord`] by the anchor block's [`BlockId`] first.
9
///
10
/// I.e. If transaction A is anchored in block B, then if block B is in the best chain, we can
11
/// assume that transaction A is also confirmed in the best chain. This does not necessarily mean
12
/// that transaction A is confirmed in block B. It could also mean transaction A is confirmed in a
13
/// parent block of B.
14
pub trait Anchor: core::fmt::Debug + Clone + Eq + PartialOrd + Ord + core::hash::Hash {
15
    /// Returns the [`BlockId`] that the associated blockchain data is "anchored" in.
16
    fn anchor_block(&self) -> BlockId;
17

18
    /// Get the upper bound of the chain data's confirmation height.
19
    ///
20
    /// The default definition gives a pessimistic answer. This can be overridden by the `Anchor`
21
    /// implementation for a more accurate value.
22
    fn confirmation_height_upper_bound(&self) -> u32 {
×
23
        self.anchor_block().height
×
24
    }
×
25
}
26

27
impl<A: Anchor> Anchor for &'static A {
28
    fn anchor_block(&self) -> BlockId {
×
29
        <A as Anchor>::anchor_block(self)
×
30
    }
×
31
}
32

33
/// Trait that makes an object appendable.
34
pub trait Append {
35
    /// Append another object of the same type onto `self`.
36
    fn append(&mut self, other: Self);
37

38
    /// Returns whether the structure is considered empty.
39
    fn is_empty(&self) -> bool;
40
}
41

42
impl Append for () {
43
    fn append(&mut self, _other: Self) {}
×
44

45
    fn is_empty(&self) -> bool {
×
46
        true
×
47
    }
×
48
}
49

50
impl<K: Ord, V> Append for BTreeMap<K, V> {
51
    fn append(&mut self, mut other: Self) {
614✔
52
        BTreeMap::append(self, &mut other)
614✔
53
    }
614✔
54

55
    fn is_empty(&self) -> bool {
×
56
        BTreeMap::is_empty(self)
×
57
    }
×
58
}
59

60
impl<T: Ord> Append for BTreeSet<T> {
61
    fn append(&mut self, mut other: Self) {
×
62
        BTreeSet::append(self, &mut other)
×
63
    }
×
64

65
    fn is_empty(&self) -> bool {
×
66
        BTreeSet::is_empty(self)
×
67
    }
×
68
}
69

70
impl<T> Append for Vec<T> {
71
    fn append(&mut self, mut other: Self) {
×
72
        Vec::append(self, &mut other)
×
73
    }
×
74

75
    fn is_empty(&self) -> bool {
1✔
76
        Vec::is_empty(self)
1✔
77
    }
1✔
78
}
79

80
impl<A: Append, B: Append> Append for (A, B) {
81
    fn append(&mut self, other: Self) {
×
82
        Append::append(&mut self.0, other.0);
×
83
        Append::append(&mut self.1, other.1);
×
84
    }
×
85

86
    fn is_empty(&self) -> bool {
×
87
        Append::is_empty(&self.0) && Append::is_empty(&self.1)
×
88
    }
×
89
}
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