Skip to content

Commit 2fd7aa1

Browse files
refactor: migrate Connection type to procedural macros
1 parent a421d16 commit 2fd7aa1

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

bdk-ffi/src/bdk.udl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -805,13 +805,7 @@ dictionary Condition {
805805
// bdk_sqlite crate
806806
// ------------------------------------------------------------------------
807807

808-
interface Connection {
809-
[Throws=SqliteError]
810-
constructor(string path);
811-
812-
[Name=new_in_memory, Throws=SqliteError]
813-
constructor();
814-
};
808+
typedef interface Connection;
815809

816810
// ------------------------------------------------------------------------
817811
// bdk crate - descriptor module

bdk-ffi/src/store.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,29 @@ use bdk_wallet::rusqlite::Connection as BdkConnection;
55
use std::sync::Mutex;
66
use std::sync::MutexGuard;
77

8+
/// A connection to a SQLite database.
9+
#[derive(uniffi::Object)]
810
pub struct Connection(Mutex<BdkConnection>);
911

12+
#[uniffi::export]
1013
impl Connection {
14+
/// Open a new connection to a SQLite database. If a database does not exist at the path, one is
15+
/// created.
16+
#[uniffi::constructor]
1117
pub fn new(path: String) -> Result<Self, SqliteError> {
1218
let connection = BdkConnection::open(path)?;
1319
Ok(Self(Mutex::new(connection)))
1420
}
1521

22+
/// Open a new connection to an in-memory SQLite database.
23+
#[uniffi::constructor]
1624
pub fn new_in_memory() -> Result<Self, SqliteError> {
1725
let connection = BdkConnection::open_in_memory()?;
1826
Ok(Self(Mutex::new(connection)))
1927
}
28+
}
2029

30+
impl Connection {
2131
pub(crate) fn get_store(&self) -> MutexGuard<BdkConnection> {
2232
self.0.lock().expect("must lock")
2333
}

0 commit comments

Comments
 (0)