Skip to content

Commit c78915a

Browse files
committed
Update README example to use rusqlite
docs: Update links in README
1 parent b5db35e commit c78915a

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

README.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,41 +73,43 @@ To persist `Wallet` state use a data storage crate that reads and writes [`Chang
7373
**Implementations**
7474

7575
* [`bdk_file_store`]: Stores wallet changes in a simple flat file.
76+
* `rusqlite`: Stores wallet changes in a SQLite database.
7677

7778
**Example**
7879

7980
```rust,no_run
80-
use bdk_wallet::{bitcoin::Network, KeychainKind, ChangeSet, Wallet};
81+
use bdk_wallet::rusqlite;
82+
use bdk_wallet::{KeychainKind, Wallet};
8183
82-
// Open or create a new file store for wallet data.
83-
let (mut db, _changeset) =
84-
bdk_file_store::Store::<ChangeSet>::load_or_create(b"magic_bytes", "/tmp/my_wallet.db")
85-
.expect("create store");
84+
// Open or create a new SQLite database for wallet data.
85+
let db_path = "my_wallet.sqlite";
86+
let mut conn = rusqlite::Connection::open(db_path)?;
8687
87-
// Create a wallet with initial wallet data read from the file store.
88-
let network = Network::Testnet;
88+
let network = bitcoin::Network::Testnet;
8989
let descriptor = "wpkh(tprv8ZgxMBicQKsPdcAqYBpzAFwU5yxBUo88ggoBqu1qPcHUfSbKK1sKMLmC7EAk438btHQrSdu3jGGQa6PA71nvH5nkDexhLteJqkM4dQmWF9g/84'/1'/0'/0/*)";
9090
let change_descriptor = "wpkh(tprv8ZgxMBicQKsPdcAqYBpzAFwU5yxBUo88ggoBqu1qPcHUfSbKK1sKMLmC7EAk438btHQrSdu3jGGQa6PA71nvH5nkDexhLteJqkM4dQmWF9g/84'/1'/0'/1/*)";
91-
let wallet_opt = Wallet::load()
91+
92+
let mut wallet = match Wallet::load()
9293
.descriptor(KeychainKind::External, Some(descriptor))
9394
.descriptor(KeychainKind::Internal, Some(change_descriptor))
9495
.extract_keys()
9596
.check_network(network)
96-
.load_wallet(&mut db)
97-
.expect("wallet");
98-
let mut wallet = match wallet_opt {
97+
.load_wallet(&mut conn)?
98+
{
9999
Some(wallet) => wallet,
100100
None => Wallet::create(descriptor, change_descriptor)
101101
.network(network)
102-
.create_wallet(&mut db)
103-
.expect("wallet"),
102+
.create_wallet(&mut conn)?,
104103
};
105104
106-
// Get a new address to receive bitcoin.
107-
let receive_address = wallet.reveal_next_address(KeychainKind::External);
108-
// Persist staged wallet data changes to the file store.
109-
wallet.persist(&mut db).expect("persist");
110-
println!("Your new receive address is: {}", receive_address.address);
105+
// Get a new address to receive bitcoin!
106+
let address_info = wallet.reveal_next_address(KeychainKind::External);
107+
108+
// Persist new wallet state to database.
109+
wallet.persist(&mut conn)?;
110+
111+
println!("Next receive address: {}", address_info.address);
112+
Ok::<_, anyhow::Error>(())
111113
```
112114

113115
## Minimum Supported Rust Version (MSRV)
@@ -134,8 +136,8 @@ just test
134136

135137
Licensed under either of
136138

137-
* Apache License, Version 2.0, ([LICENSE-APACHE](../../LICENSE-APACHE) or <https://www.apache.org/licenses/LICENSE-2.0>)
138-
* MIT license ([LICENSE-MIT](../../LICENSE-MIT) or <https://opensource.org/licenses/MIT>)
139+
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or <https://www.apache.org/licenses/LICENSE-2.0>)
140+
* MIT license ([LICENSE-MIT](LICENSE-MIT) or <https://opensource.org/licenses/MIT>)
139141

140142
at your option.
141143

@@ -146,13 +148,14 @@ submitted for inclusion in the work by you, as defined in the Apache-2.0
146148
license, shall be dual licensed as above, without any additional terms or
147149
conditions.
148150

149-
[`Wallet`]: https://docs.rs/bdk_wallet/latest/bdk_wallet/wallet/struct.Wallet.html
151+
[`Wallet`]: https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.Wallet.html
152+
[`ChangeSet`]: https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.ChangeSet.html
150153
[`bdk`]: https://github.com/bitcoindevkit/bdk
151154
[`bdk_wallet`]: https://docs.rs/bdk_wallet/latest
152155
[`bdk_chain`]: https://docs.rs/bdk_chain/latest
153156
[`bdk_file_store`]: https://docs.rs/bdk_file_store/latest
154157
[`bdk_electrum`]: https://docs.rs/bdk_electrum/latest
155158
[`bdk_esplora`]: https://docs.rs/bdk_esplora/latest
156159
[`bdk_bitcoind_rpc`]: https://docs.rs/bdk_bitcoind_rpc/latest
157-
[`rust-bitcoin`]: https://docs.rs/miniscript/latest/bitcoin/index.html
160+
[`rust-bitcoin`]: https://docs.rs/bitcoin/latest/bitcoin/
158161
[`rust-miniscript`]: https://docs.rs/miniscript/latest/miniscript/index.html

0 commit comments

Comments
 (0)