Skip to content

Commit 3b695ce

Browse files
committed
refactor: swap position of tuple values returned by Store::load
1 parent 91b5cdb commit 3b695ce

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

crates/file_store/src/store.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ where
6565
///
6666
/// [`create`]: Store::create
6767
/// [`load`]: Store::load
68-
pub fn load<P>(magic: &[u8], file_path: P) -> Result<(Option<C>, Self), StoreErrorWithDump<C>>
68+
pub fn load<P>(magic: &[u8], file_path: P) -> Result<(Self, Option<C>), StoreErrorWithDump<C>>
6969
where
7070
P: AsRef<Path>,
7171
{
@@ -92,7 +92,7 @@ where
9292
// Get aggregated changeset
9393
let aggregated_changeset = store.dump()?;
9494

95-
Ok((aggregated_changeset, store))
95+
Ok((store, aggregated_changeset))
9696
}
9797

9898
/// Aggregate [`Store`] changesets and return them as a single changeset.
@@ -133,15 +133,15 @@ where
133133
pub fn load_or_create<P>(
134134
magic: &[u8],
135135
file_path: P,
136-
) -> Result<(Option<C>, Self), StoreErrorWithDump<C>>
136+
) -> Result<(Self, Option<C>), StoreErrorWithDump<C>>
137137
where
138138
P: AsRef<Path>,
139139
{
140140
if file_path.as_ref().exists() {
141141
Self::load(magic, file_path)
142142
} else {
143143
Self::create(magic, file_path)
144-
.map(|store| (Option::<C>::None, store))
144+
.map(|store| (store, Option::<C>::None))
145145
.map_err(|err: StoreError| StoreErrorWithDump {
146146
changeset: Option::<C>::None,
147147
error: err,
@@ -371,15 +371,15 @@ mod test {
371371
let changeset = BTreeSet::from(["hello".to_string(), "world".to_string()]);
372372

373373
{
374-
let (_, mut store) =
374+
let (mut store, _) =
375375
Store::<TestChangeSet>::load_or_create(&TEST_MAGIC_BYTES, &file_path)
376376
.expect("must create");
377377
assert!(file_path.exists());
378378
store.append(&changeset).expect("must succeed");
379379
}
380380

381381
{
382-
let (recovered_changeset, _) =
382+
let (_, recovered_changeset) =
383383
Store::<TestChangeSet>::load_or_create(&TEST_MAGIC_BYTES, &file_path)
384384
.expect("must load");
385385
assert_eq!(recovered_changeset, Some(changeset));
@@ -444,7 +444,7 @@ mod test {
444444

445445
// load file again - this time we should successfully aggregate all changesets
446446
{
447-
let (aggregated_changeset, _) =
447+
let (_, aggregated_changeset) =
448448
Store::<TestChangeSet>::load(&TEST_MAGIC_BYTES, &file_path).unwrap();
449449
assert_eq!(
450450
aggregated_changeset,
@@ -480,7 +480,7 @@ mod test {
480480

481481
{
482482
// open store
483-
let (_, mut store) = Store::<TestChangeSet>::load(&TEST_MAGIC_BYTES, &file_path)
483+
let (mut store, _) = Store::<TestChangeSet>::load(&TEST_MAGIC_BYTES, &file_path)
484484
.expect("failed to load store");
485485

486486
// now append the second changeset
@@ -502,7 +502,7 @@ mod test {
502502
}
503503

504504
// Open the store again to verify file pointer position at the end of the file
505-
let (_, mut store) = Store::<TestChangeSet>::load(&TEST_MAGIC_BYTES, &file_path)
505+
let (mut store, _) = Store::<TestChangeSet>::load(&TEST_MAGIC_BYTES, &file_path)
506506
.expect("should load correctly");
507507

508508
// get the current position of file pointer just after loading store

crates/wallet/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ 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) =
73+
let (mut db, _) =
7474
bdk_file_store::Store::<ChangeSet>::load_or_create(b"magic_bytes", "/tmp/my_wallet.db")
7575
.expect("create store");
7676

crates/wallet/tests/wallet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn wallet_is_persisted() -> anyhow::Result<()> {
116116
run(
117117
"store.db",
118118
|path| Ok(bdk_file_store::Store::create(DB_MAGIC, path)?),
119-
|path| Ok(bdk_file_store::Store::load(DB_MAGIC, path)?.1),
119+
|path| Ok(bdk_file_store::Store::load(DB_MAGIC, path)?.0),
120120
)?;
121121
run::<bdk_chain::rusqlite::Connection, _, _>(
122122
"store.sqlite",
@@ -208,7 +208,7 @@ fn wallet_load_checks() -> anyhow::Result<()> {
208208
run(
209209
"store.db",
210210
|path| Ok(bdk_file_store::Store::<ChangeSet>::create(DB_MAGIC, path)?),
211-
|path| Ok(bdk_file_store::Store::load(DB_MAGIC, path)?.1),
211+
|path| Ok(bdk_file_store::Store::load(DB_MAGIC, path)?.0),
212212
)?;
213213
run(
214214
"store.sqlite",

example-crates/example_cli/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ pub fn init_or_load<CS: clap::Subcommand, S: clap::Args>(
789789
Commands::Generate { network } => generate_bip86_helper(network).map(|_| None),
790790
// try load
791791
_ => {
792-
let (changeset, db) =
792+
let (db, changeset) =
793793
Store::<ChangeSet>::load(db_magic, db_path).context("could not open file store")?;
794794

795795
let changeset = changeset.expect("should not be empty");

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>::load_or_create(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>::load_or_create(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))

example-crates/example_wallet_rpc/src/main.rs

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

8888
let start_load_wallet = Instant::now();
89-
let (_, mut db) =
89+
let (mut db, _) =
9090
Store::<bdk_wallet::ChangeSet>::load_or_create(DB_MAGIC.as_bytes(), args.db_path)?;
9191
let wallet_opt = Wallet::load()
9292
.descriptor(KeychainKind::External, Some(args.descriptor.clone()))

0 commit comments

Comments
 (0)