Use a thread-safe MemoryDatabase
This commit is contained in:
parent
a66e8eb8ed
commit
23c17ca841
@ -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,13 +12,13 @@ class LibTest {
|
|||||||
val desc =
|
val desc =
|
||||||
"wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)"
|
"wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)"
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
// fun walletNewAddress() {
|
fun walletNewAddress() {
|
||||||
// val wallet = OfflineWallet(desc)
|
val wallet = OfflineWallet(desc)
|
||||||
// val address = wallet.getNewAddress()
|
val address = wallet.getNewAddress()
|
||||||
// assertNotNull(address)
|
assertNotNull(address)
|
||||||
// assertEquals(address, "bcrt1qzg4mckdh50nwdm9hkzq06528rsu73hjxytqkxs")
|
assertEquals(address, "bcrt1qzg4mckdh50nwdm9hkzq06528rsu73hjxytqkxs")
|
||||||
// }
|
}
|
||||||
|
|
||||||
@Test(expected=BdkException.Descriptor::class)
|
@Test(expected=BdkException.Descriptor::class)
|
||||||
fun invalidDescriptorExceptionIsThrown() {
|
fun invalidDescriptorExceptionIsThrown() {
|
||||||
|
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