From 14d5ebea9c78432e9f76f01fd7b66a8a2c0de532 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 7 Dec 2023 13:24:39 -0600 Subject: [PATCH] feat: add transactions method on wallet --- bdk-ffi/src/bdk.udl | 2 ++ bdk-ffi/src/wallet.rs | 7 +++++++ bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 1229779e..f6935093 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -109,6 +109,8 @@ interface Wallet { boolean sign(PartiallySignedTransaction psbt); SentAndReceivedValues sent_and_received([ByRef] Transaction tx); + + sequence transactions(); }; interface Update {}; diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index c6f2c6ae..dc96015e 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -98,6 +98,13 @@ impl Wallet { let (sent, received): (u64, u64) = self.get_wallet().sent_and_received(&tx.clone().into()); SentAndReceivedValues { sent, received } } + + pub fn transactions(&self) -> Vec> { + self.get_wallet() + .transactions() + .map(|tx| Arc::new(tx.tx_node.tx.clone().into())) + .collect() + } } pub struct SentAndReceivedValues { diff --git a/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift index 87565986..b936ea95 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift @@ -21,6 +21,15 @@ final class LiveWalletTests: XCTestCase { try wallet.applyUpdate(update: update) XCTAssertGreaterThan(wallet.getBalance().total, UInt64(0)) + + 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())") + print("Sent \(sentAndReceived.sent)") + print("Received \(sentAndReceived.received)") + } } func testBroadcastTransaction() throws {