| Crates.io | redb_wallet_storage |
| lib.rs | redb_wallet_storage |
| version | 0.1.1 |
| created_at | 2025-03-28 03:55:25.316768+00 |
| updated_at | 2025-04-03 08:20:10.769739+00 |
| description | A redb storage backend for Bitcoin Development Kit wallets |
| homepage | |
| repository | https://github.com/pingu-73/redb_wallet_storage |
| max_upload_size | |
| id | 1609170 |
| size | 124,270 |
A redb-based storage backend for Bitcoin Development Kit (BDK) wallets.
redb-wallet-storage provides a storage backend for Bitcoin Development Kit (BDK) Wallets using redb, a pure-Rust embedded key-value store. This implementation offers an alternative to SQLite and file-based storage options.
Add to your Cargo.toml
[dependencies]
redb_wallet_storage = "0.1.0"
or use development version
[dependencies]
redb_wallet_storage = { git = "https://github.com/pingu-73/redb_wallet_storage" }
use bdk_wallet::{CreateParams, LoadParams, PersistedWallet, KeychainKind};
use bitcoin::Network;
use redb_wallet_storage::RedbStore;
// Create or open a wallet store
let mut store = RedbStore::open_or_create("wallet.redb")?;
// Try to load an existing wallet
let mut wallet = match PersistedWallet::load(&mut store, LoadParams::default())? {
Some(wallet) => {
println!("Loaded existing wallet");
wallet
},
None => {
// Create a new wallet if none exists
println!("Creating new wallet");
let descriptor = "wpkh(...)"; // Your descriptor here
let change_descriptor = "wpkh(...)"; // Your change descriptor here
let create_params = CreateParams::new(descriptor, change_descriptor)
.network(Network::Testnet);
PersistedWallet::create(&mut store, create_params)?
}
};
// Generate a new address
let address = wallet.reveal_next_address(KeychainKind::External);
println!("New address: {}", address.address);
// Persist changes to the database
wallet.persist(&mut store)?;
use bdk_wallet::{CreateParams, LoadParams, PersistedWallet, KeychainKind};
use bitcoin::Network;
use redb_wallet_storage::RedbStore;
async fn wallet_example() -> Result<(), Box<dyn std::error::Error>> {
// Create or open a wallet store
let mut store = RedbStore::open_or_create("wallet_async.redb")?;
// Load or create wallet asynchronously
let mut wallet = match PersistedWallet::load_async(&mut store, LoadParams::default()).await? {
Some(wallet) => wallet,
None => {
let descriptor = "wpkh(...)"; // Your descriptor here
let change_descriptor = "wpkh(...)"; // Your change descriptor here
let create_params = CreateParams::new(descriptor, change_descriptor)
.network(Network::Testnet);
PersistedWallet::create_async(&mut store, create_params).await?
}
};
// Generate a new address
let address = wallet.reveal_next_address(KeychainKind::External);
// Persist changes asynchronously
wallet.persist_async(&mut store).await?;
Ok(())
}
See the examples directory
This is a prototype implementation developed as part of a learning project.
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.