Refactoring the DVM payment code.
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user