Skip to content

Commit 81c8bdb

Browse files
temp 2
1 parent 53869e2 commit 81c8bdb

File tree

9 files changed

+198
-127
lines changed

9 files changed

+198
-127
lines changed

bdk-ffi/Cargo.lock

Lines changed: 7 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bdk-ffi/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ path = "uniffi-bindgen.rs"
1818
default = ["uniffi/cli"]
1919

2020
[dependencies]
21-
bdk_wallet = { version = "1.0.0-beta.1", features = ["all-keys", "keys-bip39", "rusqlite"] }
22-
bdk_esplora = { version = "0.16.0", default-features = false, features = ["std", "blocking", "blocking-https-rustls"] }
21+
# bdk_wallet = { version = "1.0.0-beta.1", features = ["all-keys", "keys-bip39", "rusqlite"] }
22+
# bdk_esplora = { git = "https://github.com/bitcoindevkit/bdk/", package = "bdk_esplora", version = "0.16.0", default-features = false, features = ["std", "blocking", "blocking-https-rustls"] }
23+
# bdk_electrum = { version = "0.15.0" }
24+
25+
bdk_wallet = { git = "https://github.com/thunderbiscuit/bdk/", branch = "feature/electrum-client-ring", features = ["all-keys", "keys-bip39", "rusqlite"] }
26+
bdk_esplora = { git = "https://github.com/thunderbiscuit/bdk/", package = "bdk_esplora", branch = "feature/electrum-client-ring", default-features = false, features = ["std", "blocking", "blocking-https-rustls"] }
2327
# NOTE: This is a temporary workaround to use the electrum-client with the use-rustls-ring feature. It points to a fork
2428
# of bdk in which the bdk_electrum library uses the electrum-client with the use-rustls-ring feature.
2529
bdk_electrum = { git = "https://github.com/thunderbiscuit/bdk/", package = "bdk_electrum", branch = "feature/electrum-client-ring", default-features = false, features = ["use-rustls-ring"] }
26-
# bdk_electrum = { version = "0.15.0" }
2730
bdk_bitcoind_rpc = { version = "0.13.0" }
2831
bitcoin-internals = { version = "0.2.0", features = ["alloc"] }
2932

bdk-ffi/src/bdk.udl

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ namespace bdk {};
44
// bdk crate - error module
55
// ------------------------------------------------------------------------
66

