Skip to content

refactor: Remove hardcoded file path #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions examples/src/main/kotlin/WalletSetupBip32.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down