All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.fr.acinq.lightning.payment.PaymentRequest.kt Maven / Gradle / Ivy

There is a newer version: 1.8.4
Show newest version
package fr.acinq.lightning.payment

import fr.acinq.bitcoin.ByteVector32
import fr.acinq.bitcoin.PublicKey
import fr.acinq.bitcoin.utils.Try
import fr.acinq.lightning.Features
import fr.acinq.lightning.MilliSatoshi
import fr.acinq.lightning.utils.currentTimestampSeconds

sealed class PaymentRequest {
    abstract val amount: MilliSatoshi?
    abstract val paymentHash: ByteVector32
    abstract val nodeId: PublicKey
    abstract val features: Features

    abstract fun isExpired(currentTimestampSeconds: Long = currentTimestampSeconds()): Boolean

    abstract fun write(): String

    companion object {
        fun read(input: String): Try =
            if (input.startsWith(Bolt12Invoice.hrp, ignoreCase = true)) {
                Bolt12Invoice.fromString(input).map { it }
            } else {
                Bolt11Invoice.read(input).map { it }
            }
        }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy