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
@@ -0,0 +1,53 @@
package com.bitcointxoko.gudariwallet.api
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
/**
* Resolves a Lightning node pubkey to a human-readable alias.
* Tries mempool.space first, falls back to 1ml.com.
* Returns null if neither source has the node or both fail.
*/
class NodeAliasClient {
private val client = OkHttpClient.Builder()
.connectTimeout(5, TimeUnit.SECONDS)
.readTimeout(5, TimeUnit.SECONDS)
.build()
private val mempoolApi: MempoolApi = Retrofit.Builder()
.baseUrl("https://mempool.space/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(MempoolApi::class.java)
private val oneMlApi: OneMlApi = Retrofit.Builder()
.baseUrl("https://1ml.com/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(OneMlApi::class.java)
suspend fun resolveAlias(pubkey: String): String? {
if (pubkey.isBlank()) return null
// 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 1ml.com
runCatching { oneMlApi.getNode(pubkey) }
.onSuccess { response ->
val alias = response.alias?.takeIf { it.isNotBlank() }
if (alias != null) return alias
}
return null
}
}