Skip to content

Commit b5db35e

Browse files
committed
Make repo into a single crate
1 parent a489e35 commit b5db35e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+188
-432
lines changed

.github/workflows/cont_integration.yml

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
env:
5555
MATRIX_RUST_VERSION: ${{ matrix.rust.version }}
5656
run: |
57-
cargo build --workspace ${{ matrix.features }}
57+
cargo build --workspace --all-targets ${{ matrix.features }}
5858
cargo test --workspace ${{ matrix.features }}
5959
6060
check-no-std:
@@ -73,8 +73,7 @@ jobs:
7373
# target: "thumbv6m-none-eabi"
7474
- name: Rust Cache
7575
uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0
76-
- name: Check bdk wallet
77-
working-directory: ./wallet
76+
- name: Check no-std
7877
# TODO "--target thumbv6m-none-eabi" should work but currently does not
7978
run: cargo check --no-default-features --features miniscript/no-std,bdk_chain/hashbrown
8079

@@ -101,8 +100,7 @@ jobs:
101100
targets: "wasm32-unknown-unknown"
102101
- name: Rust Cache
103102
uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0
104-
- name: Check bdk wallet
105-
working-directory: ./wallet
103+
- name: Check WASM
106104
run: cargo check --target wasm32-unknown-unknown --no-default-features --features miniscript/no-std,bdk_chain/hashbrown
107105

108106
fmt:
@@ -140,21 +138,3 @@ jobs:
140138
- name: Clippy
141139
run: cargo clippy --all-features --all-targets -- -D warnings
142140

143-
build-examples:
144-
needs: prepare
145-
name: Build & Test Examples
146-
runs-on: ubuntu-latest
147-
steps:
148-
- name: checkout
149-
uses: actions/checkout@v4
150-
with:
151-
persist-credentials: false
152-
- name: Install Rust toolchain
153-
uses: dtolnay/rust-toolchain@v1
154-
with:
155-
toolchain: ${{ needs.prepare.outputs.rust_version }}
156-
- name: Rust Cache
157-
uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0
158-
- name: Build + Test Examples
159-
working-directory: examples
160-
run: cargo test --workspace --all-targets --all-features

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Cargo.lock
88
# Example persisted files.
99
*.db
1010
*.sqlite*
11+
examples/test_data
File renamed without changes.

Cargo.toml

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,76 @@
1-
[workspace]
2-
resolver = "2"
3-
members = [
4-
"wallet",
5-
]
6-
exclude = ["examples"]
7-
8-
[workspace.package]
1+
[package]
2+
name = "bdk_wallet"
3+
homepage = "https://bitcoindevkit.org"
4+
version = "3.0.0-alpha.0"
5+
repository = "https://github.com/bitcoindevkit/bdk_wallet"
6+
documentation = "https://docs.rs/bdk_wallet"
7+
description = "A modern, lightweight, descriptor-based wallet library"
8+
keywords = ["bitcoin", "wallet", "descriptor", "psbt"]
9+
readme = "README.md"
10+
license = "MIT OR Apache-2.0"
911
authors = ["Bitcoin Dev Kit Developers"]
12+
edition = "2021"
13+
rust-version = "1.85.0"
1014

