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

bitcoindevkit / bdk / 9519613010

14 Jun 2024 04:52PM CUT 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

97.73
/crates/chain/src/changeset.rs
1
//! This module is home to the [`PersistBackend`] trait which defines the behavior of a data store
2
//! required to persist changes made to BDK data structures.
3
//!
4
//! The [`CombinedChangeSet`] type encapsulates a combination of [`crate`] structures that are
5
//! typically persisted together.
6

7
/// A changeset containing [`crate`] structures typically persisted together.
8
#[cfg(feature = "miniscript")]
9
#[derive(Debug, Clone, PartialEq)]
10
#[cfg_attr(
11
    feature = "serde",
12
    derive(crate::serde::Deserialize, crate::serde::Serialize),
12✔
13
    serde(
14
        crate = "crate::serde",
15
        bound(
16
            deserialize = "A: Ord + crate::serde::Deserialize<'de>, K: Ord + crate::serde::Deserialize<'de>",
17
            serialize = "A: Ord + crate::serde::Serialize, K: Ord + crate::serde::Serialize",
18
        ),
19
    )
20
)]
21
pub struct CombinedChangeSet<K, A> {
22
    /// Changes to the [`LocalChain`](crate::local_chain::LocalChain).
23
    pub chain: crate::local_chain::ChangeSet,
24
    /// Changes to [`IndexedTxGraph`](crate::indexed_tx_graph::IndexedTxGraph).
25
    pub indexed_tx_graph: crate::indexed_tx_graph::ChangeSet<A, crate::keychain::ChangeSet<K>>,
26
    /// Stores the network type of the transaction data.
27
    pub network: Option<bitcoin::Network>,
28
}
29

30
#[cfg(feature = "miniscript")]
31
impl<K, A> core::default::Default for CombinedChangeSet<K, A> {
32
    fn default() -> Self {
11,283✔
33
        Self {
11,283✔
34
            chain: core::default::Default::default(),
11,283✔
35
            indexed_tx_graph: core::default::Default::default(),
11,283✔
36
            network: None,
11,283✔
37
        }
11,283✔
38
    }
11,283✔
39
}
40

41
#[cfg(feature = "miniscript")]
42
impl<K: Ord, A: crate::Anchor> crate::Append for CombinedChangeSet<K, A> {
43
    fn append(&mut self, other: Self) {
11,161✔
44
        crate::Append::append(&mut self.chain, other.chain);
11,161✔
45
        crate::Append::append(&mut self.indexed_tx_graph, other.indexed_tx_graph);
11,161✔
46
        if other.network.is_some() {
11,161✔
47
            debug_assert!(
3✔
48
                self.network.is_none() || self.network == other.network,
3✔
NEW
49
                "network type must either be just introduced or remain the same"
×
50
            );
51
            self.network = other.network;
3✔
52
        }
11,158✔
53
    }
11,161✔
54

55
    fn is_empty(&self) -> bool {
2,487✔
56
        self.chain.is_empty() && self.indexed_tx_graph.is_empty() && self.network.is_none()
2,487✔
57
    }
2,487✔
58
}
59

60
#[cfg(feature = "miniscript")]
61
impl<K, A> From<crate::local_chain::ChangeSet> for CombinedChangeSet<K, A> {
62
    fn from(chain: crate::local_chain::ChangeSet) -> Self {
2,158✔
63
        Self {
2,158✔
64
            chain,
2,158✔
65
            ..Default::default()
2,158✔
66
        }
2,158✔
67
    }
2,158✔
68
}
69

70
#[cfg(feature = "miniscript")]
71
impl<K, A> From<crate::indexed_tx_graph::ChangeSet<A, crate::keychain::ChangeSet<K>>>
72
    for CombinedChangeSet<K, A>
73
{
74
    fn from(
5,860✔
75
        indexed_tx_graph: crate::indexed_tx_graph::ChangeSet<A, crate::keychain::ChangeSet<K>>,
5,860✔
76
    ) -> Self {
5,860✔
77
        Self {
5,860✔
78
            indexed_tx_graph,
5,860✔
79
            ..Default::default()
5,860✔
80
        }
5,860✔
81
    }
5,860✔
82
}
83

84
#[cfg(feature = "miniscript")]
85
impl<K, A> From<crate::keychain::ChangeSet<K>> for CombinedChangeSet<K, A> {
86
    fn from(indexer: crate::keychain::ChangeSet<K>) -> Self {
720✔
87
        Self {
720✔
88
            indexed_tx_graph: crate::indexed_tx_graph::ChangeSet {
720✔
89
                indexer,
720✔
90
                ..Default::default()
720✔
91
            },
720✔
92
            ..Default::default()
720✔
93
        }
720✔
94
    }
720✔
95
}
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