7+
[Error]
8+
interface FfiGenericError {
9+
GenericError();
10+
};
11+
712
[Error]
813
interface AddressParseError {
914
Base58();
@@ -242,11 +247,11 @@ interface SignerError {
242247
TxInputsIndexError(string error_message);
243248
MiniscriptPsbt(string error_message);
244249
External(string error_message);
250+
Psbt(string error_message);
245251
};
246252

247253
[Error]
248254
interface SqliteError {
249-
InvalidNetwork(Network expected, Network given);
250255
Sqlite(string rusqlite_error);
251256
};
252257

@@ -266,13 +271,13 @@ interface TxidParseError {
266271
InvalidTxid(string txid);
267272
};
268273

269-
[Error]
270-
interface WalletCreationError {
271-
Descriptor(string error_message);
272-
LoadedGenesisDoesNotMatch(string expected, string got);
273-
LoadedNetworkDoesNotMatch(Network expected, Network? got);
274-
LoadedDescriptorDoesNotMatch(string got, KeychainKind keychain);
275-
};
274+
// [Error]
275+
// interface WalletCreationError {
276+
// Descriptor(string error_message);
277+
// LoadedGenesisDoesNotMatch(string expected, string got);
278+
// LoadedNetworkDoesNotMatch(Network expected, Network? got);
279+
// LoadedDescriptorDoesNotMatch(string got, KeychainKind keychain);
280+
// };
276281

277282
// ------------------------------------------------------------------------
278283
// bdk_wallet crate - types module
@@ -317,10 +322,20 @@ dictionary TxOut {
317322

318323
[Enum]
319324
interface ChainPosition {
320-
Confirmed(u32 height, u64 timestamp);
325+
Confirmed(ConfirmationBlockTime confirmation_block_time);
321326
Unconfirmed(u64 timestamp);
322327
};
323328

329+
dictionary ConfirmationBlockTime {
330+
BlockId block_id;
331+
u64 confirmation_time;
332+
};
333+
334+
dictionary BlockId {
335+
u32 height;
336+
string hash;
337+
};
338+
324339
dictionary CanonicalTx {
325340
Transaction transaction;
326341
ChainPosition chain_position;
@@ -359,11 +374,11 @@ enum ChangeSpendPolicy {
359374
};
360375

361376
interface Wallet {
362-
[Throws=WalletCreationError]
377+
[Name=create, Throws=FfiGenericError]
363378
constructor(Descriptor descriptor, Descriptor change_descriptor, Network network, Connection connection);
364379

365-
[Name=load, Throws=WalletCreationError]
366-
constructor(Descriptor descriptor, Descriptor change_descriptor, Network network, Connection connection);
380+
// [Name=load, Throws=FfiGenericError]
381+
// constructor(Descriptor descriptor, Descriptor change_descriptor, Network network, Connection connection);
367382

368383
AddressInfo reveal_next_address(KeychainKind keychain);
369384

@@ -374,7 +389,7 @@ interface Wallet {
374389
[Throws=CannotConnectError]
375390
void apply_update(Update update);
376391

377-
boolean is_mine([ByRef] Script script);
392+
boolean is_mine(Script script);
378393

379394
[Throws=SignerError]
380395
boolean sign(Psbt psbt);
@@ -400,8 +415,7 @@ interface Wallet {
400415

401416
SyncRequest start_sync_with_revealed_spks();
402417

403-
[Throws=PersistenceError]
404-
void persist(Connection connection);
418+
boolean persist(Connection connection);
405419
};
406420

407421
interface Update {};
@@ -459,7 +473,7 @@ interface BumpFeeTxBuilder {
459473
// ------------------------------------------------------------------------
460474

461475
interface Connection {
462-
[Throws=SqliteError]
476+
[Throws=FfiGenericError]
463477
constructor(string path);
464478
};
465479

bdk-ffi/src/electrum.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ use crate::error::ElectrumError;
33
use crate::types::{FullScanRequest, SyncRequest};
44
use crate::wallet::Update;
55

6-
use bdk_electrum::bdk_chain::spk_client::{FullScanResult, SyncResult};
6+
use bdk_electrum::bdk_chain::spk_client::SyncResult;
77
use bdk_electrum::BdkElectrumClient as BdkBdkElectrumClient;
88
use bdk_wallet::bitcoin::Transaction as BdkTransaction;
99
use bdk_wallet::chain::spk_client::FullScanRequest as BdkFullScanRequest;
1010
use bdk_wallet::chain::spk_client::FullScanResult as BdkFullScanResult;
1111
use bdk_wallet::chain::spk_client::SyncRequest as BdkSyncRequest;
12-
use bdk_wallet::chain::spk_client::SyncResult as BdkSyncResult;
13-
use bdk_wallet::Update as BdkUpdate;
1412
use bdk_wallet::KeychainKind;
13+
use bdk_wallet::Update as BdkUpdate;
1514

1615
use std::collections::BTreeMap;
1716
use std::sync::Arc;
@@ -44,14 +43,12 @@ impl ElectrumClient {
4443
.take()
4544
.ok_or(ElectrumError::RequestAlreadyConsumed)?;
4645

47-
let electrum_result: FullScanResult<KeychainKind> = self.0.full_scan(
46+
let full_scan_result: BdkFullScanResult<KeychainKind> = self.0.full_scan(
4847
request,
4948
stop_gap as usize,
5049
batch_size as usize,
5150
fetch_prev_txouts,
5251
)?;
53-
let full_scan_result: BdkFullScanResult<KeychainKind> =
54-
electrum_result.with_confirmation_time_height_anchor(&self.0)?;
5552

5653
let update = BdkUpdate {
5754
last_active_indices: full_scan_result.last_active_indices,
@@ -76,11 +73,9 @@ impl ElectrumClient {
7673
.take()
7774
.ok_or(ElectrumError::RequestAlreadyConsumed)?;
7875

79-
let electrum_result: SyncResult =
76+
let sync_result: SyncResult =
8077
self.0
8178
.sync(request, batch_size as usize, fetch_prev_txouts)?;
82-
let sync_result: BdkSyncResult =
83-
electrum_result.with_confirmation_time_height_anchor(&self.0)?;
8479

8580
let update = BdkUpdate {
8681
last_active_indices: BTreeMap::default(),

bdk-ffi/src/error.rs

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::bitcoin::OutPoint;
2-
use crate::Network;
32

43
use bdk_bitcoind_rpc::bitcoincore_rpc::bitcoin::address::ParseError;
54
use bdk_electrum::electrum_client::Error as BdkElectrumError;
@@ -19,11 +18,8 @@ use bdk_wallet::error::BuildFeeBumpError;
1918
use bdk_wallet::error::CreateTxError as BdkCreateTxError;
2019
use bdk_wallet::keys::bip39::Error as BdkBip39Error;
2120
use bdk_wallet::miniscript::descriptor::DescriptorKeyParseError as BdkDescriptorKeyParseError;
22-
use bdk_wallet::rusqlite::Error as BdkSqliteError;
2321
use bdk_wallet::signer::SignerError as BdkSignerError;
2422
use bdk_wallet::tx_builder::AddUtxoError;
25-
use bdk_wallet::KeychainKind;
26-
use bdk_wallet::LoadError;
2723
use bitcoin_internals::hex::display::DisplayHex;
2824

2925
use std::convert::TryInto;
@@ -32,6 +28,18 @@ use std::convert::TryInto;
3228
// error definitions
3329
// ------------------------------------------------------------------------
3430

31+
#[derive(Debug, thiserror::Error)]
32+
pub enum FfiGenericError {
33+
GenericError,
34+
}
35+
36+
// implementing the Display trait for the FfiGenericError
37+
impl std::fmt::Display for FfiGenericError {
38+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39+
write!(f, "Generic error")
40+
}
41+
}
42+
3543
#[derive(Debug, thiserror::Error)]
3644
pub enum AddressParseError {
3745
#[error("base58 address encoding error")]
@@ -595,7 +603,6 @@ pub enum SignerError {
595603
pub enum SqliteError {
596604
// NOTE: This error is renamed from Network to InvalidNetwork to avoid conflict with the Network
597605
// enum in uniffi.
598-
599606
#[error("SQLite error: {rusqlite_error}")]
600607
Sqlite { rusqlite_error: String },
601608
}
@@ -637,14 +644,14 @@ pub enum WalletCreationError {
637644
// From NewError and NewOrLoadError
638645
#[error("error with descriptor: {error_message}")]
639646
Descriptor { error_message: String },
640-
#[error("data loaded from persistence is missing network type.")]
641-
MissingNetwork,
642-
#[error("data loaded from persistence is missing genesis hash.")]
643-
MissingGenesis,
644-
#[error("data loaded from persistence is missing descriptor: {error_message}")]
645-
MissingDescriptor { error_message: String },
646-
#[error("data loaded is unexpected: {error_message}")]
647-
Mismatch { error_message: String },
647+
// #[error("data loaded from persistence is missing network type.")]
648+
// MissingNetwork,
649+
// #[error("data loaded from persistence is missing genesis hash.")]
650+
// MissingGenesis,
651+
// #[error("data loaded from persistence is missing descriptor: {error_message}")]
652+
// MissingDescriptor { error_message: String },
653+
// #[error("data loaded is unexpected: {error_message}")]
654+
// Mismatch { error_message: String },
648655
}
649656

650657
// ------------------------------------------------------------------------
@@ -1180,7 +1187,9 @@ impl From<BdkSignerError> for SignerError {
11801187
error_message: e.to_string(),
11811188
},
11821189
BdkSignerError::External(e) => SignerError::External { error_message: e },
1183-
BdkSignerError::Psbt(e) => SignerError::Psbt { error_message: e.to_string() },
1190+
BdkSignerError::Psbt(e) => SignerError::Psbt {
1191+
error_message: e.to_string(),
1192+
},
11841193
}
11851194
}
11861195
}
@@ -1208,13 +1217,13 @@ impl From<BdkEncodeError> for TransactionError {
12081217
}
12091218
}
12101219

1211-
impl From<BdkSqliteError> for SqliteError {
1212-
fn from(error: BdkSqliteError) -> Self {
1213-
SqliteError::Sqlite {
1214-
rusqlite_error: error.to_string(),
1215-
}
1216-
}
1217-
}
1220+
// impl From<BdkSqliteError> for SqliteError {
1221+
// fn from(error: BdkSqliteError) -> Self {
1222+
// SqliteError::Sqlite {
1223+
// rusqlite_error: error.to_string(),
1224+
// }
1225+
// }
1226+
// }
12181227

12191228
impl From<DescriptorError> for WalletCreationError {
12201229
fn from(error: DescriptorError) -> Self {
@@ -1224,27 +1233,27 @@ impl From<DescriptorError> for WalletCreationError {
12241233
}
12251234
}
12261235

1227-
impl From<LoadError> for WalletCreationError {
1228-
fn from(error: LoadError) -> Self {
1229-
match error {
1230-
LoadError::Descriptor(e) => WalletCreationError::Descriptor {
1231-
error_message: e.to_string(),
1232-
},
1233-
LoadError::MissingGenesis => {
1234-
WalletCreationError::MissingGenesis
1235-
}
1236-
LoadError::LoadedNetworkDoesNotMatch { expected, got } => {
1237-
WalletCreationError::LoadedNetworkDoesNotMatch { expected, got }
1238-
}
1239-
LoadError::LoadedDescriptorDoesNotMatch { got, keychain } => {
1240-
WalletCreationError::LoadedDescriptorDoesNotMatch {
1241-
got: format!("{:?}", got),
1242-
keychain,
1243-
}
1244-
}
1245-
}
1246-
}
1247-
}
1236+
// impl From<LoadError> for WalletCreationError {
1237+
// fn from(error: LoadError) -> Self {
1238+
// match error {
1239+
// LoadError::Descriptor(e) => WalletCreationError::Descriptor {
1240+
// error_message: e.to_string(),
1241+
// },
1242+
// LoadError::MissingGenesis => {
1243+
// WalletCreationError::MissingGenesis
1244+
// }
1245+
// LoadError::LoadedNetworkDoesNotMatch { expected, got } => {
1246+
// WalletCreationError::LoadedNetworkDoesNotMatch { expected, got }
1247+
// }
1248+
// LoadError::LoadedDescriptorDoesNotMatch { got, keychain } => {
1249+
// WalletCreationError::LoadedDescriptorDoesNotMatch {
1250+
// got: format!("{:?}", got),
1251+
// keychain,
1252+
// }
1253+
// }
1254+
// }
1255+
// }
1256+
// }
12481257

12491258
// ------------------------------------------------------------------------
12501259
// error tests

bdk-ffi/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use crate::error::SignerError;
4141
use crate::error::SqliteError;
4242
use crate::error::TransactionError;
4343
use crate::error::TxidParseError;
44-
use crate::error::WalletCreationError;
4544
use crate::esplora::EsploraClient;
4645
use crate::keys::DerivationPath;
4746
use crate::keys::DescriptorPublicKey;
@@ -50,9 +49,11 @@ use crate::keys::Mnemonic;
5049
use crate::store::Connection;
5150
use crate::types::AddressInfo;
5251
use crate::types::Balance;
52+
use crate::types::BlockId;
5353
use crate::types::CanonicalTx;
5454
use crate::types::ChainPosition;
5555
use crate::types::ChangeSet;
56+
use crate::types::ConfirmationBlockTime;
5657
use crate::types::FullScanRequest;
5758
use crate::types::FullScanScriptInspector;
5859
use crate::types::LocalOutput;
@@ -64,6 +65,7 @@ use crate::wallet::SentAndReceivedValues;
6465
use crate::wallet::TxBuilder;
6566
use crate::wallet::Update;
6667
use crate::wallet::Wallet;
68+
use crate::error::FfiGenericError;
6769

6870
use bdk_wallet::bitcoin::Network;
6971
use bdk_wallet::keys::bip39::WordCount;

0 commit comments

Comments
 (0)