Skip to content

Commit

Permalink
Temp 2: Wallet struct looks like it would work
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Sep 20, 2023
1 parent 737d2c1 commit aba5278
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 156 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

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

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

[dependencies]
bdk = { git = "https://github.com/bitcoindevkit/bdk.git", rev = "59fc1b341ba94212b2ea3e888e51fb6fcd00589f", features = ["all-keys"] }
bdk_file_store = { git = "https://github.com/bitcoindevkit/bdk.git", rev = "59fc1b341ba94212b2ea3e888e51fb6fcd00589f" }
# bdk_chain = { git = "https://github.com/bitcoindevkit/bdk.git", rev = "59fc1b341ba94212b2ea3e888e51fb6fcd00589f" }
uniffi = { version = "0.23.0" }

[build-dependencies]
Expand Down
11 changes: 6 additions & 5 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
namespace bdk {

};
namespace bdk {};

[Error]
enum BdkError {
Expand Down Expand Up @@ -218,8 +216,11 @@ dictionary ScriptAmount {
};

interface Wallet {
[Throws=BdkError]
constructor(Descriptor descriptor, Descriptor? change_descriptor, Network network, DatabaseConfig database_config);
// [Throws=BdkError]
// constructor(Descriptor descriptor, Descriptor? change_descriptor, Network network, DatabaseConfig database_config);

[Name=new_no_persist, Throws=BdkError]
constructor(Descriptor descriptor, Descriptor? change_descriptor, Network network);

Network network();

Expand Down
27 changes: 10 additions & 17 deletions bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use bdk::bitcoin::blockdata::script::Script as BdkScript;
use bdk::bitcoin::blockdata::transaction::TxIn as BdkTxIn;
use bdk::bitcoin::blockdata::transaction::TxOut as BdkTxOut;
use bdk::bitcoin::consensus::Decodable;
use bdk::bitcoin::psbt::serialize::Serialize;
// use bdk::bitcoin::psbt::serialize::Serialize;
use bdk::bitcoin::util::address::{Payload as BdkPayload, WitnessVersion};
use bdk::bitcoin::{
Address as BdkAddress, Network, OutPoint as BdkOutPoint, Transaction as BdkTransaction, Txid,
Expand All @@ -31,7 +31,14 @@ use bdk::wallet::AddressIndex as BdkAddressIndex;
use bdk::wallet::AddressInfo as BdkAddressInfo;
use bdk::LocalUtxo as BdkLocalUtxo;
use bdk::TransactionDetails as BdkTransactionDetails;
use bdk::{Balance as BdkBalance, BlockTime, Error as BdkError, FeeRate, KeychainKind};
use bdk::{
// Balance as BdkBalance,
BlockTime,
Error as BdkError,
FeeRate,
KeychainKind
};
use bdk::wallet::Balance as BdkBalance;
use std::convert::From;
use std::fmt;
use std::fmt::Debug;
Expand Down Expand Up @@ -84,14 +91,6 @@ pub enum AddressIndex {
/// Use with caution, if an index is given that is less than the current descriptor index
/// then the returned address may have already been used.
Peek { index: u32 },
/// Return the address for a specific descriptor index and reset the current descriptor index
/// used by `AddressIndex::New` and `AddressIndex::LastUsed` to this value.
/// Use with caution, if an index is given that is less than the current descriptor index
/// then the returned address and subsequent addresses returned by calls to `AddressIndex::New`
/// and `AddressIndex::LastUsed` may have already been used. Also if the index is reset to a
/// value earlier than the [`Blockchain`] stop_gap (default is 20) then a
/// larger stop_gap should be used to monitor for all possibly used addresses.
Reset { index: u32 },
}

impl From<AddressIndex> for BdkAddressIndex {
Expand All @@ -100,7 +99,6 @@ impl From<AddressIndex> for BdkAddressIndex {
AddressIndex::New => BdkAddressIndex::New,
AddressIndex::LastUnused => BdkAddressIndex::LastUnused,
AddressIndex::Peek { index } => BdkAddressIndex::Peek(index),
AddressIndex::Reset { index } => BdkAddressIndex::Reset(index),
}
}
}
Expand Down Expand Up @@ -161,6 +159,7 @@ impl From<&OutPoint> for BdkOutPoint {
}
}

// MIGRATION 1.0: Not sure why total and spendable are not in Balance anymore.
pub struct Balance {
// All coinbase outputs not yet matured
pub immature: u64,
Expand All @@ -170,10 +169,6 @@ pub struct Balance {
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 {
Expand All @@ -183,8 +178,6 @@ impl From<BdkBalance> for Balance {
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(),
}
}
}
Expand Down
Loading

0 comments on commit aba5278

Please sign in to comment.