From a0bf45bef1b53f8aec273f7fe89915f3d41974c0 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Fri, 14 Jun 2024 18:09:55 -0500 Subject: [PATCH] docs: remove PersistBackend from docs, Cargo.toml and wallet README.md --- crates/chain/src/changeset.rs | 6 ------ crates/file_store/Cargo.toml | 2 +- crates/sqlite/Cargo.toml | 2 +- crates/sqlite/README.md | 4 ++-- crates/wallet/README.md | 36 ++++++++++++++++++++++------------- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/crates/chain/src/changeset.rs b/crates/chain/src/changeset.rs index 2612884b..d8422840 100644 --- a/crates/chain/src/changeset.rs +++ b/crates/chain/src/changeset.rs @@ -1,9 +1,3 @@ -//! This module is home to the [`PersistBackend`] trait which defines the behavior of a data store -//! required to persist changes made to BDK data structures. -//! -//! The [`CombinedChangeSet`] type encapsulates a combination of [`crate`] structures that are -//! typically persisted together. - /// A changeset containing [`crate`] structures typically persisted together. #[cfg(feature = "miniscript")] #[derive(Debug, Clone, PartialEq)] diff --git a/crates/file_store/Cargo.toml b/crates/file_store/Cargo.toml index 392424cb..a0df36cb 100644 --- a/crates/file_store/Cargo.toml +++ b/crates/file_store/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" license = "MIT OR Apache-2.0" repository = "https://github.com/bitcoindevkit/bdk" documentation = "https://docs.rs/bdk_file_store" -description = "A simple append-only flat file implementation of PersistBackend for Bitcoin Dev Kit." +description = "A simple append-only flat file database for persisting bdk_chain data." keywords = ["bitcoin", "persist", "persistence", "bdk", "file"] authors = ["Bitcoin Dev Kit Developers"] readme = "README.md" diff --git a/crates/sqlite/Cargo.toml b/crates/sqlite/Cargo.toml index 238c818f..8dff341a 100644 --- a/crates/sqlite/Cargo.toml +++ b/crates/sqlite/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" license = "MIT OR Apache-2.0" repository = "https://github.com/bitcoindevkit/bdk" documentation = "https://docs.rs/bdk_sqlite" -description = "A simple SQLite based implementation of PersistBackend for Bitcoin Dev Kit." +description = "A simple SQLite relational database client for persisting bdk_chain data." keywords = ["bitcoin", "persist", "persistence", "bdk", "sqlite"] authors = ["Bitcoin Dev Kit Developers"] readme = "README.md" diff --git a/crates/sqlite/README.md b/crates/sqlite/README.md index 26f4650b..ba612bde 100644 --- a/crates/sqlite/README.md +++ b/crates/sqlite/README.md @@ -1,8 +1,8 @@ # BDK SQLite -This is a simple [SQLite] relational database schema backed implementation of `PersistBackend`. +This is a simple [SQLite] relational database client for persisting [`bdk_chain`] changesets. The main structure is `Store` which persists `CombinedChangeSet` data into a SQLite database file. - +[`bdk_chain`]:https://docs.rs/bdk_chain/latest/bdk_chain/ [SQLite]: https://www.sqlite.org/index.html diff --git a/crates/wallet/README.md b/crates/wallet/README.md index 9aba4782..ffe99474 100644 --- a/crates/wallet/README.md +++ b/crates/wallet/README.md @@ -57,31 +57,42 @@ that the `Wallet` can use to update its view of the chain. ## Persistence -To persist `Wallet` state data on disk use an implementation of the [`PersistBackend`] trait. +To persist `Wallet` state data use a data store crate that reads and writes [`bdk_chain::CombinedChangeSet`]. **Implementations** -* [`bdk_file_store`]: A simple flat-file implementation of [`PersistBackend`]. -* [`bdk_sqlite`]: A simple sqlite implementation of [`PersistBackend`]. +* [`bdk_file_store`]: Stores wallet changes in a simple flat file. +* [`bdk_sqlite`]: Stores wallet changes in a SQLite relational database file. **Example** -```rust,compile_fail -use bdk_wallet::{bitcoin::Network, wallet::{ChangeSet, Wallet}}; +```rust,no_run +use bdk_wallet::{bitcoin::Network, KeychainKind, wallet::{ChangeSet, Wallet}}; fn main() { - // Create a new file `Store`. - let mut db = bdk_file_store::Store::::open_or_create_new(b"magic_bytes", "path/to/my_wallet.db").expect("create store"); + // Open or create a new file store for wallet data. + let mut db = + bdk_file_store::Store::::open_or_create_new(b"magic_bytes", "/tmp/my_wallet.db") + .expect("create store"); + // Create a wallet with initial wallet data read from the file store. let descriptor = "wpkh(tprv8ZgxMBicQKsPdcAqYBpzAFwU5yxBUo88ggoBqu1qPcHUfSbKK1sKMLmC7EAk438btHQrSdu3jGGQa6PA71nvH5nkDexhLteJqkM4dQmWF9g/84'/1'/0'/0/*)"; let change_descriptor = "wpkh(tprv8ZgxMBicQKsPdcAqYBpzAFwU5yxBUo88ggoBqu1qPcHUfSbKK1sKMLmC7EAk438btHQrSdu3jGGQa6PA71nvH5nkDexhLteJqkM4dQmWF9g/84'/1'/0'/1/*)"; - let changeset = db.load_changes().expect("changeset loaded"); - let mut wallet = Wallet::new_or_load(descriptor, change_descriptor, changeset, Network::Testnet).expect("create or load wallet"); + let changeset = db.aggregate_changesets().expect("changeset loaded"); + let mut wallet = + Wallet::new_or_load(descriptor, change_descriptor, changeset, Network::Testnet) + .expect("create or load wallet"); - // Insert a single `TxOut` at `OutPoint` into the wallet. - let _ = wallet.insert_txout(outpoint, txout); - wallet.commit_to(&mut db).expect("must commit changes to database"); + // Get a new address to receive bitcoin. + let receive_address = wallet.reveal_next_address(KeychainKind::External); + // Persist staged wallet data changes to the file store. + let staged_changeset = wallet.take_staged(); + if let Some(changeset) = staged_changeset { + db.append_changeset(&changeset) + .expect("must commit changes to database"); + } + println!("Your new receive address is: {}", receive_address.address); } ``` @@ -222,7 +233,6 @@ license, shall be dual licensed as above, without any additional terms or conditions. [`Wallet`]: https://docs.rs/bdk_wallet/latest/bdk_wallet/wallet/struct.Wallet.html -[`PersistBackend`]: https://docs.rs/bdk_chain/latest/bdk_chain/persist/trait.PersistBackend.html [`bdk_chain`]: https://docs.rs/bdk_chain/latest [`bdk_file_store`]: https://docs.rs/bdk_file_store/latest [`bdk_sqlite`]: https://docs.rs/bdk_sqlite/latest