feat: migrate nodeAliasCache to room
This commit is contained in:
+6
-6
@@ -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
|
||||
Reference in New Issue
Block a user