diff --git a/examples/src/main/kotlin/WalletSetupBip32.kt b/examples/src/main/kotlin/WalletSetupBip32.kt index bf6f1f8..5005e48 100644 --- a/examples/src/main/kotlin/WalletSetupBip32.kt +++ b/examples/src/main/kotlin/WalletSetupBip32.kt @@ -28,7 +28,7 @@ fun createDescriptorsFromBip32RootKey ( val mnemonic = Mnemonic(WordCount.WORDS12) val bip32ExtendedRootKey = DescriptorSecretKey(network, mnemonic, null) println("Bip32 root key: $bip32ExtendedRootKey") - + val descriptor: Descriptor = createScriptAppropriateDescriptor( activeWalletScriptType, bip32ExtendedRootKey, @@ -64,13 +64,20 @@ fun createScriptAppropriateDescriptor( ) } } - fun getPersistenceFilePath(): String { - val currentDirectory = Paths.get("").toAbsolutePath().toString() + "/bdk-jvm/examples/src/main/kotlin/bdk_persistence.sqlite" - File(currentDirectory).apply { + // Resolve absolute path to the fixed `examples/data` directory + val projectRoot = Paths.get("").toAbsolutePath().parent.resolve("examples") + val persistenceDirectory = projectRoot.resolve("data").toFile() + val persistenceFilePath = projectRoot.resolve("data/bdk_persistence.sqlite").toString() + + persistenceDirectory.apply { + if (!exists()) mkdirs() + } + + File(persistenceFilePath).apply { if (exists()) delete() } - return currentDirectory + return persistenceFilePath } enum class ActiveWalletScriptType {