@@ -4,6 +4,7 @@ import com.synonym.bitkitcore.Activity
44import com.synonym.bitkitcore.ActivityFilter
55import com.synonym.bitkitcore.BtOrderState2
66import com.synonym.bitkitcore.CJitStateEnum
7+ import com.synonym.bitkitcore.ClosedChannelDetails
78import com.synonym.bitkitcore.CreateCjitOptions
89import com.synonym.bitkitcore.CreateOrderOptions
910import com.synonym.bitkitcore.FeeRates
@@ -26,6 +27,7 @@ import com.synonym.bitkitcore.deleteActivityById
2627import com.synonym.bitkitcore.estimateOrderFeeFull
2728import com.synonym.bitkitcore.getActivities
2829import com.synonym.bitkitcore.getActivityById
30+ import com.synonym.bitkitcore.getAllClosedChannels
2931import com.synonym.bitkitcore.getAllUniqueTags
3032import com.synonym.bitkitcore.getCjitEntries
3133import com.synonym.bitkitcore.getInfo
@@ -39,7 +41,13 @@ import com.synonym.bitkitcore.refreshActiveOrders
3941import com.synonym.bitkitcore.removeTags
4042import com.synonym.bitkitcore.updateActivity
4143import com.synonym.bitkitcore.updateBlocktankUrl
44+ import com.synonym.bitkitcore.upsertActivities
4245import com.synonym.bitkitcore.upsertActivity
46+ import com.synonym.bitkitcore.upsertCjitEntries
47+ import com.synonym.bitkitcore.upsertClosedChannel
48+ import com.synonym.bitkitcore.upsertClosedChannels
49+ import com.synonym.bitkitcore.upsertInfo
50+ import com.synonym.bitkitcore.upsertOrders
4351import io.ktor.client.HttpClient
4452import io.ktor.client.request.get
4553import io.ktor.http.HttpStatusCode
@@ -199,10 +207,20 @@ class ActivityService(
199207 }
200208 }
201209
202- suspend fun upsert (activity : Activity ) {
203- ServiceQueue .CORE .background {
204- upsertActivity(activity)
205- }
210+ suspend fun upsert (activity : Activity ) = ServiceQueue .CORE .background {
211+ upsertActivity(activity)
212+ }
213+
214+ suspend fun upsertList (activities : List <Activity >) = ServiceQueue .CORE .background {
215+ upsertActivities(activities)
216+ }
217+
218+ suspend fun upsertClosedChannelItem (closedChannel : ClosedChannelDetails ) = ServiceQueue .CORE .background {
219+ upsertClosedChannel(closedChannel)
220+ }
221+
222+ suspend fun upsertClosedChannelList (closedChannels : List <ClosedChannelDetails >) = ServiceQueue .CORE .background {
223+ upsertClosedChannels(closedChannels)
206224 }
207225
208226 suspend fun getActivity (id : String ): Activity ? {
@@ -267,6 +285,12 @@ class ActivityService(
267285 }
268286 }
269287
288+ suspend fun closedChannels (
289+ sortDirection : SortDirection ,
290+ ): List <ClosedChannelDetails > = ServiceQueue .CORE .background {
291+ getAllClosedChannels(sortDirection)
292+ }
293+
270294 /* *
271295 * Maps all `PaymentDetails` from LDK Node to bitkit-core [Activity] records.
272296 *
@@ -325,7 +349,7 @@ class ActivityService(
325349 }
326350 }
327351
328- private suspend fun processBolt11 (
352+ private fun processBolt11 (
329353 kind : PaymentKind .Bolt11 ,
330354 payment : PaymentDetails ,
331355 state : PaymentState ,
@@ -421,6 +445,7 @@ class ActivityService(
421445 confirmed = isConfirmed,
422446 timestamp = timestamp,
423447 isBoosted = false ,
448+ boostTxIds = emptyList(),
424449 isTransfer = false ,
425450 doesExist = true ,
426451 confirmTimestamp = confirmedTimestamp,
@@ -471,11 +496,11 @@ class ActivityService(
471496 )
472497
473498 repeat(count) { i ->
474- val isLightning = Random .Default . nextBoolean()
499+ val isLightning = Random .nextBoolean()
475500 val value = (1000 .. 1_000_000 ).random().toULong()
476501 val txTimestamp =
477502 (timestamp.toLong() - (0 .. 30L * 24 * 60 * 60 ).random()).toULong() // Random time in last 30 days
478- val txType = if (Random .Default . nextBoolean()) PaymentType .SENT else PaymentType .RECEIVED
503+ val txType = if (Random .nextBoolean()) PaymentType .SENT else PaymentType .RECEIVED
479504 val status = when ((0 .. 10 ).random()) {
480505 in 0 .. 7 -> PaymentState .SUCCEEDED // 80% chance
481506 8 -> PaymentState .PENDING // 10% chance
@@ -497,7 +522,7 @@ class ActivityService(
497522 invoice = " lnbc$value " ,
498523 message = possibleMessages.random(),
499524 timestamp = txTimestamp,
500- preimage = if (Random .Default . nextBoolean()) " preimage$i " else null ,
525+ preimage = if (Random .nextBoolean()) " preimage$i " else null ,
501526 createdAt = txTimestamp,
502527 updatedAt = txTimestamp
503528 )
@@ -513,16 +538,17 @@ class ActivityService(
513538 fee = (100 .. 10_000 ).random().toULong(),
514539 feeRate = (1 .. 100 ).random().toULong(),
515540 address = " bc1...$i " ,
516- confirmed = Random .Default . nextBoolean(),
541+ confirmed = Random .nextBoolean(),
517542 timestamp = txTimestamp,
518- isBoosted = Random .Default .nextBoolean(),
519- isTransfer = Random .Default .nextBoolean(),
543+ isBoosted = Random .nextBoolean(),
544+ boostTxIds = emptyList(),
545+ isTransfer = Random .nextBoolean(),
520546 doesExist = true ,
521- confirmTimestamp = if (Random .Default . nextBoolean()) txTimestamp + 3600 .toULong() else null ,
522- channelId = if (Random .Default . nextBoolean()) " channel$i " else null ,
547+ confirmTimestamp = if (Random .nextBoolean()) txTimestamp + 3600 .toULong() else null ,
548+ channelId = if (Random .nextBoolean()) " channel$i " else null ,
523549 transferTxId = null ,
524550 createdAt = txTimestamp,
525- updatedAt = txTimestamp
551+ updatedAt = txTimestamp,
526552 )
527553 )
528554 }
@@ -664,6 +690,18 @@ class BlocktankService(
664690 }
665691 }
666692
693+ suspend fun setInfo (info : IBtInfo ) = ServiceQueue .CORE .background {
694+ upsertInfo(info)
695+ }
696+
697+ suspend fun upsertOrderList (orders : List <IBtOrder >) = ServiceQueue .CORE .background {
698+ upsertOrders(orders)
699+ }
700+
701+ suspend fun upsertCjitList (cjitEntries : List <IcJitEntry >) = ServiceQueue .CORE .background {
702+ upsertCjitEntries(cjitEntries)
703+ }
704+
667705 // MARK: - Regtest methods
668706 suspend fun regtestMine (count : UInt = 1u) {
669707 com.synonym.bitkitcore.regtestMine(count = count)
0 commit comments