feat: migrate nodeAliasCache to room

This commit is contained in:
2026-06-01 23:59:42 +02:00
parent 38c6c6f723
commit 93332dc683
12 changed files with 166 additions and 180 deletions
@@ -7,10 +7,10 @@ import java.util.concurrent.TimeUnit
/**
* Resolves a Lightning node pubkey to a human-readable alias.
* Tries 1ml.com first, falls back to mempool.space.
* Tries mempool.space first, falls back to 1ml.com.
* Returns null if neither source has the node or both fail.
*/
class NodeAliasService {
class NodeAliasClient {
private val client = OkHttpClient.Builder()
.connectTimeout(5, TimeUnit.SECONDS)
@@ -34,15 +34,15 @@ class NodeAliasService {
suspend fun resolveAlias(pubkey: String): String? {
if (pubkey.isBlank()) return null
// 1. Try 1ml.com
runCatching { oneMlApi.getNode(pubkey) }
// 1. Try mempool.space
runCatching { mempoolApi.getNode(pubkey) }
.onSuccess { response ->
val alias = response.alias?.takeIf { it.isNotBlank() }
if (alias != null) return alias
}
// 2. Fall back to mempool.space
runCatching { mempoolApi.getNode(pubkey) }
// 2. Fall back to 1ml.com
runCatching { oneMlApi.getNode(pubkey) }
.onSuccess { response ->
val alias = response.alias?.takeIf { it.isNotBlank() }
if (alias != null) return alias