Refactoring the DVM payment code.

This commit is contained in:
Vitor Pamplona
2024-05-20 12:37:55 -04:00
parent c88b21b547
commit 9ceb8866ed
6 changed files with 177 additions and 100 deletions
@@ -34,6 +34,39 @@ class NIP90StatusEvent(
content: String,
sig: HexKey,
) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
class StatusCode(val code: String, val description: String)
class AmountInvoice(val amount: Long?, val lnInvoice: String?)
fun status(): StatusCode? {
return tags.firstOrNull { it.size > 1 && it[0] == "status" }?.let {
if (it.size > 2 && content == "") {
StatusCode(it[1], it[2])
} else {
StatusCode(it[1], content)
}
}
}
fun firstAmount(): AmountInvoice? {
return tags.firstOrNull { it.size > 1 && it[0] == "amount" }?.let {
val amount = it[1].toLongOrNull()
if (it.size > 2) {
if (it[2].isNotBlank()) {
AmountInvoice(amount, it[2])
} else {
null
}
} else {
if (amount != null) {
AmountInvoice(amount, null)
} else {
null
}
}
}
}
companion object {
const val KIND = 7000
const val ALT = "NIP90 Status update"