@@ -3,6 +3,9 @@ package to.bitkit.repositories
33import com.synonym.bitkitcore.Activity
44import com.synonym.bitkitcore.Activity.Onchain
55import com.synonym.bitkitcore.ActivityFilter
6+ import com.synonym.bitkitcore.IcJitEntry
7+ import com.synonym.bitkitcore.LightningActivity
8+ import com.synonym.bitkitcore.PaymentState
69import com.synonym.bitkitcore.PaymentType
710import com.synonym.bitkitcore.SortDirection
811import kotlinx.coroutines.CoroutineDispatcher
@@ -14,6 +17,7 @@ import kotlinx.coroutines.flow.first
1417import kotlinx.coroutines.flow.map
1518import kotlinx.coroutines.withContext
1619import kotlinx.coroutines.withTimeout
20+ import org.lightningdevkit.ldknode.ChannelDetails
1721import org.lightningdevkit.ldknode.PaymentDetails
1822import to.bitkit.data.AppDb
1923import to.bitkit.data.CacheStore
@@ -22,6 +26,7 @@ import to.bitkit.data.dto.PendingBoostActivity
2226import to.bitkit.data.dto.TransferType
2327import to.bitkit.data.entities.TagMetadataEntity
2428import to.bitkit.di.BgDispatcher
29+ import to.bitkit.ext.amountOnClose
2530import to.bitkit.ext.matchesPaymentId
2631import to.bitkit.ext.nowTimestamp
2732import to.bitkit.ext.rawId
@@ -504,6 +509,41 @@ class ActivityRepo @Inject constructor(
504509 }
505510 }
506511
512+ /* *
513+ * Inserts a new activity for a fulfilled (channel ready) cjit channel order
514+ */
515+ suspend fun insertActivityFromCjit (
516+ cjitEntry : IcJitEntry ? ,
517+ channel : ChannelDetails ,
518+ ): Result <Unit > = withContext(bgDispatcher) {
519+ runCatching {
520+ requireNotNull(cjitEntry)
521+
522+ val amount = channel.amountOnClose
523+ val now = nowTimestamp().epochSecond.toULong()
524+
525+ return @withContext insertActivity(
526+ Activity .Lightning (
527+ LightningActivity (
528+ id = channel.fundingTxo?.txid.orEmpty(),
529+ txType = PaymentType .RECEIVED ,
530+ status = PaymentState .SUCCEEDED ,
531+ value = amount,
532+ fee = 0U ,
533+ invoice = cjitEntry.invoice.request,
534+ message = " " ,
535+ timestamp = now,
536+ preimage = null ,
537+ createdAt = now,
538+ updatedAt = null ,
539+ )
540+ )
541+ )
542+ }.onFailure { e ->
543+ Logger .error(" insertActivity error" , e, context = TAG )
544+ }
545+ }
546+
507547 suspend fun addActivityToPendingBoost (pendingBoostActivity : PendingBoostActivity ) = withContext(bgDispatcher) {
508548 cacheStore.addActivityToPendingBoost(pendingBoostActivity)
509549 }
0 commit comments