Skip to content

Commit 48892ac

Browse files
committed
refactor: Remove hardcoded file path
1 parent 2571ff0 commit 48892ac

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

examples/src/main/kotlin/WalletSetupBip32.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fun createDescriptorsFromBip32RootKey (
2828
val mnemonic = Mnemonic(WordCount.WORDS12)
2929
val bip32ExtendedRootKey = DescriptorSecretKey(network, mnemonic, null)
3030
println("Bip32 root key: $bip32ExtendedRootKey")
31-
31+
3232
val descriptor: Descriptor = createScriptAppropriateDescriptor(
3333
activeWalletScriptType,
3434
bip32ExtendedRootKey,
@@ -64,13 +64,20 @@ fun createScriptAppropriateDescriptor(
6464
)
6565
}
6666
}
67-
6867
fun getPersistenceFilePath(): String {
69-
val currentDirectory = Paths.get("").toAbsolutePath().toString() + "/bdk-jvm/examples/src/main/kotlin/bdk_persistence.sqlite"
70-
File(currentDirectory).apply {
68+
// Resolve absolute path to the fixed `examples/data` directory
69+
val projectRoot = Paths.get("").toAbsolutePath().parent.resolve("examples")
70+
val persistenceDirectory = projectRoot.resolve("data").toFile()
71+
val persistenceFilePath = projectRoot.resolve("data/bdk_persistence.sqlite").toString()
72+
73+
persistenceDirectory.apply {
74+
if (!exists()) mkdirs()
75+
}
76+
77+
File(persistenceFilePath).apply {
7178
if (exists()) delete()
7279
}
73-
return currentDirectory
80+
return persistenceFilePath
7481
}
7582

7683
enum class ActiveWalletScriptType {

0 commit comments

Comments
 (0)