Skip to content

Commit a147740

Browse files
Merge #675: Use T: AsRef<Path> as param to SqliteDatabase::new
558e37a Use T: AsRef<Path> as param to SqliteDatabase::new (Vladimir Fomene) Pull request description: This PR fixes #674 ### Description Currently SqliteDatabase::new takes a String as path, with this change, it now accepts any type that implements AsRef<Path>. ### Notes to the reviewers ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### New Features: * [ ] I've added tests for the new feature * [ ] I've added docs for the new feature * [x] I've updated `CHANGELOG.md` #### Bugfixes: * [ ] This pull request breaks the existing API * [ ] I've added tests to reproduce the issue which are now passing * [x] I'm linking the issue being fixed by this PR ACKs for top commit: danielabrozzoni: utACK 558e37a Tree-SHA512: c5ff5b60e5904a5b7ef492a1e40296864b6b7506e4c6a187cfab05ef8140d14ddd322d016b4eeb18c5cfca8d4b575370b4f13c6ea7d7374ab0372a3237a5ed94
2 parents 6bae52e + 558e37a commit a147740

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
- Add `descriptor::checksum::get_checksum_bytes` method.
99
- Add `Excess` enum to handle remaining amount after coin selection.
1010
- Move change creation from `Wallet::create_tx` to `CoinSelectionAlgorithm::coin_select`.
11+
- Change the interface of `SqliteDatabase::new` to accept any type that implement AsRef<Path>
1112

1213
## [v0.20.0] - [v0.19.0]
1314

src/database/sqlite.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
99
// You may not use this file except in accordance with one or both of these
1010
// licenses.
11+
use std::path::Path;
12+
use std::path::PathBuf;
1113

1214
use bitcoin::consensus::encode::{deserialize, serialize};
1315
use bitcoin::hash_types::Txid;
@@ -60,17 +62,20 @@ static MIGRATIONS: &[&str] = &[
6062
#[derive(Debug)]
6163
pub struct SqliteDatabase {
6264
/// Path on the local filesystem to store the sqlite file
63-
pub path: String,
65+
pub path: PathBuf,
6466
/// A rusqlite connection object to the sqlite database
6567
pub connection: Connection,
6668
}
6769

6870
impl SqliteDatabase {
6971
/// Instantiate a new SqliteDatabase instance by creating a connection
7072
/// to the database stored at path
71-
pub fn new(path: String) -> Self {
73+
pub fn new<T: AsRef<Path>>(path: T) -> Self {
7274
let connection = get_connection(&path).unwrap();
73-
SqliteDatabase { path, connection }
75+
SqliteDatabase {
76+
path: PathBuf::from(path.as_ref()),
77+
connection,
78+
}
7479
}
7580
fn insert_script_pubkey(
7681
&self,
@@ -908,7 +913,7 @@ impl BatchDatabase for SqliteDatabase {
908913
}
909914
}
910915

911-
pub fn get_connection(path: &str) -> Result<Connection, Error> {
916+
pub fn get_connection<T: AsRef<Path>>(path: &T) -> Result<Connection, Error> {
912917
let connection = Connection::open(path)?;
913918
migrate(&connection)?;
914919
Ok(connection)

0 commit comments

Comments
 (0)