11-
[workspace.lints.clippy]
12-
print_stdout = "deny"
13-
print_stderr = "deny"
15+
[package.metadata.docs.rs]
16+
all-features = true
17+
rustdoc-args = ["--cfg", "docsrs"]
18+
19+
[dependencies]
20+
bdk_chain = { version = "0.23.1", features = ["miniscript", "serde"], default-features = false }
21+
bitcoin = { version = "0.32.6", features = ["serde", "base64"], default-features = false }
22+
miniscript = { version = "12.3.1", features = ["serde"], default-features = false }
23+
rand_core = { version = "0.6.0" }
24+
serde_json = { version = "1" }
25+
serde = { version = "1", features = ["derive"] }
26+
27+
# Optional dependencies
28+
anyhow = { version = "1.0.98", optional = true }
29+
bdk_file_store = { version = "0.21.1", optional = true }
30+
bip39 = { version = "2.0", optional = true }
31+
tempfile = { version = "3.20.0", optional = true }
32+
33+
[features]
34+
default = ["std"]
35+
std = ["bitcoin/std", "bitcoin/rand-std", "miniscript/std", "bdk_chain/std"]
36+
compiler = ["miniscript/compiler"]
37+
all-keys = ["keys-bip39"]
38+
keys-bip39 = ["bip39"]
39+
rusqlite = ["bdk_chain/rusqlite"]
40+
file_store = ["bdk_file_store"]
41+
test-utils = ["std", "anyhow", "tempfile"]
42+
43+
[dev-dependencies]
44+
anyhow = "1"
45+
assert_matches = "1.5.0"
46+
bdk_bitcoind_rpc = { version = "0.21.0" }
47+
bdk_electrum = { version = "0.23.1" }
48+
bdk_esplora = { version = "0.22.1", features = ["async-https", "blocking-https", "tokio"] }
49+
bdk_wallet = { path = ".", features = ["rusqlite", "file_store", "test-utils"] }
50+
clap = { version = "4.5.17", features = ["derive", "env"] }
51+
ctrlc = "3.4.6"
52+
rand = "0.8"
53+
tempfile = "3"
54+
tokio = { version = "1.38.1", features = ["rt", "rt-multi-thread", "macros"] }
55+
56+
[[example]]
57+
name = "mnemonic_to_descriptors"
58+
path = "examples/mnemonic_to_descriptors.rs"
59+
required-features = ["all-keys"]
60+
61+
[[example]]
62+
name = "miniscriptc"
63+
path = "examples/compiler.rs"
64+
required-features = ["compiler"]
65+
66+
[[example]]
67+
name = "electrum"
68+
69+
[[example]]
70+
name = "esplora_async"
71+
72+
[[example]]
73+
name = "esplora_blocking"
74+
75+
[[example]]
76+
name = "bitcoind_rpc"

README.md

Lines changed: 103 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
# The Bitcoin Dev Kit Wallet
2-
31
<div align="center">
4-
<h1>BDK Wallet</h1>
2+
<h1>BDK</h1>
53

6-
<img src="./static/bdk.png" width="220" />
4+
<img src="https://raw.githubusercontent.com/bitcoindevkit/bdk/master/static/bdk.png" width="220" />
75

86
<p>
97
<strong>A modern, lightweight, descriptor-based wallet library written in Rust!</strong>
108
</p>
119

1210
<p>
1311
<a href="https://crates.io/crates/bdk_wallet"><img alt="Crate Info" src="https://img.shields.io/crates/v/bdk_wallet.svg"/></a>
14-
<a href="https://github.com/bitcoindevkit/bdk_wallet/blob/master/LICENSE"><img alt="MIT or Apache-2.0 Licensed" src="https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg"/></a>
15-
<a href="https://github.com/bitcoindevkit/bdk_wallet/actions?query=workflow%3ACI"><img alt="CI Status" src="https://github.com/bitcoindevkit/bdk_wallet/workflows/CI/badge.svg"></a>
16-
<a href="https://coveralls.io/github/bitcoindevkit/bdk_wallet?branch=master"><img src="https://coveralls.io/repos/github/bitcoindevkit/bdk_wallet/badge.svg?branch=master"/></a>
17-
<a href="https://docs.rs/bdk_wallet"><img alt="Wallet API Docs" src="https://img.shields.io/badge/docs.rs-bdk_wallet-green"/></a>
12+
<a href="https://github.com/bitcoindevkit/bdk/blob/master/LICENSE"><img alt="MIT or Apache-2.0 Licensed" src="https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg"/></a>
13+
<a href="https://github.com/bitcoindevkit/bdk/actions?query=workflow%3ACI"><img alt="CI Status" src="https://github.com/bitcoindevkit/bdk/workflows/CI/badge.svg"></a>
14+
<a href="https://coveralls.io/github/bitcoindevkit/bdk?branch=master"><img src="https://coveralls.io/repos/github/bitcoindevkit/bdk/badge.svg?branch=master"/></a>
15+
<a href="https://docs.rs/bdk_wallet"><img alt="API Docs" src="https://img.shields.io/badge/docs.rs-bdk_wallet-green"/></a>
1816
<a href="https://blog.rust-lang.org/2025/02/20/Rust-1.85.0/"><img alt="Rustc Version 1.85.0+" src="https://img.shields.io/badge/rustc-1.85.0%2B-lightgrey.svg"/></a>
1917
<a href="https://discord.gg/d7NkDKm"><img alt="Chat on Discord" src="https://img.shields.io/discord/753336465005608961?logo=discord"></a>
2018
</p>
@@ -29,25 +27,88 @@
2927
## About
3028

