Skip to content

Commit

Permalink
feat: extract_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
reez committed Sep 3, 2024
1 parent d74acfa commit 6477264
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl Wallet {
let wallet: PersistedWallet<BdkConnection> = BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor))
.descriptor(KeychainKind::Internal, Some(change_descriptor))
.extract_keys()
.load_wallet(db)?
.ok_or(LoadWithPersistError::CouldNotLoad)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
}
24 changes: 24 additions & 0 deletions bdk-swift/Tests/BitcoinDevKitTests/OfflinePersistenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 6477264

Please sign in to comment.