Skip to content

Commit a1a4599

Browse files
committed
feat: add transactions method on wallet
1 parent bbc6e1a commit a1a4599

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/LiveWalletTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ class LiveWalletTest {
1919
println("Balance: $balance")
2020

2121
assert(wallet.getBalance().total > 0uL)
22+
23+
println("Transactions count: ${wallet.transactions().count()}")
24+
val transactions = wallet.transactions().take(3)
25+
for (tx in transactions) {
26+
val sentAndReceived = wallet.sentAndReceived(tx)
27+
println("Transaction: ${tx.txid()}")
28+
println("Sent ${sentAndReceived.sent}")
29+
println("Received ${sentAndReceived.received}")
30+
}
2231
}
2332

2433
@Test

bdk-ffi/src/bdk.udl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ interface Wallet {
109109
boolean sign(PartiallySignedTransaction psbt);
110110

111111
SentAndReceivedValues sent_and_received([ByRef] Transaction tx);
112+
113+
sequence<Transaction> transactions();
112114
};
113115

114116
interface Update {};

bdk-ffi/src/wallet.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ impl Wallet {
9999
let (sent, received): (u64, u64) = self.get_wallet().sent_and_received(&tx.clone().into());
100100
SentAndReceivedValues { sent, received }
101101
}
102+
103+
pub fn transactions(&self) -> Vec<Arc<Transaction>> {
104+
self.get_wallet()
105+
.transactions()
106+
.map(|tx| Arc::new(tx.tx_node.tx.clone().into()))
107+
.collect()
108+
}
102109
}
103110

104111
pub struct SentAndReceivedValues {

bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveWalletTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ class LiveWalletTest {
1515
println("Balance: ${wallet.getBalance().total}")
1616

1717
assert(wallet.getBalance().total > 0uL)
18+
19+
println("Transactions count: ${wallet.transactions().count()}")
20+
val transactions = wallet.transactions().take(3)
21+
for (tx in transactions) {
22+
val sentAndReceived = wallet.sentAndReceived(tx)
23+
println("Transaction: ${tx.txid()}")
24+
println("Sent ${sentAndReceived.sent}")
25+
println("Received ${sentAndReceived.received}")
26+
}
1827
}
1928

2029
@Test

bdk-python/tests/test_live_wallet.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TestLiveWallet(unittest.TestCase):
55

66
def test_synced_balance(self):
77
descriptor: bdk.Descriptor = bdk.Descriptor(
8-
"wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
8+
"wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)",
99
bdk.Network.TESTNET
1010
)
1111
wallet: bdk.Wallet = bdk.Wallet.new_no_persist(
@@ -23,6 +23,15 @@ def test_synced_balance(self):
2323

2424
self.assertGreater(wallet.get_balance().total, 0)
2525

26+
print(f"Transactions count: {len(wallet.transactions())}")
27+
transactions = wallet.transactions()[:3]
28+
for tx in transactions:
29+
sent_and_received = wallet.sent_and_received(tx)
30+
print(f"Transaction: {tx.txid()}")
31+
print(f"Sent {sent_and_received.sent}")
32+
print(f"Received {sent_and_received.received}")
33+
34+
2635
def test_broadcast_transaction(self):
2736
descriptor: bdk.Descriptor = bdk.Descriptor(
2837
"wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)",

bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ final class LiveWalletTests: XCTestCase {
2121
try wallet.applyUpdate(update: update)
2222

2323
XCTAssertGreaterThan(wallet.getBalance().total, UInt64(0))
24+
25+
print("Transactions count: \(wallet.transactions().count)")
26+
let transactions = wallet.transactions().prefix(3)
27+
for tx in transactions {
28+
let sentAndReceived = wallet.sentAndReceived(tx: tx)
29+
print("Transaction: \(tx.txid())")
30+
print("Sent \(sentAndReceived.sent)")
31+
print("Received \(sentAndReceived.received)")
32+
}
2433
}
2534

2635
func testBroadcastTransaction() throws {

0 commit comments

Comments
 (0)