mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-04-11 21:39:26 +02:00
Adds zap amount cache for the memory space calculations
This commit is contained in:
parent
8ed78ea38f
commit
282d4614c0
@ -39,9 +39,20 @@ class LnZapEvent(
|
||||
// This event is also kept in LocalCache (same object)
|
||||
@Transient val zapRequest: LnZapRequestEvent?
|
||||
|
||||
// Keeps this as a field because it's a heavier function used everywhere.
|
||||
val amount by lazy {
|
||||
try {
|
||||
lnInvoice()?.let { LnInvoiceUtil.getAmountInSats(it) }
|
||||
} catch (e: Exception) {
|
||||
Log.e("LnZapEvent", "Failed to Parse LnInvoice ${lnInvoice()}", e)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override fun countMemory(): Long =
|
||||
super.countMemory() +
|
||||
pointerSizeInBytes + (zapRequest?.countMemory() ?: 0) // rough calculation
|
||||
pointerSizeInBytes + (zapRequest?.countMemory() ?: 0) + // rough calculation
|
||||
pointerSizeInBytes + 36 // bigdecimal size
|
||||
|
||||
override fun containedPost(): LnZapRequestEvent? =
|
||||
try {
|
||||
@ -75,16 +86,6 @@ class LnZapEvent(
|
||||
|
||||
override fun amount() = amount
|
||||
|
||||
// Keeps this as a field because it's a heavier function used everywhere.
|
||||
val amount by lazy {
|
||||
try {
|
||||
lnInvoice()?.let { LnInvoiceUtil.getAmountInSats(it) }
|
||||
} catch (e: Exception) {
|
||||
Log.e("LnZapEvent", "Failed to Parse LnInvoice ${lnInvoice()}", e)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override fun content(): String = content
|
||||
|
||||
fun lnInvoice() = tags.firstOrNull { it.size > 1 && it[0] == "bolt11" }?.get(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user