Skip to content

Commit 83e6229

Browse files
committed
refactor: update all call names to bdk_file_store::Store methods
1 parent a3c3c42 commit 83e6229

11 files changed

Lines changed: 37 additions & 34 deletions

File tree

crates/file_store/src/store.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,17 @@ mod test {
379379
let changeset = BTreeSet::from(["hello".to_string(), "world".to_string()]);
380380

381381
{
382-
let (_, mut store) = Store::<TestChangeSet>::load_or_create(&TEST_MAGIC_BYTES, &file_path)
383-
.expect("must create");
382+
let (_, mut store) =
383+
Store::<TestChangeSet>::load_or_create(&TEST_MAGIC_BYTES, &file_path)
384+
.expect("must create");
384385
assert!(file_path.exists());
385386
store.append(&changeset).expect("must succeed");
386387
}
387388

388389
{
389-
let (recovered_changeset, _) = Store::<TestChangeSet>::load_or_create(&TEST_MAGIC_BYTES, &file_path)
390-
.expect("must load");
390+
let (recovered_changeset, _) =
391+
Store::<TestChangeSet>::load_or_create(&TEST_MAGIC_BYTES, &file_path)
392+
.expect("must load");
391393
assert_eq!(recovered_changeset, Some(changeset));
392394
}
393395
}

