Use a thread-safe MemoryDatabase
This commit is contained in:
parent
b6d6a0d092
commit
598d08b3bc
@ -9,10 +9,13 @@ edition = "2018"
|
|||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bdk = { version = "^0.11", features = ["all-keys"] }
|
bdk = { version = "^0.12.1-dev", features = ["all-keys"] }
|
||||||
uniffi_macros = "0.14.0"
|
uniffi_macros = "0.14.0"
|
||||||
uniffi = "0.14.0"
|
uniffi = "0.14.0"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
uniffi_build = "0.14.0"
|
uniffi_build = "0.14.0"
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
bdk = { git = "https://github.com/artfuldev/bdk.git", branch = "use-send-and-sync-on-memory-database" }
|
||||||
|
12
src/lib.rs
12
src/lib.rs
@ -1,28 +1,26 @@
|
|||||||
use bdk::bitcoin::Network;
|
use bdk::bitcoin::Network;
|
||||||
use bdk::sled;
|
use bdk::database::MemoryDatabase;
|
||||||
use bdk::sled::Tree;
|
|
||||||
use bdk::wallet::AddressIndex;
|
use bdk::wallet::AddressIndex;
|
||||||
use bdk::Error;
|
use bdk::Error;
|
||||||
use bdk::Wallet;
|
use bdk::Wallet;
|
||||||
|
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
type BdkError = Error;
|
type BdkError = Error;
|
||||||
|
|
||||||
uniffi_macros::include_scaffolding!("bdk");
|
uniffi_macros::include_scaffolding!("bdk");
|
||||||
|
|
||||||
struct OfflineWallet {
|
struct OfflineWallet {
|
||||||
wallet: Mutex<Wallet<(), Tree>>,
|
wallet: Mutex<Wallet<(), MemoryDatabase>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OfflineWallet {
|
impl OfflineWallet {
|
||||||
fn new(descriptor: String) -> Result<Self, BdkError> {
|
fn new(descriptor: String) -> Result<Self, BdkError> {
|
||||||
let database = sled::open("testdb").unwrap();
|
let database = MemoryDatabase::default();
|
||||||
let tree = database.open_tree("test").unwrap();
|
|
||||||
let wallet = Mutex::new(Wallet::new_offline(
|
let wallet = Mutex::new(Wallet::new_offline(
|
||||||
&descriptor,
|
&descriptor,
|
||||||
None,
|
None,
|
||||||
Network::Regtest,
|
Network::Regtest,
|
||||||
tree,
|
database,
|
||||||
)?);
|
)?);
|
||||||
Ok(OfflineWallet { wallet })
|
Ok(OfflineWallet { wallet })
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user