Skip to content

Commit

Permalink
temp1
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed May 3, 2024
1 parent 330dc96 commit 6ce1941
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 153 deletions.
35 changes: 24 additions & 11 deletions bdk-ffi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions bdk-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ path = "uniffi-bindgen.rs"
default = ["uniffi/cli"]

[dependencies]
bdk = { version = "1.0.0-alpha.9", features = ["all-keys", "keys-bip39"] }
bdk_esplora = { version = "0.11.0", default-features = false, features = ["std", "blocking"] }
esplora-client = { version = "0.7.0", default-features = false, features = ["blocking-https-rustls"] }
# bdk_esplora = { version = "0.10.0", default-features = false, features = ["std", "blocking", "async-https-rustls"] }
bdk_file_store = { version = "0.9.0" }
bdk = { version = "1.0.0-alpha.10", features = ["all-keys", "keys-bip39"] }
bdk_esplora = { version = "0.12.0", default-features = false, features = ["std", "blocking", "blocking-https-rustls"] }
bdk_file_store = { version = "0.10.0" }

uniffi = { version = "=0.26.1" }
bitcoin-internals = { version = "0.2.0", features = ["alloc"] }
Expand Down
20 changes: 6 additions & 14 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,9 @@ interface WalletCreationError {
Io(string error_message);
InvalidMagicBytes(sequence<u8> got, sequence<u8> expected);
Descriptor();
Write();
Load();
Persist(string error_message);
NotInitialized();
LoadedGenesisDoesNotMatch();
LoadedGenesisDoesNotMatch(string expected, string got);
LoadedNetworkDoesNotMatch(Network expected, Network? got);
};

Expand All @@ -202,13 +201,6 @@ dictionary AddressInfo {
KeychainKind keychain;
};

[Enum]
interface AddressIndex {
New();
LastUnused();
Peek(u32 index);
};

