Skip to content

Commit

Permalink
Add payerNote + payerKey to incoming payment event
Browse files Browse the repository at this point in the history
See #91.
  • Loading branch information
pm47 authored Aug 14, 2024
1 parent a98625c commit 4427e74
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/commonMain/kotlin/fr/acinq/lightning/bin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,9 @@ class Phoenixd : CliktCommand() {
.collect {
when {
it is PaymentEvents.PaymentReceived && it.amount > 0.msat -> {
val incomingPayment = paymentsDb.getIncomingPayment(it.paymentHash)
val metadata = paymentsDb.metadataQueries.get(WalletPaymentId.IncomingPaymentId(it.paymentHash))
emit(ApiType.PaymentReceived(it, metadata))
emit(ApiType.PaymentReceived(it, incomingPayment, metadata))
}
else -> {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import fr.acinq.lightning.channel.states.ChannelStateWithCommitments
import fr.acinq.lightning.db.LightningOutgoingPayment
import fr.acinq.lightning.json.JsonSerializers
import fr.acinq.lightning.payment.Bolt11Invoice
import fr.acinq.lightning.payment.OfferPaymentMetadata
import fr.acinq.lightning.utils.UUID
import io.ktor.http.*
import kotlinx.datetime.Clock
Expand Down Expand Up @@ -83,8 +84,15 @@ sealed class ApiType {

@Serializable
@SerialName("payment_received")
data class PaymentReceived(@SerialName("amountSat") val amount: Satoshi, val paymentHash: ByteVector32, val externalId: String?, @Transient val webhookUrl: Url? = null) : ApiEvent() {
constructor(event: fr.acinq.lightning.PaymentEvents.PaymentReceived, metadata: PaymentMetadata?) : this(event.amount.truncateToSatoshi(), event.paymentHash, metadata?.externalId, metadata?.webhookUrl)
data class PaymentReceived(@SerialName("amountSat") val amount: Satoshi, val paymentHash: ByteVector32, val externalId: String?, val payerNote: String?, val payerKey: PublicKey?, @Transient val webhookUrl: Url? = null) : ApiEvent() {
constructor(event: fr.acinq.lightning.PaymentEvents.PaymentReceived, incomingPayment: fr.acinq.lightning.db.IncomingPayment?, metadata: PaymentMetadata?) : this(
amount = event.amount.truncateToSatoshi(),
paymentHash = event.paymentHash,
externalId = metadata?.externalId,
payerNote = ((incomingPayment?.origin as? fr.acinq.lightning.db.IncomingPayment.Origin.Offer)?.metadata as? OfferPaymentMetadata.V1)?.payerNote,
payerKey = ((incomingPayment?.origin as? fr.acinq.lightning.db.IncomingPayment.Origin.Offer)?.metadata as? OfferPaymentMetadata.V1)?.payerKey,
webhookUrl = metadata?.webhookUrl
)
}

@Serializable
Expand All @@ -108,7 +116,7 @@ sealed class ApiType {

@Serializable
@SerialName("incoming_payment")
data class IncomingPayment(val paymentHash: ByteVector32, val preimage: ByteVector32, val externalId: String?, val description: String?, val invoice: String?, val isPaid: Boolean, val receivedSat: Satoshi, val fees: MilliSatoshi, val completedAt: Long?, val createdAt: Long) {
data class IncomingPayment(val paymentHash: ByteVector32, val preimage: ByteVector32, val externalId: String?, val description: String?, val invoice: String?, val isPaid: Boolean, val receivedSat: Satoshi, val fees: MilliSatoshi, val payerNote: String?, val payerKey: PublicKey?, val completedAt: Long?, val createdAt: Long) {
constructor(payment: fr.acinq.lightning.db.IncomingPayment, externalId: String?) : this (
paymentHash = payment.paymentHash,
preimage = payment.preimage,
Expand All @@ -118,6 +126,8 @@ sealed class ApiType {
isPaid = payment.completedAt != null,
receivedSat = payment.amount.truncateToSatoshi(),
fees = payment.fees,
payerNote = ((payment.origin as? fr.acinq.lightning.db.IncomingPayment.Origin.Offer)?.metadata as? OfferPaymentMetadata.V1)?.payerNote,
payerKey = ((payment.origin as? fr.acinq.lightning.db.IncomingPayment.Origin.Offer)?.metadata as? OfferPaymentMetadata.V1)?.payerKey,
completedAt = payment.completedAt,
createdAt = payment.createdAt,
)
Expand Down

0 comments on commit 4427e74

Please sign in to comment.