Module bdk::database::any

source ·
Expand description

Runtime-checked database types

This module provides the implementation of AnyDatabase which allows switching the inner Database type at runtime.

Example

In this example, wallet_memory and wallet_sled have the same type of Wallet<(), AnyDatabase>.

let memory = MemoryDatabase::default();
let wallet_memory = Wallet::new("...", None, Network::Testnet, memory)?;

let sled = sled::open("my-database")?.open_tree("default_tree")?;
let wallet_sled = Wallet::new("...", None, Network::Testnet, sled)?;

When paired with the use of ConfigurableDatabase, it allows creating wallets with any database supported using a single line of code:

let config = serde_json::from_str("...")?;
let database = AnyDatabase::from_config(&config)?;
let wallet = Wallet::new("...", None, Network::Testnet, database)?;

Structs

Enums