Upgrade bdk dependency to 0.11

This commit is contained in:
Steve Myers
2021-09-25 21:17:40 -07:00
parent 342c4c4aa8
commit 39e5efe5c0
9 changed files with 226 additions and 83 deletions

View File

@@ -9,8 +9,6 @@ pub enum FfiError {
InvalidU32Bytes,
Generic,
ScriptDoesntHaveAddressForm,
SingleRecipientMultipleOutputs,
SingleRecipientNoInputs,
NoRecipients,
NoUtxosSelected,
OutputBelowDustLimit,
@@ -23,12 +21,14 @@ pub enum FfiError {
IrreplaceableTransaction,
FeeRateTooLow,
FeeTooLow,
FeeRateUnavailable,
MissingKeyOrigin,
Key,
ChecksumMismatch,
SpendingPolicyRequired,
InvalidPolicyPathError,
Signer,
InvalidNetwork,
InvalidProgressValue,
ProgressUpdateError,
InvalidOutpoint,
@@ -41,6 +41,7 @@ pub enum FfiError {
Json,
Hex,
Psbt,
PsbtParse,
Electrum,
// Esplora,
// CompactFilters,
@@ -53,8 +54,6 @@ impl From<&bdk::Error> for FfiError {
Error::InvalidU32Bytes(_) => FfiError::InvalidU32Bytes,
Error::Generic(_) => FfiError::Generic,
Error::ScriptDoesntHaveAddressForm => FfiError::ScriptDoesntHaveAddressForm,
Error::SingleRecipientMultipleOutputs => FfiError::SingleRecipientMultipleOutputs,
Error::SingleRecipientNoInputs => FfiError::SingleRecipientNoInputs,
Error::NoRecipients => FfiError::NoRecipients,
Error::NoUtxosSelected => FfiError::NoUtxosSelected,
Error::OutputBelowDustLimit(_) => FfiError::OutputBelowDustLimit,
@@ -67,12 +66,14 @@ impl From<&bdk::Error> for FfiError {
Error::IrreplaceableTransaction => FfiError::IrreplaceableTransaction,
Error::FeeRateTooLow { .. } => FfiError::FeeRateTooLow,
Error::FeeTooLow { .. } => FfiError::FeeTooLow,
Error::FeeRateUnavailable => FfiError::FeeRateUnavailable,
Error::MissingKeyOrigin(_) => FfiError::MissingKeyOrigin,
Error::Key(_) => FfiError::Key,
Error::ChecksumMismatch => FfiError::ChecksumMismatch,
Error::SpendingPolicyRequired(_) => FfiError::SpendingPolicyRequired,
Error::InvalidPolicyPathError(_) => FfiError::InvalidPolicyPathError,
Error::Signer(_) => FfiError::Signer,
Error::InvalidNetwork { .. } => FfiError::InvalidNetwork,
Error::InvalidProgressValue(_) => FfiError::InvalidProgressValue,
Error::ProgressUpdateError => FfiError::ProgressUpdateError,
Error::InvalidOutpoint(_) => FfiError::InvalidOutpoint,
@@ -85,9 +86,11 @@ impl From<&bdk::Error> for FfiError {
Error::Json(_) => FfiError::Json,
Error::Hex(_) => FfiError::Hex,
Error::Psbt(_) => FfiError::Psbt,
Error::PsbtParse(_) => FfiError::PsbtParse,
Error::Electrum(_) => FfiError::Electrum,
// Error::Esplora(_) => JniError::Esplora,
// Error::CompactFilters(_) => JniError::CompactFilters,
// Error::Rpc(_) => JniError::Rpc,
Error::Sled(_) => FfiError::Sled,
}
}

View File

@@ -16,6 +16,7 @@ fn new_electrum_config(
socks5: Option<char_p_ref>,
retry: i16,
timeout: i16,
stop_gap: usize,
) -> Box<BlockchainConfig> {
let url = url.to_string();
let socks5 = socks5.map(|s| s.to_string());
@@ -27,6 +28,7 @@ fn new_electrum_config(
socks5,
retry,
timeout,
stop_gap,
});
Box::new(BlockchainConfig {
raw: electrum_config,

View File

@@ -2,7 +2,6 @@ use std::convert::TryFrom;
use std::ffi::CString;
use ::safer_ffi::prelude::*;
use bdk::bitcoin::network::constants::Network::Testnet;
use bdk::blockchain::{log_progress, AnyBlockchain, AnyBlockchainConfig, ConfigurableBlockchain};
use bdk::database::{AnyDatabase, AnyDatabaseConfig, ConfigurableDatabase};
use bdk::wallet::AddressIndex::New;
@@ -16,6 +15,8 @@ use database::DatabaseConfig;
use crate::error::FfiError;
use crate::types::{FfiResult, FfiResultVoid};
use crate::wallet::transaction::{LocalUtxo, TransactionDetails};
use bdk::bitcoin::Network;
use std::str::FromStr;
mod blockchain;
mod database;
@@ -33,14 +34,16 @@ pub struct OpaqueWallet {
fn new_wallet_result(
descriptor: char_p_ref,
change_descriptor: Option<char_p_ref>,
network: char_p_ref,
blockchain_config: &BlockchainConfig,
database_config: &DatabaseConfig,
) -> FfiResult<Option<Box<OpaqueWallet>>> {
let descriptor = descriptor.to_string();
let change_descriptor = change_descriptor.map(|s| s.to_string());
let net = Network::from_str(network.to_str()).expect("Network name");
let bc_config = &blockchain_config.raw;
let db_config = &database_config.raw;
let wallet_result = new_wallet(descriptor, change_descriptor, bc_config, db_config);
let wallet_result = new_wallet(descriptor, change_descriptor, net, bc_config, db_config);
match wallet_result {
Ok(w) => FfiResult {
@@ -57,11 +60,10 @@ fn new_wallet_result(
fn new_wallet(
descriptor: String,
change_descriptor: Option<String>,
network: Network,
blockchain_config: &AnyBlockchainConfig,
database_config: &AnyDatabaseConfig,
) -> Result<Wallet<AnyBlockchain, AnyDatabase>, Error> {
let network = Testnet;
let client = AnyBlockchain::from_config(blockchain_config)?;
let database = AnyDatabase::from_config(database_config)?;

View File

@@ -13,27 +13,52 @@ pub struct TransactionDetails {
// pub transaction: Option<Transaction>,
/// Transaction id
pub txid: char_p_boxed,
/// Timestamp
pub timestamp: u64,
/// Received value (sats)
pub received: u64,
/// Sent value (sats)
pub sent: u64,
/// Fee value (sats)
pub fees: u64,
/// Confirmed in block height, `None` means unconfirmed
pub height: i32,
/// Fee value (sats) if known, -1 if unknown, based on backend
pub fee: i64,
/// true if confirmed
pub is_confirmed: bool,
/// Confirmed in block height
pub confirmation_time: ConfirmationTime,
/// Whether the tx has been verified against the consensus rules
pub verified: bool,
}
#[derive_ReprC]
#[repr(C)]
#[derive(Debug, Clone)]
pub struct ConfirmationTime {
/// confirmation block height, 0 if is_confirmed is false
pub height: u32,
/// confirmation block timestamp, 0 if is_confirmed is false
pub timestamp: u64,
}
impl From<&bdk::TransactionDetails> for TransactionDetails {
fn from(op: &bdk::TransactionDetails) -> Self {
let fee = op.fee.map(|f| i64::try_from(f).unwrap()).unwrap_or(-1);
let confirmation_time = op
.confirmation_time
.as_ref()
.map(|c| ConfirmationTime {
height: c.height,
timestamp: c.timestamp,
})
.unwrap_or(ConfirmationTime {
height: 0,
timestamp: 0,
});
TransactionDetails {
txid: char_p_boxed::try_from(op.txid.to_string()).unwrap(),
timestamp: op.timestamp,
received: op.received,
sent: op.sent,
fees: op.fees,
height: op.height.map(|h| h as i32).unwrap_or(-1),
fee,
is_confirmed: op.confirmation_time.is_some(),
confirmation_time,
verified: op.verified,
}
}
}