crates/wallet/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ To persist `Wallet` state data use a data store crate that reads and writes [`Ch
7070
use bdk_wallet::{bitcoin::Network, KeychainKind, ChangeSet, Wallet};
7171
7272
// Open or create a new file store for wallet data.
73-
let mut db =
74-
bdk_file_store::Store::<ChangeSet>::open_or_create_new(b"magic_bytes", "/tmp/my_wallet.db")
73+
let (_, mut db) =
74+
bdk_file_store::Store::<ChangeSet>::load_or_create(b"magic_bytes", "/tmp/my_wallet.db")
7575
.expect("create store");
7676
7777
// Create a wallet with initial wallet data read from the file store.

crates/wallet/src/wallet/persisted.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl WalletPersister for bdk_chain::rusqlite::Connection {
291291
#[derive(Debug)]
292292
pub enum FileStoreError {
293293
/// Error when loading from the store.
294-
Load(bdk_file_store::AggregateChangesetsError<ChangeSet>),
294+
Load(bdk_file_store::StoreErrorWithDump<ChangeSet>),
295295
/// Error when writing to the store.
296296
Write(std::io::Error),
297297
}
@@ -316,15 +316,13 @@ impl WalletPersister for bdk_file_store::Store<ChangeSet> {
316316

317317
fn initialize(persister: &mut Self) -> Result<ChangeSet, Self::Error> {
318318
persister
319-
.aggregate_changesets()
319+
.dump()
320320
.map(Option::unwrap_or_default)
321321
.map_err(FileStoreError::Load)
322322
}
323323

324324
fn persist(persister: &mut Self, changeset: &ChangeSet) -> Result<(), Self::Error> {
325-
persister
326-
.append_changeset(changeset)
327-
.map_err(FileStoreError::Write)
325+
persister.append(changeset).map_err(FileStoreError::Write)
328326
}
329327
}
330328

crates/wallet/tests/wallet.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,11 @@ fn wallet_is_persisted() -> anyhow::Result<()> {
116116

117117
run(
118118
"store.db",
119-
|path| Ok(bdk_file_store::Store::create_new(DB_MAGIC, path)?),
120-
|path| Ok(bdk_file_store::Store::open(DB_MAGIC, path)?),
119+
|path| Ok(bdk_file_store::Store::create(DB_MAGIC, path)?),
120+
|path| {
121+
let (_, store) = bdk_file_store::Store::load(DB_MAGIC, path)?;
122+
Ok(store)
123+
},
121124
)?;
122125
run::<bdk_chain::rusqlite::Connection, _, _>(
123126
"store.sqlite",
@@ -208,12 +211,11 @@ fn wallet_load_checks() -> anyhow::Result<()> {
208211

209212
run(
210213
"store.db",
214+
|path| Ok(bdk_file_store::Store::<ChangeSet>::create(DB_MAGIC, path)?),
211215
|path| {
212-
Ok(bdk_file_store::Store::<ChangeSet>::create_new(
213-
DB_MAGIC, path,
214-
)?)
216+
let (_, store) = bdk_file_store::Store::<ChangeSet>::load(DB_MAGIC, path)?;
217+
Ok(store)
215218
},
216-
|path| Ok(bdk_file_store::Store::<ChangeSet>::open(DB_MAGIC, path)?),
217219
)?;
218220
run(
219221
"store.sqlite",

example-crates/example_bitcoind_rpc_polling/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn main() -> anyhow::Result<()> {
169169
let db = &mut *db.lock().unwrap();
170170
last_db_commit = Instant::now();
171171
if let Some(changeset) = db_stage.take() {
172-
db.append_changeset(&changeset)?;
172+
db.append(&changeset)?;
173173
}
174174
println!(
175175
"[{:>10}s] committed to db (took {}s)",
@@ -213,7 +213,7 @@ fn main() -> anyhow::Result<()> {
213213
..Default::default()
214214
});
215215
if let Some(changeset) = db_stage.take() {
216-
db.append_changeset(&changeset)?;
216+
db.append(&changeset)?;
217217
}
218218
}
219219
}
@@ -307,7 +307,7 @@ fn main() -> anyhow::Result<()> {
307307
let db = &mut *db.lock().unwrap();
308308
last_db_commit = Instant::now();
309309
if let Some(changeset) = db_stage.take() {
310-
db.append_changeset(&changeset)?;
310+
db.append(&changeset)?;
311311
}
312312
println!(
313313
"[{:>10}s] committed to db (took {}s)",

example-crates/example_cli/src/lib.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ pub fn handle_commands<CS: clap::Subcommand, S: clap::Args>(
470470
let ((spk_i, spk), index_changeset) =
471471
spk_chooser(index, Keychain::External).expect("Must exist");
472472
let db = &mut *db.lock().unwrap();
473-
db.append_changeset(&ChangeSet {
473+
db.append(&ChangeSet {
474474
indexer: index_changeset,
475475
..Default::default()
476476
})?;
@@ -641,7 +641,7 @@ pub fn handle_commands<CS: clap::Subcommand, S: clap::Args>(
641641
// If we're unable to persist this, then we don't want to broadcast.
642642
{
643643
let db = &mut *db.lock().unwrap();
644-
db.append_changeset(&ChangeSet {
644+
db.append(&ChangeSet {
645645
indexer,
646646
..Default::default()
647647
})?;
@@ -731,7 +731,7 @@ pub fn handle_commands<CS: clap::Subcommand, S: clap::Args>(
731731
// We know the tx is at least unconfirmed now. Note if persisting here fails,
732732
// it's not a big deal since we can always find it again from the
733733
// blockchain.
734-
db.lock().unwrap().append_changeset(&ChangeSet {
734+
db.lock().unwrap().append(&ChangeSet {
735735
tx_graph: changeset.tx_graph,
736736
indexer: changeset.indexer,
737737
..Default::default()
@@ -801,9 +801,10 @@ pub fn init_or_load<CS: clap::Subcommand, S: clap::Args>(
801801
Commands::Generate { network } => generate_bip86_helper(network).map(|_| None),
802802
// try load
803803
_ => {
804-
let mut db =
805-
Store::<ChangeSet>::open(db_magic, db_path).context("could not open file store")?;
806-
let changeset = db.aggregate_changesets()?.expect("db must not be empty");
804+
let (changeset, db) =
805+
Store::<ChangeSet>::load(db_magic, db_path).context("could not open file store")?;
806+
807+
let changeset = changeset.expect("should not be empty");
807808

808809
let network = changeset.network.expect("changeset network");
809810

@@ -878,8 +879,8 @@ where
878879
LocalChain::from_genesis_hash(constants::genesis_block(network).block_hash());
879880
changeset.network = Some(network);
880881
changeset.local_chain = chain_changeset;
881-
let mut db = Store::<ChangeSet>::create_new(db_magic, db_path)?;
882-
db.append_changeset(&changeset)?;
882+
let mut db = Store::<ChangeSet>::create(db_magic, db_path)?;
883+
db.append(&changeset)?;
883884
println!("New database {db_path}");
884885
}
885886

example-crates/example_electrum/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,6 @@ fn main() -> anyhow::Result<()> {
278278
};
279279

280280
let mut db = db.lock().unwrap();
281-
db.append_changeset(&db_changeset)?;
281+
db.append(&db_changeset)?;
282282
Ok(())
283283
}

example-crates/example_esplora/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ fn main() -> anyhow::Result<()> {
278278

279279
// We persist the changes
280280
let mut db = db.lock().unwrap();
281-
db.append_changeset(&ChangeSet {
281+
db.append(&ChangeSet {
282282
local_chain: local_chain_changeset,
283283
tx_graph: indexed_tx_graph_changeset.tx_graph,
284284
indexer: indexed_tx_graph_changeset.indexer,

example-crates/example_wallet_electrum/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const ELECTRUM_URL: &str = "ssl://electrum.blockstream.info:60002";
2222
fn main() -> Result<(), anyhow::Error> {
2323
let db_path = "bdk-electrum-example.db";
2424

25-
let mut db = Store::<bdk_wallet::ChangeSet>::open_or_create_new(DB_MAGIC.as_bytes(), db_path)?;
25+
let (_, mut db) = Store::<bdk_wallet::ChangeSet>::load_or_create(DB_MAGIC.as_bytes(), db_path)?;
2626

2727
let wallet_opt = Wallet::load()
2828
.descriptor(KeychainKind::External, Some(EXTERNAL_DESC))

example-crates/example_wallet_esplora_blocking/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const INTERNAL_DESC: &str = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7
1919
const ESPLORA_URL: &str = "http://signet.bitcoindevkit.net";
2020

2121
fn main() -> Result<(), anyhow::Error> {
22-
let mut db = Store::<bdk_wallet::ChangeSet>::open_or_create_new(DB_MAGIC.as_bytes(), DB_PATH)?;
22+
let (_, mut db) = Store::<bdk_wallet::ChangeSet>::load_or_create(DB_MAGIC.as_bytes(), DB_PATH)?;
2323

2424
let wallet_opt = Wallet::load()
2525
.descriptor(KeychainKind::External, Some(EXTERNAL_DESC))

0 commit comments

Comments
 (0)