Skip to content

Commit

Permalink
chore: bump rust bdk to alpha 11
Browse files Browse the repository at this point in the history
  • Loading branch information
reez committed May 11, 2024
1 parent ac15ed7 commit 9affc75
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 38 deletions.
20 changes: 10 additions & 10 deletions bdk-ffi/Cargo.lock

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

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

[dependencies]
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" }
bdk = { version = "1.0.0-alpha.11", features = ["all-keys", "keys-bip39"] }
bdk_esplora = { version = "0.13.0", default-features = false, features = ["std", "blocking", "blocking-https-rustls"] }
bdk_file_store = { version = "0.11.0" }

uniffi = { version = "=0.26.1" }
bitcoin-internals = { version = "0.2.0", features = ["alloc"] }
Expand Down
21 changes: 13 additions & 8 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ interface WalletCreationError {
NotInitialized();
LoadedGenesisDoesNotMatch(string expected, string got);
LoadedNetworkDoesNotMatch(Network expected, Network? got);
LoadedDescriptorDoesNotMatch(string got, string keychain);
};

// ------------------------------------------------------------------------
Expand All @@ -203,17 +204,17 @@ dictionary AddressInfo {
};

dictionary Balance {
u64 immature;
Amount immature;

u64 trusted_pending;
Amount trusted_pending;

u64 untrusted_pending;
Amount untrusted_pending;

u64 confirmed;
Amount confirmed;

u64 trusted_spendable;
Amount trusted_spendable;

u64 total;
Amount total;
};

dictionary LocalOutput {
Expand Down Expand Up @@ -460,8 +461,8 @@ dictionary ScriptAmount {
};

dictionary SentAndReceivedValues {
u64 sent;
u64 received;
Amount sent;
Amount received;
};

// ------------------------------------------------------------------------
Expand Down Expand Up @@ -543,6 +544,10 @@ dictionary OutPoint {
u32 vout;
};

dictionary Amount {
u64 sat;
};

interface FeeRate {
[Name=from_sat_per_vb, Throws=FeeRateError]
constructor(u64 sat_per_vb);
Expand Down
16 changes: 16 additions & 0 deletions bdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ pub enum WalletCreationError {
expected: Network,
got: Option<Network>,
},

#[error("loaded descriptor '{got}' does not match what was provided '{keychain}'")]
LoadedDescriptorDoesNotMatch { got: String, keychain: String },
}

// ------------------------------------------------------------------------
Expand Down Expand Up @@ -902,6 +905,12 @@ impl From<NewOrLoadError> for WalletCreationError {
NewOrLoadError::LoadedNetworkDoesNotMatch { expected, got } => {
WalletCreationError::LoadedNetworkDoesNotMatch { expected, got }
}
NewOrLoadError::LoadedDescriptorDoesNotMatch { got, keychain } => {
WalletCreationError::LoadedDescriptorDoesNotMatch {
got: format!("{:?}", got),
keychain: format!("{:?}", keychain),
}
}
}
}
}
Expand Down Expand Up @@ -1605,6 +1614,13 @@ mod test {
},
"loaded network type is not bitcoin, got Some(Testnet)".to_string(),
),
(
WalletCreationError::LoadedDescriptorDoesNotMatch {
got: "def".to_string(),
keychain: "abc".to_string(),
},
"loaded descriptor 'def' does not match what was provided 'abc'".to_string(),
),
];

for (error, expected) in errors {
Expand Down
1 change: 1 addition & 0 deletions bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use crate::keys::DescriptorPublicKey;
use crate::keys::DescriptorSecretKey;
use crate::keys::Mnemonic;
use crate::types::AddressInfo;
use crate::types::Amount;
use crate::types::Balance;
use crate::types::CanonicalTx;
use crate::types::ChainPosition;
Expand Down
44 changes: 32 additions & 12 deletions bdk-ffi/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,28 @@ use bdk::wallet::Balance as BdkBalance;
use bdk::KeychainKind;
use bdk::LocalOutput as BdkLocalOutput;

use bdk::bitcoin::Amount as BdkAmount;
use std::sync::{Arc, Mutex};

pub struct Amount {
pub sat: u64,
}

impl From<BdkAmount> for Amount {
fn from(amount: BdkAmount) -> Self {
Amount {
sat: amount.to_sat(),
}
}
}

impl From<Amount> for BdkAmount {
fn from(amount: Amount) -> Self {
BdkAmount::from_sat(amount.sat)
}
}


#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ChainPosition {
Confirmed { height: u32, timestamp: u64 },
Expand Down Expand Up @@ -65,23 +85,23 @@ impl From<BdkAddressInfo> for AddressInfo {
}

pub struct Balance {
pub immature: u64,
pub trusted_pending: u64,
pub untrusted_pending: u64,
pub confirmed: u64,
pub trusted_spendable: u64,
pub total: u64,
pub immature: Amount,
pub trusted_pending: Amount,
pub untrusted_pending: Amount,
pub confirmed: Amount,
pub trusted_spendable: Amount,
pub total: Amount,
}

impl From<BdkBalance> for Balance {
fn from(bdk_balance: BdkBalance) -> Self {
Balance {
immature: bdk_balance.immature,
trusted_pending: bdk_balance.trusted_pending,
untrusted_pending: bdk_balance.untrusted_pending,
confirmed: bdk_balance.confirmed,
trusted_spendable: bdk_balance.trusted_spendable(),
total: bdk_balance.total(),
immature: bdk_balance.immature.into(),
trusted_pending: bdk_balance.trusted_pending.into(),
untrusted_pending: bdk_balance.untrusted_pending.into(),
confirmed: bdk_balance.confirmed.into(),
trusted_spendable: bdk_balance.trusted_spendable().into(),
total: bdk_balance.total().into(),
}
}
}
Expand Down
20 changes: 15 additions & 5 deletions bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::error::{
use crate::types::{
AddressInfo, Balance, CanonicalTx, FullScanRequest, LocalOutput, ScriptAmount, SyncRequest,
};
use crate::Amount;

use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;
use bdk::bitcoin::Network;
Expand Down Expand Up @@ -102,8 +103,11 @@ impl Wallet {
}

pub fn sent_and_received(&self, tx: &Transaction) -> SentAndReceivedValues {
let (sent, received): (u64, u64) = self.get_wallet().sent_and_received(&tx.into());
SentAndReceivedValues { sent, received }
let (sent, received) = self.get_wallet().sent_and_received(&tx.into());
SentAndReceivedValues {
sent: Amount::from(sent),
received: Amount::from(received),
}
}

pub fn transactions(&self) -> Vec<CanonicalTx> {
Expand Down Expand Up @@ -152,8 +156,8 @@ impl Wallet {
}

pub struct SentAndReceivedValues {
pub sent: u64,
pub received: u64,
pub sent: Amount,
pub received: Amount,
}

pub struct Update(pub(crate) BdkUpdate);
Expand Down Expand Up @@ -315,7 +319,13 @@ impl TxBuilder {
let mut wallet = wallet.get_wallet();
let mut tx_builder = wallet.build_tx();
for (script, amount) in &self.recipients {
tx_builder.add_recipient(script.clone(), *amount);
tx_builder.add_recipient(
script.clone(),
Amount {
sat: *amount,
}
.into(),
);
}
tx_builder.change_policy(self.change_policy);
if !self.utxos.is_empty() {
Expand Down

0 comments on commit 9affc75

Please sign in to comment.