diff --git a/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/LiveWalletTest.kt b/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/LiveWalletTest.kt index 307b88bc..c666e5e2 100644 --- a/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/LiveWalletTest.kt +++ b/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/LiveWalletTest.kt @@ -37,8 +37,8 @@ class LiveWalletTest { println("Transactions count: ${wallet.transactions().count()}") val transactions = wallet.transactions().take(3) for (tx in transactions) { - val sentAndReceived = wallet.sentAndReceived(tx) - println("Transaction: ${tx.txid()}") + val sentAndReceived = wallet.sentAndReceived(tx.transaction) + println("Transaction: ${tx.transaction.txid()}") println("Sent ${sentAndReceived.sent}") println("Received ${sentAndReceived.received}") } diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index c7156347..fecd33f6 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -147,7 +147,7 @@ interface Wallet { SentAndReceivedValues sent_and_received([ByRef] Transaction tx); - sequence transactions(); + sequence transactions(); [Throws=CalculateFeeError] u64 calculate_fee([ByRef] Transaction tx); @@ -363,6 +363,17 @@ interface Address { boolean is_valid_for_network(Network network); }; +[Enum] +interface ConfirmationDetails { + Confirmed(u32 height, u64 timestamp); + Unconfirmed(u64 timestamp); +}; + +dictionary TransactionDetails { + Transaction transaction; + ConfirmationDetails confirmation; +}; + interface Transaction { [Throws=Alpha3Error] constructor(sequence transaction_bytes); diff --git a/bdk-ffi/src/bitcoin.rs b/bdk-ffi/src/bitcoin.rs index 3af00c7f..8fee1c18 100644 --- a/bdk-ffi/src/bitcoin.rs +++ b/bdk-ffi/src/bitcoin.rs @@ -8,8 +8,10 @@ use bdk::bitcoin::Network; use bdk::bitcoin::OutPoint as BdkOutPoint; use bdk::bitcoin::Transaction as BdkTransaction; use bdk::bitcoin::Txid; +use bdk::chain::tx_graph::CanonicalTx as BdkCanonicalTx; use crate::error::Alpha3Error; +use bdk::chain::{ChainPosition, ConfirmationTimeHeightAnchor}; use std::io::Cursor; use std::str::FromStr; use std::sync::{Arc, Mutex}; @@ -114,6 +116,36 @@ impl From for Address { } } +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ConfirmationDetails { + Confirmed { height: u32, timestamp: u64 }, + Unconfirmed { timestamp: u64 }, +} + +pub struct TransactionDetails { + pub transaction: Arc, + pub confirmation: ConfirmationDetails, +} + +impl<'a> From> + for TransactionDetails +{ + fn from(tx: BdkCanonicalTx<'a, BdkTransaction, ConfirmationTimeHeightAnchor>) -> Self { + let confirmation = match tx.chain_position { + ChainPosition::Confirmed(anchor) => ConfirmationDetails::Confirmed { + height: anchor.confirmation_height, + timestamp: anchor.confirmation_time, + }, + ChainPosition::Unconfirmed(timestamp) => ConfirmationDetails::Unconfirmed { timestamp }, + }; + + TransactionDetails { + transaction: Arc::new(Transaction::from(tx.tx_node.tx)), + confirmation, + } + } +} + #[derive(Debug, Clone, PartialEq, Eq)] pub struct Transaction { inner: BdkTransaction, diff --git a/bdk-ffi/src/lib.rs b/bdk-ffi/src/lib.rs index 19b1eef9..e899d339 100644 --- a/bdk-ffi/src/lib.rs +++ b/bdk-ffi/src/lib.rs @@ -34,6 +34,9 @@ use crate::wallet::TxBuilder; use crate::wallet::Update; use crate::wallet::Wallet; +use crate::bitcoin::ConfirmationDetails; +use crate::bitcoin::TransactionDetails; + use crate::error::PersistenceError; use crate::error::WalletCreationError; use bdk::bitcoin::Network; diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index c145d828..07ae46a2 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -1,4 +1,4 @@ -use crate::bitcoin::{OutPoint, PartiallySignedTransaction, Transaction}; +use crate::bitcoin::{OutPoint, PartiallySignedTransaction, Transaction, TransactionDetails}; use crate::descriptor::Descriptor; use crate::error::{Alpha3Error, CalculateFeeError, PersistenceError, WalletCreationError}; use crate::types::ScriptAmount; @@ -104,10 +104,10 @@ impl Wallet { SentAndReceivedValues { sent, received } } - pub fn transactions(&self) -> Vec> { + pub fn transactions(&self) -> Vec { self.get_wallet() .transactions() - .map(|tx| Arc::new(tx.tx_node.tx.into())) + .map(|tx| tx.into()) .collect() } diff --git a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveWalletTest.kt b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveWalletTest.kt index 9a8b37e4..813abfbc 100644 --- a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveWalletTest.kt +++ b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveWalletTest.kt @@ -35,8 +35,8 @@ class LiveWalletTest { println("Transactions count: ${wallet.transactions().count()}") val transactions = wallet.transactions().take(3) for (tx in transactions) { - val sentAndReceived = wallet.sentAndReceived(tx) - println("Transaction: ${tx.txid()}") + val sentAndReceived = wallet.sentAndReceived(tx.transaction) + println("Transaction: ${tx.transaction.txid()}") println("Sent ${sentAndReceived.sent}") println("Received ${sentAndReceived.received}") } diff --git a/bdk-python/tests/test_live_wallet.py b/bdk-python/tests/test_live_wallet.py index 9d794fa1..ead2e17a 100644 --- a/bdk-python/tests/test_live_wallet.py +++ b/bdk-python/tests/test_live_wallet.py @@ -32,8 +32,8 @@ def test_synced_balance(self): print(f"Transactions count: {len(wallet.transactions())}") transactions = wallet.transactions()[:3] for tx in transactions: - sent_and_received = wallet.sent_and_received(tx) - print(f"Transaction: {tx.txid()}") + sent_and_received = wallet.sent_and_received(tx.transaction) + print(f"Transaction: {tx.transaction.txid()}") print(f"Sent {sent_and_received.sent}") print(f"Received {sent_and_received.received}") diff --git a/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift index b7d67b03..12ee9e7f 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift @@ -47,8 +47,8 @@ final class LiveWalletTests: XCTestCase { print("Transactions count: \(wallet.transactions().count)") let transactions = wallet.transactions().prefix(3) for tx in transactions { - let sentAndReceived = wallet.sentAndReceived(tx: tx) - print("Transaction: \(tx.txid())") + let sentAndReceived = wallet.sentAndReceived(tx: tx.transaction) + print("Transaction: \(tx.transaction.txid())") print("Sent \(sentAndReceived.sent)") print("Received \(sentAndReceived.received)") }