Merge bitcoindevkit/bdk-ffi#193: Update bdk dependency to 0.22

3c6075ad96afa238dc3ceca71ba82cb10088bb90 Add Balance struct and conversion from BdkBalance (thunderbiscuit)
4e15badb14d34db4911641f345e99987d132a81c Update BDK to version 0.22 (thunderbiscuit)

Pull request description:

  The bindings do not build when attempting this upgrade because `get_balance()` now returns a `Balance` struct (this was merged in bitcoindevkit/bdk#640)

  ```sh
  error[E0308]: mismatched types
     --> src/lib.rs:433:9
      |
  432 |     fn get_balance(&self) -> Result<u64, Error> {
      |                              ------------------ expected `Result<u64, bdk::Error>` because of return type
  433 |         self.get_wallet().get_balance()
      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found struct `Balance`
      |
      = note: expected enum `Result<u64, _>`
                 found enum `Result<Balance, _>`

  For more information about this error, try `rustc --explain E0308`.
  error: could not compile `bdk-ffi` due to previous error
  ```

  When we upgrade to `0.22.0` we could decide to add the `Balance` struct to the bindings, or simply return the total by calling `get_total()`, which returns a `u64` (same as we have now).

ACKs for top commit:
  notmandatory:
    ACK 3c6075ad96afa238dc3ceca71ba82cb10088bb90

Tree-SHA512: 13d2f83f992735f4f9619ae339d7834df08385129edf06bac830c298b433571af3f211e92a6da1f4f9646dec27dbd2c6133a035f26eac8757b7a1c94b54b463d
This commit is contained in:
Steve Myers 2022-09-08 13:58:08 -05:00
commit dfb350e206
No known key found for this signature in database
GPG Key ID: 8105A46B22C2D051
4 changed files with 47 additions and 7 deletions

View File

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Remove dictionary `ExtendedKeyInfo {mnenonic, xprv, fingerprint}` [#154] - Remove dictionary `ExtendedKeyInfo {mnenonic, xprv, fingerprint}` [#154]
- Remove interface `Transaction` [#190] - Remove interface `Transaction` [#190]
- Changed `Wallet` interface `list_transaction()` to return array of `TransactionDetails` [#190] - Changed `Wallet` interface `list_transaction()` to return array of `TransactionDetails` [#190]
- Update `bdk` dependency version to 0.22 [#193]
- APIs Added [#154] - APIs Added [#154]
- `generate_mnemonic()`, returns string mnemonic - `generate_mnemonic()`, returns string mnemonic
- `interface DescriptorSecretKey` - `interface DescriptorSecretKey`
@ -37,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#154]: https://github.com/bitcoindevkit/bdk-ffi/pull/154 [#154]: https://github.com/bitcoindevkit/bdk-ffi/pull/154
[#184]: https://github.com/bitcoindevkit/bdk-ffi/pull/184 [#184]: https://github.com/bitcoindevkit/bdk-ffi/pull/184
[#185]: https://github.com/bitcoindevkit/bdk-ffi/pull/185 [#185]: https://github.com/bitcoindevkit/bdk-ffi/pull/185
[#193]: https://github.com/bitcoindevkit/bdk-ffi/pull/193
## [v0.8.0] ## [v0.8.0]
- Update BDK to version 0.20.0 [#169] - Update BDK to version 0.20.0 [#169]

View File

@ -14,7 +14,7 @@ crate-type = ["staticlib", "cdylib"]
name = "bdkffi" name = "bdkffi"
[dependencies] [dependencies]
bdk = { version = "0.20", features = ["all-keys", "use-esplora-ureq", "sqlite-bundled"] } bdk = { version = "0.22", features = ["all-keys", "use-esplora-ureq", "sqlite-bundled"] }
uniffi_macros = { version = "0.19.3", features = ["builtin-bindgen"] } uniffi_macros = { version = "0.19.3", features = ["builtin-bindgen"] }
uniffi = { version = "0.19.3", features = ["builtin-bindgen"] } uniffi = { version = "0.19.3", features = ["builtin-bindgen"] }

View File

@ -7,6 +7,7 @@ namespace bdk {
enum BdkError { enum BdkError {
"InvalidU32Bytes", "InvalidU32Bytes",
"Generic", "Generic",
"MissingCachedScripts",
"ScriptDoesntHaveAddressForm", "ScriptDoesntHaveAddressForm",
"NoRecipients", "NoRecipients",
"NoUtxosSelected", "NoUtxosSelected",
@ -73,6 +74,15 @@ dictionary SqliteDbConfiguration {
string path; string path;
}; };
dictionary Balance {
u64 immature;
u64 trusted_pending;
u64 untrusted_pending;
u64 confirmed;
u64 spendable;
u64 total;
};
[Enum] [Enum]
interface DatabaseConfig { interface DatabaseConfig {
Memory(); Memory();
@ -176,7 +186,7 @@ interface Wallet {
AddressInfo get_address(AddressIndex address_index); AddressInfo get_address(AddressIndex address_index);
[Throws=BdkError] [Throws=BdkError]
u64 get_balance(); Balance get_balance();
[Throws=BdkError] [Throws=BdkError]
boolean sign([ByRef] PartiallySignedBitcoinTransaction psbt); boolean sign([ByRef] PartiallySignedBitcoinTransaction psbt);

View File

@ -23,8 +23,8 @@ use bdk::wallet::tx_builder::ChangeSpendPolicy;
use bdk::wallet::AddressIndex as BdkAddressIndex; use bdk::wallet::AddressIndex as BdkAddressIndex;
use bdk::wallet::AddressInfo as BdkAddressInfo; use bdk::wallet::AddressInfo as BdkAddressInfo;
use bdk::{ use bdk::{
BlockTime, Error, FeeRate, KeychainKind, SignOptions, SyncOptions as BdkSyncOptions, Balance as BdkBalance, BlockTime, Error, FeeRate, KeychainKind, SignOptions,
Wallet as BdkWallet, SyncOptions as BdkSyncOptions, Wallet as BdkWallet,
}; };
use std::collections::HashSet; use std::collections::HashSet;
use std::convert::{From, TryFrom}; use std::convert::{From, TryFrom};
@ -150,7 +150,7 @@ pub struct TransactionDetails {
/// Sent value (sats) /// Sent value (sats)
/// Sum of owned inputs of this transaction. /// Sum of owned inputs of this transaction.
pub sent: u64, pub sent: u64,
/// Fee value (sats) if available. /// Fee value (sats) if confirmed.
/// The availability of the fee depends on the backend. It's never None with an Electrum /// The availability of the fee depends on the backend. It's never None with an Electrum
/// Server backend, but it could be None with a Bitcoin RPC node without txindex that receive /// Server backend, but it could be None with a Bitcoin RPC node without txindex that receive
/// funds while offline. /// funds while offline.
@ -246,6 +246,34 @@ impl From<&OutPoint> for BdkOutPoint {
} }
} }
pub struct Balance {
// All coinbase outputs not yet matured
pub immature: u64,
/// Unconfirmed UTXOs generated by a wallet tx
pub trusted_pending: u64,
/// Unconfirmed UTXOs received from an external wallet
pub untrusted_pending: u64,
/// Confirmed and immediately spendable balance
pub confirmed: u64,
/// Get sum of trusted_pending and confirmed coins
pub spendable: u64,
/// Get the whole balance visible to the wallet
pub total: u64,
}
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,
spendable: bdk_balance.get_spendable(),
total: bdk_balance.get_total(),
}
}
}
/// A transaction output, which defines new coins to be created from old ones. /// A transaction output, which defines new coins to be created from old ones.
pub struct TxOut { pub struct TxOut {
/// The value of the output, in satoshis. /// The value of the output, in satoshis.
@ -402,8 +430,8 @@ impl Wallet {
/// Return the balance, meaning the sum of this wallets unspent outputs values. Note that this method only operates /// Return the balance, meaning the sum of this wallets unspent outputs values. Note that this method only operates
/// on the internal database, which first needs to be Wallet.sync manually. /// on the internal database, which first needs to be Wallet.sync manually.
fn get_balance(&self) -> Result<u64, Error> { fn get_balance(&self) -> Result<Balance, Error> {
self.get_wallet().get_balance() self.get_wallet().get_balance().map(|b| b.into())
} }
/// Sign a transaction with all the wallets signers. /// Sign a transaction with all the wallets signers.