3129
The `bdk_wallet` project provides a high level descriptor based wallet API for building Bitcoin applications.
32-
It is built upon the excellent [`rust-bitcoin`] and [`rust-miniscript`] crates.
3330

3431
## Architecture
3532

36-
There is currently only one published crate in this repository:
33+
[`bdk_wallet`] contains the central high level [`Wallet`] type that is built from the other low-level components.
3734

38-
- [`wallet`](./wallet): Contains the central high level `Wallet` type that is built from the low-level mechanisms provided by the other components.
35+
Core BDK crates that `bdk_wallet` depends on are found in the [`bdk`] repository. This works by
36+
leveraging the functionality in [`rust-bitcoin`] and [`rust-miniscript`].
3937

40-
Crates that `bdk_wallet` depends on are found in the [`bdk`] repository.
38+
# BDK Wallet
4139

42-
Fully working examples of how to use these components are in `/examples`:
40+
The `bdk_wallet` provides the [`Wallet`] type which is a simple, high-level
41+
interface built from the low-level components of [`bdk_chain`]. `Wallet` is a good starting point
42+
for many simple applications as well as a good demonstration of how to use the other mechanisms to
43+
construct a wallet. It has two keychains (external and internal) that are defined by
44+
[miniscript descriptors][`rust-miniscript`] and uses them to generate addresses. When you give it
45+
chain data it also uses the descriptors to find transaction outputs owned by them. From there, you
46+
can create and sign transactions.
4347

44-
- [`example_wallet_esplora_blocking`](examples/example_wallet_esplora_blocking): Uses the `Wallet` to sync and spend using the Esplora blocking interface.
45-
- [`example_wallet_esplora_async`](examples/example_wallet_esplora_async): Uses the `Wallet` to sync and spend using the Esplora asynchronous interface.
46-
- [`example_wallet_electrum`](examples/example_wallet_electrum): Uses the `Wallet` to sync and spend using Electrum.
48+
For details about the API of `Wallet` see the [module-level documentation][`Wallet`].
4749