dictionary Balance {
u64 immature;

Expand Down Expand Up @@ -260,10 +252,8 @@ interface Wallet {
[Throws=WalletCreationError]
constructor(Descriptor descriptor, Descriptor? change_descriptor, string persistence_backend_path, Network network);

AddressInfo get_address(AddressIndex address_index);

[Throws=PersistenceError]
AddressInfo try_get_internal_address(AddressIndex address_index);
AddressInfo reveal_next_address(KeychainKind keychain);

Network network();

Expand Down Expand Up @@ -439,7 +429,7 @@ interface EsploraClient {
constructor(string url);

[Throws=EsploraError]
Update full_scan(Wallet wallet, u64 stop_gap, u64 parallel_requests);
Update full_scan(FullScanRequest full_scan_request, u64 stop_gap, u64 parallel_requests);

[Throws=EsploraError]
void broadcast([ByRef] Transaction transaction);
Expand Down Expand Up @@ -551,3 +541,5 @@ interface FeeRate {

u64 to_sat_per_kwu();
};

interface FullScanRequest {};
89 changes: 61 additions & 28 deletions bdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::bitcoin::OutPoint;

use bdk::bitcoin::bip32::Error as BdkBip32Error;
use bdk::bitcoin::psbt::PsbtParseError as BdkPsbtParseError;
use bdk::bitcoin::Network;
use bdk::chain::tx_graph::CalculateFeeError as BdkCalculateFeeError;
Expand All @@ -10,19 +11,13 @@ use bdk::wallet::tx_builder::AddUtxoError;
use bdk::wallet::NewOrLoadError;
use bdk_esplora::esplora_client::{Error as BdkEsploraError, Error};
use bdk_file_store::FileError as BdkFileError;
use bdk_file_store::IterError;
use bitcoin_internals::hex::display::DisplayHex;

use crate::error::bip32::Error as BdkBip32Error;
use bdk::bitcoin::address::ParseError;
use bdk::keys::bip39::Error as BdkBip39Error;
use bdk::miniscript::descriptor::DescriptorKeyParseError as BdkDescriptorKeyParseError;

use bdk::bitcoin::bip32;

use bdk::chain;

use bdk::wallet::error::CreateTxError as BdkCreateTxError;

use std::convert::TryInto;

// ------------------------------------------------------------------------
Expand Down Expand Up @@ -406,6 +401,7 @@ pub enum TxidParseError {
InvalidTxid { txid: String },
}

// This error combines the Rust bdk::wallet::NewOrLoadError and bdk_file_store::FileError
#[derive(Debug, thiserror::Error)]
pub enum WalletCreationError {
#[error("io error trying to read file: {error_message}")]
Expand All @@ -417,17 +413,14 @@ pub enum WalletCreationError {
#[error("error with descriptor")]
Descriptor,

#[error("failed to write to persistence")]
Write,

#[error("failed to load from persistence")]
Load,
#[error("failed to either write to or load from persistence, {error_message}")]
Persist { error_message: String },

#[error("wallet is not initialized, persistence backend is empty")]
NotInitialized,

#[error("loaded genesis hash does not match the expected one")]
LoadedGenesisDoesNotMatch,
#[error("loaded genesis hash {got} does not match the expected one {expected}")]
LoadedGenesisDoesNotMatch { expected: String, got: String },

#[error("loaded network type is not {expected}, got {got:?}")]
LoadedNetworkDoesNotMatch {
Expand Down Expand Up @@ -557,8 +550,8 @@ impl From<chain::local_chain::CannotConnectError> for CannotConnectError {
}
}

impl From<BdkCreateTxError<std::io::Error>> for CreateTxError {
fn from(error: BdkCreateTxError<std::io::Error>) -> Self {
impl From<BdkCreateTxError> for CreateTxError {
fn from(error: BdkCreateTxError) -> Self {
match error {
BdkCreateTxError::Descriptor(e) => CreateTxError::Descriptor {
error_message: e.to_string(),
Expand Down Expand Up @@ -748,6 +741,44 @@ impl From<BdkEsploraError> for EsploraError {
}
}

impl From<Box<BdkEsploraError>> for EsploraError {
fn from(error: Box<BdkEsploraError>) -> Self {
match *error {
BdkEsploraError::Minreq(e) => EsploraError::Minreq {
error_message: e.to_string(),
},
BdkEsploraError::HttpResponse { status, message } => EsploraError::HttpResponse {
status,
error_message: message,
},
BdkEsploraError::Parsing(e) => EsploraError::Parsing {
error_message: e.to_string(),
},
Error::StatusCode(e) => EsploraError::StatusCode {
error_message: e.to_string(),
},
BdkEsploraError::BitcoinEncoding(e) => EsploraError::BitcoinEncoding {
error_message: e.to_string(),
},
BdkEsploraError::HexToArray(e) => EsploraError::HexToArray {
error_message: e.to_string(),
},
BdkEsploraError::HexToBytes(e) => EsploraError::HexToBytes {
error_message: e.to_string(),
},
BdkEsploraError::TransactionNotFound(_) => EsploraError::TransactionNotFound,
BdkEsploraError::HeaderHeightNotFound(height) => {
EsploraError::HeaderHeightNotFound { height }
}
BdkEsploraError::HeaderHashNotFound(_) => EsploraError::HeaderHashNotFound,
Error::InvalidHttpHeaderName(name) => EsploraError::InvalidHttpHeaderName { name },
BdkEsploraError::InvalidHttpHeaderValue(value) => {
EsploraError::InvalidHttpHeaderValue { value }
}
}
}
}

impl From<bdk::bitcoin::psbt::ExtractTxError> for ExtractTxError {
fn from(error: bdk::bitcoin::psbt::ExtractTxError) -> Self {
match error {
Expand Down Expand Up @@ -855,15 +886,19 @@ impl From<BdkFileError> for WalletCreationError {
}
}

impl From<NewOrLoadError<std::io::Error, IterError>> for WalletCreationError {
fn from(error: NewOrLoadError<std::io::Error, IterError>) -> Self {
impl From<NewOrLoadError> for WalletCreationError {
fn from(error: NewOrLoadError) -> Self {
match error {
NewOrLoadError::Descriptor(_) => WalletCreationError::Descriptor,
NewOrLoadError::Write(_) => WalletCreationError::Write,
NewOrLoadError::Load(_) => WalletCreationError::Load,
NewOrLoadError::Persist(e) => WalletCreationError::Persist {
error_message: e.to_string(),
},
NewOrLoadError::NotInitialized => WalletCreationError::NotInitialized,
NewOrLoadError::LoadedGenesisDoesNotMatch { .. } => {
WalletCreationError::LoadedGenesisDoesNotMatch
NewOrLoadError::LoadedGenesisDoesNotMatch { expected, got } => {
WalletCreationError::LoadedGenesisDoesNotMatch {
expected: expected.to_string(),
got: format!("{:?}", got),
}
}
NewOrLoadError::LoadedNetworkDoesNotMatch { expected, got } => {
WalletCreationError::LoadedNetworkDoesNotMatch { expected, got }
Expand Down Expand Up @@ -1544,12 +1579,10 @@ mod test {
"error with descriptor".to_string(),
),
(
WalletCreationError::Write,
"failed to write to persistence".to_string(),
),
(
WalletCreationError::Load,
"failed to load from persistence".to_string(),
WalletCreationError::Persist {
error_message: "persistence error".to_string(),
},
"persistence error: persistence error".to_string(),
),
(
WalletCreationError::NotInitialized,
Expand Down
Loading

0 comments on commit 6ce1941

Please sign in to comment.