a4f28c079e3bc4500e8329aeed230d8100d38617 chore: improve LocalChain::apply_header_connected_to doc (LLFourn) 8ec65f0b8ef7d452a0bdba6760c46bd8511c91ff feat(example): add RPC wallet example (Vladimir Fomene) a7d01dc39acb3ff7f4bc8e237c7862d019a91cd1 feat(chain)!: make `IndexedTxGraph::apply_block_relevant` more efficient (志宇) e0512acf9476fa3fa7da9cc28a222432f974aad5 feat(bitcoind_rpc)!: emissions include checkpoint and connected_to data (志宇) 8f2d4d9d400e398b54cf1bad36057f3f8f4a69a4 test(chain): `LocalChain` test for update that is shorter than original (志宇) 9467cad55d68354fe037d57bceeee57c2032bd51 feat(wallet): introduce block-by-block api (Vladimir Fomene) d3e5095df10d21ff5cb7f8ce4dab7922f3cb6e35 feat(chain): add `apply_header..` methods to `LocalChain` (志宇) 2b61a122ff40253f2e67c0ae6824ce881c9f12a1 feat(chain): add `CheckPoint::from_block_ids` convenience method (志宇) Pull request description: ### Description Introduce block-by-block API for `bdk::Wallet`. A `wallet_rpc` example is added to demonstrate syncing `bdk::Wallet` with the `bdk_bitcoind_rpc` chain-source crate. The API of `bdk_bitcoind_rpc::Emitter` is changed so the receiver knows how to connect to the block emitted. ### Notes to the reviewers ### Changelog notice Added * `Wallet` methods to apply full blocks (`apply_block` and `apply_block_connected_to`) and a method to apply a batch of unconfirmed transactions (`apply_unconfirmed_txs`). * `CheckPoint::from_block_ids` convenience method. * `LocalChain` methods to apply a block header (`apply_header` and `apply_header_connected_to`). * Test to show that `LocalChain` can apply updates that are shorter than original. This will happen during reorgs if we sync wallet with `bdk_bitcoind_rpc::Emitter`. Fixed * `InsertTxError` now implements `std::error::Error`. #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### New Features: * [x] I've added tests for the new feature * [x] I've added docs for the new feature ACKs for top commit: LLFourn: self-ACK: a4f28c079e3bc4500e8329aeed230d8100d38617 evanlinjin: ACK a4f28c079e3bc4500e8329aeed230d8100d38617 Tree-SHA512: e39fb65b4e69c0a6748d64eab12913dc9cfe5eb8355ab8fb68f60a37c3bb2e1489ddd8f2f138c6470135344f40e3dc671928f65d303fd41fb63f577b30895b60
BDK

A modern, lightweight, descriptor-based wallet library written in Rust!
Project Homepage | Documentation
bdk
The bdk
crate provides the Wallet
type which is a simple, high-level
interface built from the low-level components of bdk_chain
. Wallet
is a good starting point
for many simple applications as well as a good demonstration of how to use the other mechanisms to
construct a wallet. It has two keychains (external and internal) which are defined by
miniscript descriptors and uses them to generate addresses. When you give it
chain data it also uses the descriptors to find transaction outputs owned by them. From there, you
can create and sign transactions.
For more information, see the Wallet
's documentation.
Blockchain data
In order to get blockchain data for Wallet
to consume, you have to put it into particular form.
Right now this is KeychainScan
which is defined in bdk_chain
.
This can be created manually or from blockchain-scanning crates.
Blockchain Data Sources
bdk_esplora
: Grabs blockchain data from Esplora for updating BDK structures.bdk_electrum
: Grabs blockchain data from Electrum for updating BDK structures.
Examples
Persistence
To persist the Wallet
on disk, Wallet
needs to be constructed with a
Persist
implementation.
Implementations
bdk_file_store
: a simple flat-file implementation ofPersist
.
Example
use bdk::{bitcoin::Network, wallet::{AddressIndex, Wallet}};
fn main() {
// a type that implements `Persist`
let db = ();
let descriptor = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/0'/0'/0/*)";
let mut wallet = Wallet::new(descriptor, None, db, Network::Testnet).expect("should create");
// get a new address (this increments revealed derivation index)
println!("revealed address: {}", wallet.get_address(AddressIndex::New));
println!("staged changes: {:?}", wallet.staged());
// persist changes
wallet.commit().expect("must save");
}
Testing
Unit testing
cargo test
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.