From 3b695ce624db145ce3afe3801bcd6fec5c4bfbd9 Mon Sep 17 00:00:00 2001
From: nymius <155548262+nymius@users.noreply.github.com>
Date: Thu, 19 Dec 2024 16:44:29 -0300
Subject: [PATCH] refactor: swap position of tuple values returned by
Store::load
---
crates/file_store/src/store.rs | 18 +++++++++---------
crates/wallet/README.md | 2 +-
crates/wallet/tests/wallet.rs | 4 ++--
example-crates/example_cli/src/lib.rs | 2 +-
.../example_wallet_electrum/src/main.rs | 2 +-
.../src/main.rs | 2 +-
example-crates/example_wallet_rpc/src/main.rs | 2 +-
7 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/crates/file_store/src/store.rs b/crates/file_store/src/store.rs
index 8b3a3ce03..ded1902f7 100644
--- a/crates/file_store/src/store.rs
+++ b/crates/file_store/src/store.rs
@@ -65,7 +65,7 @@ where
///
/// [`create`]: Store::create
/// [`load`]: Store::load
- pub fn load
(magic: &[u8], file_path: P) -> Result<(Option, Self), StoreErrorWithDump>
+ pub fn load(magic: &[u8], file_path: P) -> Result<(Self, Option), StoreErrorWithDump>
where
P: AsRef,
{
@@ -92,7 +92,7 @@ where
// Get aggregated changeset
let aggregated_changeset = store.dump()?;
- Ok((aggregated_changeset, store))
+ Ok((store, aggregated_changeset))
}
/// Aggregate [`Store`] changesets and return them as a single changeset.
@@ -133,7 +133,7 @@ where
pub fn load_or_create(
magic: &[u8],
file_path: P,
- ) -> Result<(Option, Self), StoreErrorWithDump>
+ ) -> Result<(Self, Option), StoreErrorWithDump>
where
P: AsRef,
{
@@ -141,7 +141,7 @@ where
Self::load(magic, file_path)
} else {
Self::create(magic, file_path)
- .map(|store| (Option::::None, store))
+ .map(|store| (store, Option::::None))
.map_err(|err: StoreError| StoreErrorWithDump {
changeset: Option::::None,
error: err,
@@ -371,7 +371,7 @@ mod test {
let changeset = BTreeSet::from(["hello".to_string(), "world".to_string()]);
{
- let (_, mut store) =
+ let (mut store, _) =
Store::::load_or_create(&TEST_MAGIC_BYTES, &file_path)
.expect("must create");
assert!(file_path.exists());
@@ -379,7 +379,7 @@ mod test {
}
{
- let (recovered_changeset, _) =
+ let (_, recovered_changeset) =
Store::::load_or_create(&TEST_MAGIC_BYTES, &file_path)
.expect("must load");
assert_eq!(recovered_changeset, Some(changeset));
@@ -444,7 +444,7 @@ mod test {
// load file again - this time we should successfully aggregate all changesets
{
- let (aggregated_changeset, _) =
+ let (_, aggregated_changeset) =
Store::::load(&TEST_MAGIC_BYTES, &file_path).unwrap();
assert_eq!(
aggregated_changeset,
@@ -480,7 +480,7 @@ mod test {
{
// open store
- let (_, mut store) = Store::::load(&TEST_MAGIC_BYTES, &file_path)
+ let (mut store, _) = Store::::load(&TEST_MAGIC_BYTES, &file_path)
.expect("failed to load store");
// now append the second changeset
@@ -502,7 +502,7 @@ mod test {
}
// Open the store again to verify file pointer position at the end of the file
- let (_, mut store) = Store::::load(&TEST_MAGIC_BYTES, &file_path)
+ let (mut store, _) = Store::::load(&TEST_MAGIC_BYTES, &file_path)
.expect("should load correctly");
// get the current position of file pointer just after loading store
diff --git a/crates/wallet/README.md b/crates/wallet/README.md
index cb02170fc..793ba8f2e 100644
--- a/crates/wallet/README.md
+++ b/crates/wallet/README.md
@@ -70,7 +70,7 @@ To persist `Wallet` state data use a data store crate that reads and writes [`Ch
use bdk_wallet::{bitcoin::Network, KeychainKind, ChangeSet, Wallet};
// Open or create a new file store for wallet data.
-let (_, mut db) =
+let (mut db, _) =
bdk_file_store::Store::::load_or_create(b"magic_bytes", "/tmp/my_wallet.db")
.expect("create store");
diff --git a/crates/wallet/tests/wallet.rs b/crates/wallet/tests/wallet.rs
index 5f33c5787..e4c9b4c79 100644
--- a/crates/wallet/tests/wallet.rs
+++ b/crates/wallet/tests/wallet.rs
@@ -116,7 +116,7 @@ fn wallet_is_persisted() -> anyhow::Result<()> {
run(
"store.db",
|path| Ok(bdk_file_store::Store::create(DB_MAGIC, path)?),
- |path| Ok(bdk_file_store::Store::load(DB_MAGIC, path)?.1),
+ |path| Ok(bdk_file_store::Store::load(DB_MAGIC, path)?.0),
)?;
run::(
"store.sqlite",
@@ -208,7 +208,7 @@ fn wallet_load_checks() -> anyhow::Result<()> {
run(
"store.db",
|path| Ok(bdk_file_store::Store::::create(DB_MAGIC, path)?),
- |path| Ok(bdk_file_store::Store::load(DB_MAGIC, path)?.1),
+ |path| Ok(bdk_file_store::Store::load(DB_MAGIC, path)?.0),
)?;
run(
"store.sqlite",
diff --git a/example-crates/example_cli/src/lib.rs b/example-crates/example_cli/src/lib.rs
index 5822d085d..e965495e0 100644
--- a/example-crates/example_cli/src/lib.rs
+++ b/example-crates/example_cli/src/lib.rs
@@ -789,7 +789,7 @@ pub fn init_or_load(
Commands::Generate { network } => generate_bip86_helper(network).map(|_| None),
// try load
_ => {
- let (changeset, db) =
+ let (db, changeset) =
Store::::load(db_magic, db_path).context("could not open file store")?;
let changeset = changeset.expect("should not be empty");
diff --git a/example-crates/example_wallet_electrum/src/main.rs b/example-crates/example_wallet_electrum/src/main.rs
index 4acbd04bc..91ef56366 100644
--- a/example-crates/example_wallet_electrum/src/main.rs
+++ b/example-crates/example_wallet_electrum/src/main.rs
@@ -22,7 +22,7 @@ const ELECTRUM_URL: &str = "ssl://electrum.blockstream.info:60002";
fn main() -> Result<(), anyhow::Error> {
let db_path = "bdk-electrum-example.db";
- let (_, mut db) = Store::::load_or_create(DB_MAGIC.as_bytes(), db_path)?;
+ let (mut db, _) = Store::::load_or_create(DB_MAGIC.as_bytes(), db_path)?;
let wallet_opt = Wallet::load()
.descriptor(KeychainKind::External, Some(EXTERNAL_DESC))
diff --git a/example-crates/example_wallet_esplora_blocking/src/main.rs b/example-crates/example_wallet_esplora_blocking/src/main.rs
index 2a508934c..735f2a783 100644
--- a/example-crates/example_wallet_esplora_blocking/src/main.rs
+++ b/example-crates/example_wallet_esplora_blocking/src/main.rs
@@ -19,7 +19,7 @@ const INTERNAL_DESC: &str = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7
const ESPLORA_URL: &str = "http://signet.bitcoindevkit.net";
fn main() -> Result<(), anyhow::Error> {
- let (_, mut db) = Store::::load_or_create(DB_MAGIC.as_bytes(), DB_PATH)?;
+ let (mut db, _) = Store::::load_or_create(DB_MAGIC.as_bytes(), DB_PATH)?;
let wallet_opt = Wallet::load()
.descriptor(KeychainKind::External, Some(EXTERNAL_DESC))
diff --git a/example-crates/example_wallet_rpc/src/main.rs b/example-crates/example_wallet_rpc/src/main.rs
index e3d40e43b..136fd720a 100644
--- a/example-crates/example_wallet_rpc/src/main.rs
+++ b/example-crates/example_wallet_rpc/src/main.rs
@@ -86,7 +86,7 @@ fn main() -> anyhow::Result<()> {
);
let start_load_wallet = Instant::now();
- let (_, mut db) =
+ let (mut db, _) =
Store::::load_or_create(DB_MAGIC.as_bytes(), args.db_path)?;
let wallet_opt = Wallet::load()
.descriptor(KeychainKind::External, Some(args.descriptor.clone()))