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 14, 2024
1 parent f27bada commit e554088
Show file tree
Hide file tree
Showing 20 changed files with 266 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class LiveTxBuilderTest {
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
println("Balance: ${wallet.getBalance().total.toSat()}")

assert(wallet.getBalance().total > 0uL) {
assert(wallet.getBalance().total.toSat() > 0uL) {
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address.asString()} and try again."
}

Expand All @@ -59,9 +59,9 @@ class LiveTxBuilderTest {
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
println("Balance: ${wallet.getBalance().total.toSat()}")

assert(wallet.getBalance().total > 0uL) {
assert(wallet.getBalance().total.toSat() > 0uL) {
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address.asString()} and try again."
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class LiveWalletTest {
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
println("Balance: ${wallet.getBalance().total.toSat()}")
val balance: Balance = wallet.getBalance()
println("Balance: $balance")

assert(wallet.getBalance().total > 0uL) {
assert(wallet.getBalance().total.toSat() > 0uL) {
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address.asString()} and try again."
}

Expand All @@ -60,9 +60,9 @@ class LiveWalletTest {
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
println("Balance: ${wallet.getBalance().total.toSat()}")

assert(wallet.getBalance().total > 0uL) {
assert(wallet.getBalance().total.toSat() > 0uL) {
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address} and try again."
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class OfflineWalletTest {

assertEquals(
expected = 0uL,
actual = wallet.getBalance().total
actual = wallet.getBalance().total.toSat()
)
}
}
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
46 changes: 36 additions & 10 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ enum FeeRateError {
"ArithmeticOverflow"
};

[Error]
interface ParseAmountError {
Negative();
TooBig();
TooPrecise();
InvalidFormat();
InputTooLarge();
InvalidCharacter(string error_message);
UnknownDenomination(string error_message);
PossiblyConfusingDenomination(string error_message);
OtherParseAmountErr();
};

[Error]
interface PersistenceError {
Write(string error_message);
Expand Down Expand Up @@ -185,6 +198,7 @@ interface WalletCreationError {
NotInitialized();
LoadedGenesisDoesNotMatch(string expected, string got);
LoadedNetworkDoesNotMatch(Network expected, Network? got);
LoadedDescriptorDoesNotMatch(string got, KeychainKind keychain);
};

// ------------------------------------------------------------------------
Expand All @@ -203,17 +217,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 @@ -302,7 +316,7 @@ interface Update {};
interface TxBuilder {
constructor();

TxBuilder add_recipient([ByRef] Script script, u64 amount);
TxBuilder add_recipient([ByRef] Script script, Amount amount);

TxBuilder set_recipients(sequence<ScriptAmount> recipients);

Expand Down Expand Up @@ -456,12 +470,12 @@ interface EsploraClient {

dictionary ScriptAmount {
Script script;
u64 amount;
Amount amount;
};

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

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

interface Amount {
[Name=from_sat]
constructor(u64 from_sat);

[Name=from_btc, Throws=ParseAmountError]
constructor(f64 from_btc);

u64 to_sat();

f64 to_btc();
};

interface FeeRate {
[Name=from_sat_per_vb, Throws=FeeRateError]
constructor(u64 sat_per_vb);
Expand Down
37 changes: 37 additions & 0 deletions bdk-ffi/src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,43 @@ use std::io::Cursor;
use std::str::FromStr;
use std::sync::{Arc, Mutex};

use bdk::bitcoin::amount::ParseAmountError;
use bdk::bitcoin::Amount as BdkAmount;

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Amount(pub(crate) BdkAmount);

impl Amount {
pub fn from_sat(sat: u64) -> Self {
Amount(BdkAmount::from_sat(sat))
}

pub fn from_btc(btc: f64) -> Result<Self, ParseAmountError> {
let bdk_amount = BdkAmount::from_btc(btc).map_err(ParseAmountError::from)?;
Ok(Amount(bdk_amount))
}

pub fn to_sat(&self) -> u64 {
self.0.to_sat()
}

pub fn to_btc(&self) -> f64 {
self.0.to_btc()
}
}

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

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

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Script(pub(crate) BdkScriptBuf);

Expand Down
Loading

0 comments on commit e554088

Please sign in to comment.