From 647726434e7ad1afb129e017712b6998586c8023 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 30 Aug 2024 16:09:22 -0500 Subject: [PATCH] feat: extract_keys --- bdk-ffi/src/wallet.rs | 1 + .../bitcoindevkit/OfflinePersistenceTest.kt | 31 +++++++++++++++++++ .../OfflinePersistenceTests.swift | 24 ++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index a337200a..ad9a5cee 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -68,6 +68,7 @@ impl Wallet { let wallet: PersistedWallet = BdkWallet::load() .descriptor(KeychainKind::External, Some(descriptor)) .descriptor(KeychainKind::Internal, Some(change_descriptor)) + .extract_keys() .load_wallet(db)? .ok_or(LoadWithPersistError::CouldNotLoad)?; diff --git a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/OfflinePersistenceTest.kt b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/OfflinePersistenceTest.kt index 21dfe27e..7fc3b3c9 100644 --- a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/OfflinePersistenceTest.kt +++ b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/OfflinePersistenceTest.kt @@ -40,4 +40,35 @@ class OfflinePersistenceTest { actual = addressInfo.address.toString(), ) } + + @Test + fun testPersistenceWithDescriptor() { + val connection = Connection(persistenceFilePath) + + val descriptorPub = Descriptor( + "wpkh([9122d9e0/84'/1'/0']tpubDCYVtmaSaDzTxcgvoP5AHZNbZKZzrvoNH9KARep88vESc6MxRqAp4LmePc2eeGX6XUxBcdhAmkthWTDqygPz2wLAyHWisD299Lkdrj5egY6/0/*)#zpaanzgu", + Network.SIGNET + ) + val changeDescriptorPub = Descriptor( + "wpkh([9122d9e0/84'/1'/0']tpubDCYVtmaSaDzTxcgvoP5AHZNbZKZzrvoNH9KARep88vESc6MxRqAp4LmePc2eeGX6XUxBcdhAmkthWTDqygPz2wLAyHWisD299Lkdrj5egY6/1/*)#n4cuwhcy", + Network.SIGNET + ) + + val wallet: Wallet = Wallet.load( + descriptorPub, + changeDescriptorPub, + connection + ) + val addressInfo: AddressInfo = wallet.revealNextAddress(KeychainKind.EXTERNAL) + println("Address: $addressInfo") + + assertEquals( + expected = 7u, + actual = addressInfo.index, + ) + assertEquals( + expected = "tb1qan3lldunh37ma6c0afeywgjyjgnyc8uz975zl2", + actual = addressInfo.address.toString(), + ) + } } diff --git a/bdk-swift/Tests/BitcoinDevKitTests/OfflinePersistenceTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/OfflinePersistenceTests.swift index fe70d4d2..35bb4935 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/OfflinePersistenceTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/OfflinePersistenceTests.swift @@ -38,4 +38,28 @@ final class OfflinePersistenceTests: XCTestCase { XCTAssertTrue(nextAddress.address.description == "tb1qan3lldunh37ma6c0afeywgjyjgnyc8uz975zl2") XCTAssertTrue(nextAddress.index == 7) } + + func testPersistenceWithDescriptor() throws { + let connection = try Connection(path: dbFilePath.path) + + let descriptorPub = try Descriptor( + descriptor: "wpkh([9122d9e0/84'/1'/0']tpubDCYVtmaSaDzTxcgvoP5AHZNbZKZzrvoNH9KARep88vESc6MxRqAp4LmePc2eeGX6XUxBcdhAmkthWTDqygPz2wLAyHWisD299Lkdrj5egY6/0/*)#zpaanzgu", + network: Network.signet + ) + let changeDescriptorPub = try Descriptor( + descriptor: "wpkh([9122d9e0/84'/1'/0']tpubDCYVtmaSaDzTxcgvoP5AHZNbZKZzrvoNH9KARep88vESc6MxRqAp4LmePc2eeGX6XUxBcdhAmkthWTDqygPz2wLAyHWisD299Lkdrj5egY6/1/*)#n4cuwhcy", + network: Network.signet + ) + + let wallet = try Wallet.load( + descriptor: descriptorPub, + changeDescriptor: changeDescriptorPub, + connection: connection + ) + let nextAddress: AddressInfo = wallet.revealNextAddress(keychain: KeychainKind.external) + print("Address: \(nextAddress)") + + XCTAssertEqual(nextAddress.index, 7) + XCTAssertEqual(nextAddress.address.description, "tb1qan3lldunh37ma6c0afeywgjyjgnyc8uz975zl2") + } }