Skip to content

Commit

Permalink
feat: add transactions method on wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
reez committed Dec 7, 2023
1 parent 46e0324 commit 14d5ebe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ interface Wallet {
boolean sign(PartiallySignedTransaction psbt);

SentAndReceivedValues sent_and_received([ByRef] Transaction tx);

sequence<Transaction> transactions();
};

interface Update {};
Expand Down
7 changes: 7 additions & 0 deletions bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<Transaction>> {
self.get_wallet()
.transactions()
.map(|tx| Arc::new(tx.tx_node.tx.clone().into()))
.collect()
}
}

pub struct SentAndReceivedValues {
Expand Down
9 changes: 9 additions & 0 deletions bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 14d5ebe

Please sign in to comment.