48-
[`bdk`]: https://github.com/bitcoindevkit/bdk
49-
[`rust-miniscript`]: https://github.com/rust-bitcoin/rust-miniscript
50-
[`rust-bitcoin`]: https://github.com/rust-bitcoin/rust-bitcoin
50+
## Blockchain data
51+
52+
In order to get blockchain data for `Wallet` to consume, you should configure a client from
53+
an available chain source. Typically you make a request to the chain source and get a response
54+
that the `Wallet` can use to update its view of the chain.
55+
56+
**Blockchain Data Sources**
57+
58+
* [`bdk_esplora`]: Gets blockchain data from Esplora for updating BDK structures.
59+
* [`bdk_electrum`]: Gets blockchain data from Electrum for updating BDK structures.
60+
* [`bdk_bitcoind_rpc`]: Gets blockchain data from Bitcoin Core for updating BDK structures.
61+
62+
**Examples**
63+
64+
* [`examples/esplora_async`](https://github.com/bitcoindevkit/bdk_wallet/tree/master/examples/esplora_async)
65+
* [`examples/esplora_blocking`](https://github.com/bitcoindevkit/bdk_wallet/tree/master/examples/esplora_blocking)
66+
* [`examples/electrum`](https://github.com/bitcoindevkit/bdk_wallet/tree/master/examples/electrum)
67+
* [`examples/bitcoind_rpc`](https://github.com/bitcoindevkit/bdk_wallet/tree/master/examples/bitcoind_rpc)
68+
69+
## Persistence
70+
71+
To persist `Wallet` state use a data storage crate that reads and writes [`ChangeSet`].
72+
73+
**Implementations**
74+
75+
* [`bdk_file_store`]: Stores wallet changes in a simple flat file.
76+
77+
**Example**
78+
79+
```rust,no_run
80+
use bdk_wallet::{bitcoin::Network, KeychainKind, ChangeSet, Wallet};
81+
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");
86+
87+
// Create a wallet with initial wallet data read from the file store.
88+
let network = Network::Testnet;
89+
let descriptor = "wpkh(tprv8ZgxMBicQKsPdcAqYBpzAFwU5yxBUo88ggoBqu1qPcHUfSbKK1sKMLmC7EAk438btHQrSdu3jGGQa6PA71nvH5nkDexhLteJqkM4dQmWF9g/84'/1'/0'/0/*)";
90+
let change_descriptor = "wpkh(tprv8ZgxMBicQKsPdcAqYBpzAFwU5yxBUo88ggoBqu1qPcHUfSbKK1sKMLmC7EAk438btHQrSdu3jGGQa6PA71nvH5nkDexhLteJqkM4dQmWF9g/84'/1'/0'/1/*)";
91+
let wallet_opt = Wallet::load()
92+
.descriptor(KeychainKind::External, Some(descriptor))
93+
.descriptor(KeychainKind::Internal, Some(change_descriptor))
94+
.extract_keys()
95+
.check_network(network)
96+
.load_wallet(&mut db)
97+
.expect("wallet");
98+
let mut wallet = match wallet_opt {
99+
Some(wallet) => wallet,
100+
None => Wallet::create(descriptor, change_descriptor)
101+
.network(network)
102+
.create_wallet(&mut db)
103+
.expect("wallet"),
104+
};
105+
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);
111+
```
51112

52113
## Minimum Supported Rust Version (MSRV)
53114

@@ -61,18 +122,37 @@ This project has a [`justfile`](/justfile) for easy command running. You must ha
61122

62123
To see a list of available recipes: `just -l`
63124

64-
## License
125+
## Testing
126+
127+
### Unit testing
128+
129+
```bash
130+
just test
131+
```
132+
133+
# License
65134

66135
Licensed under either of
67136

68-
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or <https://www.apache.org/licenses/LICENSE-2.0>)
69-
* MIT license ([LICENSE-MIT](LICENSE-MIT) or <https://opensource.org/licenses/MIT>)
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>)
70139

71140
at your option.
72141

73-
### Contribution
142+
# Contribution
74143

75144
Unless you explicitly state otherwise, any contribution intentionally
76145
submitted for inclusion in the work by you, as defined in the Apache-2.0
77146
license, shall be dual licensed as above, without any additional terms or
78147
conditions.
148+
149+
[`Wallet`]: https://docs.rs/bdk_wallet/latest/bdk_wallet/wallet/struct.Wallet.html
150+
[`bdk`]: https://github.com/bitcoindevkit/bdk
151+
[`bdk_wallet`]: https://docs.rs/bdk_wallet/latest
152+
[`bdk_chain`]: https://docs.rs/bdk_chain/latest
153+
[`bdk_file_store`]: https://docs.rs/bdk_file_store/latest
154+
[`bdk_electrum`]: https://docs.rs/bdk_electrum/latest
155+
[`bdk_esplora`]: https://docs.rs/bdk_esplora/latest
156+
[`bdk_bitcoind_rpc`]: https://docs.rs/bdk_bitcoind_rpc/latest
157+
[`rust-bitcoin`]: https://docs.rs/miniscript/latest/bitcoin/index.html
158+
[`rust-miniscript`]: https://docs.rs/miniscript/latest/miniscript/index.html

example-crates/Cargo.toml

Lines changed: 0 additions & 8 deletions
This file was deleted.

example-crates/example_wallet_electrum/Cargo.toml

Lines changed: 0 additions & 9 deletions
This file was deleted.

example-crates/example_wallet_esplora_async/Cargo.toml

Lines changed: 0 additions & 12 deletions
This file was deleted.

example-crates/example_wallet_esplora_blocking/Cargo.toml

Lines changed: 0 additions & 12 deletions
This file was deleted.

example-crates/example_wallet_rpc/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)