diff --git a/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/LiveTxBuilderTest.kt b/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/LiveTxBuilderTest.kt index 6b72e06e..1ff6a446 100644 --- a/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/LiveTxBuilderTest.kt +++ b/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/LiveTxBuilderTest.kt @@ -14,9 +14,9 @@ class LiveTxBuilderTest { val esploraClient = EsploraClient("https://mempool.space/testnet/api") val update = esploraClient.scan(wallet, 10uL, 1uL) wallet.applyUpdate(update) - println("Balance: ${wallet.getBalance().total()}") + println("Balance: ${wallet.getBalance().total}") - assert(wallet.getBalance().total() > 0uL) + assert(wallet.getBalance().total > 0uL) val recipient: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.TESTNET) val psbt: PartiallySignedTransaction = TxBuilder() 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 0fd4fb30..462bda22 100644 --- a/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/LiveWalletTest.kt +++ b/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/LiveWalletTest.kt @@ -11,11 +11,10 @@ class LiveWalletTest { val descriptor: Descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.TESTNET) val wallet: Wallet = Wallet.newNoPersist(descriptor, null, Network.TESTNET) val esploraClient: EsploraClient = EsploraClient("https://mempool.space/testnet/api") - // val esploraClient = EsploraClient("https://blockstream.info/testnet/api") val update = esploraClient.scan(wallet, 10uL, 1uL) wallet.applyUpdate(update) - println("Balance: ${wallet.getBalance().total()}") + println("Balance: ${wallet.getBalance().total}") - assert(wallet.getBalance().total() > 0uL) + assert(wallet.getBalance().total > 0uL) } } diff --git a/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/OfflineWalletTest.kt b/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/OfflineWalletTest.kt index 5a3206a0..4c3dd991 100644 --- a/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/OfflineWalletTest.kt +++ b/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/OfflineWalletTest.kt @@ -50,7 +50,7 @@ class OfflineWalletTest { assertEquals( expected = 0uL, - actual = wallet.getBalance().total() + actual = wallet.getBalance().total ) } } diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index caabbaaf..98719f96 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -43,18 +43,18 @@ enum BdkError { "Psbt", }; -interface Balance { - u64 immature(); +dictionary Balance { + u64 immature; - u64 trusted_pending(); + u64 trusted_pending; - u64 untrusted_pending(); + u64 untrusted_pending; - u64 confirmed(); + u64 confirmed; - u64 trusted_spendable(); + u64 trusted_spendable; - u64 total(); + u64 total; }; dictionary AddressInfo { diff --git a/bdk-ffi/src/lib.rs b/bdk-ffi/src/lib.rs index 5bc4e30f..6184bb00 100644 --- a/bdk-ffi/src/lib.rs +++ b/bdk-ffi/src/lib.rs @@ -175,47 +175,33 @@ impl From<&BdkAddressIndex> for AddressIndex { // } pub struct Balance { - pub inner: BdkBalance, + // All coinbase outputs not yet matured + pub immature: u64, + /// Unconfirmed UTXOs generated by a wallet tx + pub trusted_pending: u64, + /// Unconfirmed UTXOs received from an external wallet + pub untrusted_pending: u64, + /// Confirmed and immediately spendable balance + pub confirmed: u64, + /// Get sum of trusted_pending and confirmed coins + pub trusted_spendable: u64, + /// Get the whole balance visible to the wallet + pub total: u64, } -impl Balance { - /// All coinbase outputs not yet matured. - fn immature(&self) -> u64 { - self.inner.immature - } - - /// Unconfirmed UTXOs generated by a wallet tx. - fn trusted_pending(&self) -> u64 { - self.inner.trusted_pending - } - - /// Unconfirmed UTXOs received from an external wallet. - fn untrusted_pending(&self) -> u64 { - self.inner.untrusted_pending - } - - /// Confirmed and immediately spendable balance. - fn confirmed(&self) -> u64 { - self.inner.confirmed - } - - /// Get sum of trusted_pending and confirmed coins. - fn trusted_spendable(&self) -> u64 { - self.inner.trusted_spendable() - } - - /// Get the whole balance visible to the wallet. - fn total(&self) -> u64 { - self.inner.total() +impl From for Balance { + fn from(bdk_balance: BdkBalance) -> Self { + Balance { + immature: bdk_balance.immature, + trusted_pending: bdk_balance.trusted_pending, + untrusted_pending: bdk_balance.untrusted_pending, + confirmed: bdk_balance.confirmed, + trusted_spendable: bdk_balance.trusted_spendable(), + total: bdk_balance.total(), + } } } -// impl From for Balance { -// fn from(bdk_balance: BdkBalance) -> Self { -// Balance { inner: bdk_balance } -// } -// } - // /// A transaction output, which defines new coins to be created from old ones. // #[derive(Debug, Clone)] // pub struct TxOut { diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index 2fe73d60..e14ef4d3 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -52,11 +52,9 @@ impl Wallet { .into() } - // TODO 16: Why is the Arc required here? - pub fn get_balance(&self) -> Arc { - let bdk_balance = self.get_wallet().get_balance(); - let balance = Balance { inner: bdk_balance }; - Arc::new(balance) + pub fn get_balance(&self) -> Balance { + let bdk_balance: bdk::wallet::Balance = self.get_wallet().get_balance(); + Balance::from(bdk_balance) } pub fn apply_update(&self, update: Arc) -> Result<(), BdkError> { diff --git a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveTxBuilderTest.kt b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveTxBuilderTest.kt index ca8cd197..d99f5597 100644 --- a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveTxBuilderTest.kt +++ b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveTxBuilderTest.kt @@ -12,9 +12,9 @@ class LiveTxBuilderTest { val esploraClient = EsploraClient("https://mempool.space/testnet/api") val update = esploraClient.scan(wallet, 10uL, 1uL) wallet.applyUpdate(update) - println("Balance: ${wallet.getBalance().total()}") + println("Balance: ${wallet.getBalance().total}") - assert(wallet.getBalance().total() > 0uL) + assert(wallet.getBalance().total > 0uL) val recipient: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.TESTNET) val psbt: PartiallySignedTransaction = TxBuilder() 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 44f6dca4..21d2d649 100644 --- a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveWalletTest.kt +++ b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveWalletTest.kt @@ -11,8 +11,8 @@ class LiveWalletTest { // val esploraClient = EsploraClient("https://blockstream.info/testnet/api") val update = esploraClient.scan(wallet, 10uL, 1uL) wallet.applyUpdate(update) - println("Balance: ${wallet.getBalance().total()}") + println("Balance: ${wallet.getBalance().total}") - assert(wallet.getBalance().total() > 0uL) + assert(wallet.getBalance().total > 0uL) } } diff --git a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/OfflineWalletTest.kt b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/OfflineWalletTest.kt index 19b71d96..85744737 100644 --- a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/OfflineWalletTest.kt +++ b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/OfflineWalletTest.kt @@ -47,7 +47,7 @@ class OfflineWalletTest { assertEquals( expected = 0uL, - actual = wallet.getBalance().total() + actual = wallet.getBalance().total ) } } diff --git a/bdk-python/README.md b/bdk-python/README.md index b99bbd96..e0ae4138 100644 --- a/bdk-python/README.md +++ b/bdk-python/README.md @@ -15,7 +15,7 @@ pip install --requirement requirements.txt bash ./scripts/generate-linux.sh # here you should run the script appropriate for your platform python setup.py bdist_wheel --verbose pip install ./dist/bdkpython-.whl --force-reinstall -python -m unittest --verbose tests/test_bdk.py +python -m unittest --verbose ``` ## Build the package diff --git a/bdk-python/tests/test_live_tx_builder.py b/bdk-python/tests/test_live_tx_builder.py index 55bbe390..8416513d 100644 --- a/bdk-python/tests/test_live_tx_builder.py +++ b/bdk-python/tests/test_live_tx_builder.py @@ -21,7 +21,7 @@ def test_tx_builder(self): ) wallet.apply_update(update) - self.assertGreater(wallet.get_balance().total(), 0) + self.assertGreater(wallet.get_balance().total, 0) recipient = bdk.Address( address = "tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", diff --git a/bdk-python/tests/test_live_wallet.py b/bdk-python/tests/test_live_wallet.py index 16ee1e90..f2041fdc 100644 --- a/bdk-python/tests/test_live_wallet.py +++ b/bdk-python/tests/test_live_wallet.py @@ -21,7 +21,7 @@ def test_synced_balance(self): ) wallet.apply_update(update) - self.assertGreater(wallet.get_balance().total(), 0) + self.assertGreater(wallet.get_balance().total, 0) if __name__ == '__main__': diff --git a/bdk-python/tests/test_offline_wallet.py b/bdk-python/tests/test_offline_wallet.py index 49e3c909..4fc6ccd1 100644 --- a/bdk-python/tests/test_offline_wallet.py +++ b/bdk-python/tests/test_offline_wallet.py @@ -28,7 +28,7 @@ def test_balance(self): bdk.Network.TESTNET ) - self.assertEqual(wallet.get_balance().total(), 0) + self.assertEqual(wallet.get_balance().total, 0) if __name__ == '__main__': unittest.main() diff --git a/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift index d0aee18e..196f6439 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift @@ -20,7 +20,7 @@ final class LiveTxBuilderTests: XCTestCase { ) try wallet.applyUpdate(update: update) - XCTAssertGreaterThan(wallet.getBalance().total(), UInt64(0), "Wallet must have positive balance, please add funds") + XCTAssertGreaterThan(wallet.getBalance().total, UInt64(0), "Wallet must have positive balance, please add funds") let recipient: Address = try Address(address: "tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", network: .testnet) let psbt: PartiallySignedTransaction = try TxBuilder() diff --git a/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift index b8b6fabd..24866e68 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift @@ -20,6 +20,6 @@ final class LiveWalletTests: XCTestCase { ) try wallet.applyUpdate(update: update) - XCTAssertGreaterThan(wallet.getBalance().total(), UInt64(0)) + XCTAssertGreaterThan(wallet.getBalance().total, UInt64(0)) } } diff --git a/bdk-swift/Tests/BitcoinDevKitTests/OfflineWalletTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/OfflineWalletTests.swift index 441f032f..273fc861 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/OfflineWalletTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/OfflineWalletTests.swift @@ -28,6 +28,6 @@ final class OfflineWalletTests: XCTestCase { network: .testnet ) - XCTAssertEqual(wallet.getBalance().total(), 0) + XCTAssertEqual(wallet.getBalance().total, 0) } }