@@ -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