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 b42789a..a49f69c 100644 --- a/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/LiveTxBuilderTest.kt +++ b/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/LiveTxBuilderTest.kt @@ -29,6 +29,7 @@ class LiveTxBuilderTest { val fullScanRequest: FullScanRequest = wallet.startFullScan() val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL) wallet.applyUpdate(update) + wallet.commit() println("Balance: ${wallet.getBalance().total}") assert(wallet.getBalance().total > 0uL) @@ -52,6 +53,7 @@ class LiveTxBuilderTest { val fullScanRequest: FullScanRequest = wallet.startFullScan() val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL) wallet.applyUpdate(update) + wallet.commit() println("Balance: ${wallet.getBalance().total}") assert(wallet.getBalance().total > 0uL) 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 cd40a44..122a8e1 100644 --- a/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/LiveWalletTest.kt +++ b/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/LiveWalletTest.kt @@ -29,6 +29,7 @@ class LiveWalletTest { val fullScanRequest: FullScanRequest = wallet.startFullScan() val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL) wallet.applyUpdate(update) + wallet.commit() println("Balance: ${wallet.getBalance().total}") val balance: Balance = wallet.getBalance() println("Balance: $balance") @@ -52,8 +53,8 @@ class LiveWalletTest { val esploraClient = EsploraClient("https://esplora.testnet.kuutamo.cloud/") val fullScanRequest: FullScanRequest = wallet.startFullScan() val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL) - wallet.applyUpdate(update) + wallet.commit() println("Balance: ${wallet.getBalance().total}") println("New address: ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address}") diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 5cc38cf..4083090 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -267,6 +267,9 @@ interface Wallet { [Throws=CannotConnectError] void apply_update(Update update); + [Throws=PersistenceError] + boolean commit(); + boolean is_mine([ByRef] Script script); [Throws=SignerError] diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index 46bf1b9..aeea601 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -69,18 +69,13 @@ impl Wallet { .map_err(CannotConnectError::from) } - // TODO: This is the fallible version of get_internal_address; should I rename it to get_internal_address? - // It's a slight change of the API, the other option is to rename the get_address to try_get_address - // pub fn try_get_internal_address( - // &self, - // address_index: AddressIndex, - // ) -> Result { - // let address_info = self - // .get_wallet() - // .try_get_internal_address(address_index.into())? - // .into(); - // Ok(address_info) - // } + pub fn commit(&self) -> Result { + self.get_wallet() + .commit() + .map_err(|e| PersistenceError::Write { + error_message: e.to_string(), + }) + } pub fn network(&self) -> Network { self.get_wallet().network() 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 9eb129d..3104896 100644 --- a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveTxBuilderTest.kt +++ b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveTxBuilderTest.kt @@ -22,16 +22,18 @@ class LiveTxBuilderTest { @Test fun testTxBuilder() { val descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.TESTNET) - val wallet = Wallet(descriptor, null, persistenceFilePath, Network.TESTNET) - val esploraClient = EsploraClient("https://esplora.testnet.kuutamo.cloud/") + val wallet = Wallet(descriptor, null, persistenceFilePath, Network.SIGNET) + // val esploraClient = EsploraClient("https://esplora.testnet.kuutamo.cloud/") + val esploraClient = EsploraClient("http://signet.bitcoindevkit.net") val fullScanRequest: FullScanRequest = wallet.startFullScan() val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL) wallet.applyUpdate(update) + wallet.commit() println("Balance: ${wallet.getBalance().total}") assert(wallet.getBalance().total > 0uL) - val recipient: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.TESTNET) + val recipient: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.SIGNET) val psbt: Psbt = TxBuilder() .addRecipient(recipient.scriptPubkey(), 4200uL) .feeRate(FeeRate.fromSatPerVb(2uL)) @@ -46,17 +48,19 @@ class LiveTxBuilderTest { fun complexTxBuilder() { val externalDescriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.TESTNET) val changeDescriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", Network.TESTNET) - val wallet = Wallet(externalDescriptor, changeDescriptor, persistenceFilePath, Network.TESTNET) - val esploraClient = EsploraClient("https://esplora.testnet.kuutamo.cloud/") + val wallet = Wallet(externalDescriptor, changeDescriptor, persistenceFilePath, Network.SIGNET) + // val esploraClient = EsploraClient("https://esplora.testnet.kuutamo.cloud/") + val esploraClient = EsploraClient("http://signet.bitcoindevkit.net") val fullScanRequest: FullScanRequest = wallet.startFullScan() val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL) wallet.applyUpdate(update) + wallet.commit() println("Balance: ${wallet.getBalance().total}") assert(wallet.getBalance().total > 0uL) - val recipient1: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.TESTNET) - val recipient2: Address = Address("tb1qw2c3lxufxqe2x9s4rdzh65tpf4d7fssjgh8nv6", Network.TESTNET) + val recipient1: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.SIGNET) + val recipient2: Address = Address("tb1qw2c3lxufxqe2x9s4rdzh65tpf4d7fssjgh8nv6", Network.SIGNET) val allRecipients: List = listOf( ScriptAmount(recipient1.scriptPubkey(), 4200uL), ScriptAmount(recipient2.scriptPubkey(), 4200uL), 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 c878105..d5afff7 100644 --- a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveWalletTest.kt +++ b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveWalletTest.kt @@ -29,6 +29,7 @@ class LiveWalletTest { val fullScanRequest: FullScanRequest = wallet.startFullScan() val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL) wallet.applyUpdate(update) + wallet.commit() println("Balance: ${wallet.getBalance().total}") assert(wallet.getBalance().total > 0uL) @@ -51,6 +52,7 @@ class LiveWalletTest { val fullScanRequest: FullScanRequest = wallet.startFullScan() val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL) wallet.applyUpdate(update) + wallet.commit() println("Balance: ${wallet.getBalance().total}") println("New address: ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address.asString()}") diff --git a/bdk-python/tests/test_live_tx_builder.py b/bdk-python/tests/test_live_tx_builder.py index 2c9a3fc..78b130d 100644 --- a/bdk-python/tests/test_live_tx_builder.py +++ b/bdk-python/tests/test_live_tx_builder.py @@ -27,6 +27,7 @@ class LiveTxBuilderTest(unittest.TestCase): parallel_requests=1 ) wallet.apply_update(update) + wallet.commit() self.assertGreater(wallet.get_balance().total, 0) @@ -62,6 +63,7 @@ class LiveTxBuilderTest(unittest.TestCase): parallel_requests=1 ) wallet.apply_update(update) + wallet.commit() self.assertGreater(wallet.get_balance().total, 0) diff --git a/bdk-python/tests/test_live_wallet.py b/bdk-python/tests/test_live_wallet.py index 230b64b..0fdafdb 100644 --- a/bdk-python/tests/test_live_wallet.py +++ b/bdk-python/tests/test_live_wallet.py @@ -27,6 +27,7 @@ class LiveWalletTest(unittest.TestCase): parallel_requests=1 ) wallet.apply_update(update) + wallet.commit() self.assertGreater(wallet.get_balance().total, 0) @@ -58,6 +59,7 @@ class LiveWalletTest(unittest.TestCase): parallel_requests=1 ) wallet.apply_update(update) + wallet.commit() self.assertGreater(wallet.get_balance().total, 0) diff --git a/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift index 18b17e4..ef9dc6d 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift @@ -42,6 +42,7 @@ final class LiveTxBuilderTests: XCTestCase { parallelRequests: 1 ) try wallet.applyUpdate(update: update) + try wallet.commit() XCTAssertGreaterThan(wallet.getBalance().total, UInt64(0), "Wallet must have positive balance, please add funds") @@ -78,7 +79,8 @@ final class LiveTxBuilderTests: XCTestCase { parallelRequests: 1 ) try wallet.applyUpdate(update: update) - + try wallet.commit() + XCTAssertGreaterThan(wallet.getBalance().total, UInt64(0), "Wallet must have positive balance, please add funds") let recipient1: Address = try Address(address: "tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", network: .testnet) diff --git a/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift index ef4db72..24a797b 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift @@ -42,6 +42,7 @@ final class LiveWalletTests: XCTestCase { parallelRequests: 1 ) try wallet.applyUpdate(update: update) + try wallet.commit() XCTAssertGreaterThan(wallet.getBalance().total, UInt64(0)) @@ -74,6 +75,7 @@ final class LiveWalletTests: XCTestCase { parallelRequests: 1 ) try wallet.applyUpdate(update: update) + try wallet.commit() XCTAssertGreaterThan(wallet.getBalance().total, UInt64(0), "Wallet must have positive balance, please add funds")