Skip to content

Commit 4f09b0a

Browse files
committed
refactor: extract node config method
1 parent 37aeaf7 commit 4f09b0a

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

app/src/main/java/to/bitkit/services/LightningService.kt

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,27 @@ class LightningService @Inject constructor(
7979
customServerUrl: String? = null,
8080
customRgsServerUrl: String? = null,
8181
) {
82-
val mnemonic = keychain.loadString(Keychain.Key.BIP39_MNEMONIC.name) ?: throw ServiceError.MnemonicNotFound
83-
val passphrase = keychain.loadString(Keychain.Key.BIP39_PASSPHRASE.name)
82+
Logger.debug("Building node…")
83+
84+
val config = config(walletIndex)
85+
node = build(
86+
walletIndex,
87+
customServerUrl,
88+
customRgsServerUrl,
89+
config,
90+
)
91+
92+
Logger.info("LDK node setup")
93+
}
8494

95+
private fun config(
96+
walletIndex: Int,
97+
): Config {
8598
// TODO get trustedLnPeers from blocktank info
86-
this.trustedPeers = Env.trustedLnPeers
99+
val trustedPeerNodeIds = Env.trustedLnPeers.map { it.nodeId }
87100
val dirPath = Env.ldkStoragePath(walletIndex)
88101

89-
val trustedPeerNodeIds = trustedPeers.map { it.nodeId }
90-
val config = defaultConfig().copy(
102+
return defaultConfig().copy(
91103
storageDirPath = dirPath,
92104
network = Env.network,
93105
trustedPeers0conf = trustedPeerNodeIds,
@@ -96,27 +108,19 @@ class LightningService @Inject constructor(
96108
perChannelReserveSats = 1u,
97109
),
98110
)
99-
100-
Logger.debug("Building node…")
101-
102-
node = build(
103-
config,
104-
walletIndex,
105-
NodeEntropy.fromBip39Mnemonic(mnemonic, passphrase),
106-
customServerUrl,
107-
customRgsServerUrl,
108-
)
109-
110-
Logger.info("LDK node setup")
111111
}
112112

113113
private suspend fun build(
114-
config: Config,
115114
walletIndex: Int,
116-
nodeEntropy: NodeEntropy,
117115
customServerUrl: String?,
118116
customRgsServerUrl: String?,
117+
config: Config,
119118
): Node = ServiceQueue.LDK.background {
119+
val nodeEntropy = NodeEntropy.fromBip39Mnemonic(
120+
mnemonic = keychain.loadString(Keychain.Key.BIP39_MNEMONIC.name) ?: throw ServiceError.MnemonicNotFound,
121+
passphrase = keychain.loadString(Keychain.Key.BIP39_PASSPHRASE.name),
122+
)
123+
120124
val builder = Builder.fromConfig(config).apply {
121125
setCustomLogger(LdkLogWriter())
122126
configureChainSource(customServerUrl)

0 commit comments

Comments
 (0)