Skip to content

Commit 17c9a00

Browse files
committed
fix: payment hash extraction
1 parent 8303632 commit 17c9a00

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

app/src/main/java/to/bitkit/repositories/WalletRepo.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -439,22 +439,25 @@ class WalletRepo @Inject constructor(
439439
try {
440440
deleteExpiredInvoices()
441441
val decoded = decode(bip21Invoice)
442-
val paymentHashOrAddress = when (decoded) {
442+
val paymentHash = when (decoded) {
443443
is Scanner.Lightning -> decoded.invoice.paymentHash.toHex()
444-
is Scanner.OnChain -> decoded.extractLightningHashOrAddress()
444+
is Scanner.OnChain -> decoded.extractLightningHash()
445445
else -> null
446446
}
447447

448-
paymentHashOrAddress?.let {
448+
paymentHash?.let {
449+
val entity = TagMetadataEntity(
450+
id = paymentHash,
451+
paymentHash = paymentHash,
452+
tags = tags,
453+
address = onChainAddress,
454+
isReceive = true,
455+
createdAt = nowTimestamp().toEpochMilli()
456+
)
449457
db.tagMetadataDao().saveTagMetadata(
450-
tagMetadata = TagMetadataEntity(
451-
id = paymentHashOrAddress,
452-
tags = tags,
453-
address = onChainAddress,
454-
isReceive = true,
455-
createdAt = nowTimestamp().toEpochMilli()
456-
)
458+
tagMetadata = entity
457459
)
460+
Logger.debug("Tag metadata saved: $entity", context = TAG)
458461
}
459462
} catch (e: Throwable) {
460463
Logger.error("saveInvoice error", e, context = TAG)
@@ -499,14 +502,13 @@ class WalletRepo @Inject constructor(
499502
}
500503
}
501504

502-
private suspend fun Scanner.OnChain.extractLightningHashOrAddress(): String {
503-
val address = this.invoice.address
504-
val lightningInvoice: String = this.invoice.params?.get("lightning") ?: address
505+
private suspend fun Scanner.OnChain.extractLightningHash(): String? {
506+
val lightningInvoice: String = this.invoice.params?.get("lightning") ?: return null
505507
val decoded = decode(lightningInvoice)
506508

507509
return when (decoded) {
508510
is Scanner.Lightning -> decoded.invoice.paymentHash.toHex()
509-
else -> address
511+
else -> null
510512
}
511513
}
512514

0 commit comments

Comments
 (0)