@@ -6,7 +6,48 @@ use miniscript::{Descriptor, DescriptorPublicKey};
66type IndexedTxGraphChangeSet =
77 indexed_tx_graph:: ChangeSet < ConfirmationBlockTime , keychain_txout:: ChangeSet > ;
88
9- /// A changeset for [`Wallet`](crate::Wallet).
9+ /// A changeset for [`Wallet`].
10+ ///
11+ /// The changeset is used to persist and recover changes and additions made during the
12+ /// life of the wallet. The kinds of changes that frequently make up this set are new
13+ /// transactions, blocks in the local chain, and derivation indexes. The changeset is
14+ /// also responsible for transmitting persistent metadata such as the public descriptor(s)
15+ /// and configured network. All of these are necessary for the correct functioning of a
16+ /// wallet.
17+ ///
18+ /// For greater efficiency the wallet is able to stage changes before committing them.
19+ /// Many operations result in staged changes which require persistence on the part of the
20+ /// user. These include address revelation, applying an [`Update`], and introducing
21+ /// transactions and related data to the wallet. To get the staged changes see
22+ /// [`Wallet::staged`] and similar methods. Once the changes are committed to the persistence
23+ /// layer the contents of the stage should be discarded.
24+ ///
25+ /// You should persist early and often generally speaking, however in principle there is
26+ /// no limitation on the number or type of changes that can be staged prior to persistence
27+ /// or the order in which they're staged. This is because changesets are designed to be
28+ /// [merged]. The change that is eventually persisted will include the combined effect of
29+ /// each change individually.
30+ ///
31+ /// The [`ChangeSet`] is backwards compatible in the sense that it is intended to interoperate
32+ /// with earlier versions of the library. Specifically this means that the orginal fields will
33+ /// remain unchanged and that the addition of new fields corresponds to new feature upgrades.
34+ ///
35+ /// The API of [`Wallet`] is designed to give the user control of what data to persist, when
36+ /// to persist it, and to determine when committed changes can be safely discarded. You should
37+ /// consider how your database handles partial or repeat writes, whether the persistence
38+ /// operation proceeds atomically, and whether the order of writes matters among the fields
39+ /// of the [`ChangeSet`]. BDK has no strict requirements regarding these details but
40+ /// provides a straightforward solution in the case of [SQLite]. If implementing your own
41+ /// persistence layer, please see the docs for [`PersistedWallet`] and [`WalletPersister`]
42+ /// as a reference.
43+ ///
44+ /// [merged]: bdk_chain::Merge
45+ /// [`PersistedWallet`]: crate::PersistedWallet
46+ /// [SQLite]: bdk_chain::rusqlite_impl
47+ /// [`Update`]: crate::Update
48+ /// [`WalletPersister`]: crate::WalletPersister
49+ /// [`Wallet::staged`]: crate::Wallet::staged
50+ /// [`Wallet`]: crate::Wallet
1051#[ derive( Default , Debug , Clone , PartialEq , serde:: Deserialize , serde:: Serialize ) ]
1152pub struct ChangeSet {
1253 /// Descriptor for recipient addresses.
0 commit comments