@@ -17,6 +17,7 @@ import org.lightningdevkit.ldknode.Txid
1717import to.bitkit.data.dto.PendingBoostActivity
1818import to.bitkit.ext.BoostType
1919import to.bitkit.ext.boostType
20+ import to.bitkit.ext.nowMillis
2021import to.bitkit.ext.nowTimestamp
2122import to.bitkit.models.TransactionSpeed
2223import to.bitkit.repositories.ActivityRepo
@@ -203,6 +204,8 @@ class BoostTransactionViewModel @Inject constructor(
203204 destinationAddress = walletRepo.getOnchainAddress(),
204205 ).fold(
205206 onSuccess = { newTxId ->
207+ // For CPFP, immediately update parent with child txId
208+ Logger .debug(" CPFP successful. Appending child txId $newTxId to parent's boostTxIds" , context = TAG )
206209 handleBoostSuccess(newTxId, isRBF = false )
207210 },
208211 onFailure = { error ->
@@ -283,7 +286,7 @@ class BoostTransactionViewModel @Inject constructor(
283286 /* *
284287 * Updates activity based on boost type:
285288 * - RBF: Updates current activity with boost data, then replaces with new transaction
286- * - CPFP: Simply updates the current activity
289+ * - CPFP: Updates parent activity by appending child txId to boostTxIds
287290 */
288291 private suspend fun updateActivity (newTxId : Txid , isRBF : Boolean ): Result <Unit > {
289292 Logger .debug(" Updating activity for txId: $newTxId . isRBF: $isRBF " , context = TAG )
@@ -294,24 +297,25 @@ class BoostTransactionViewModel @Inject constructor(
294297 return if (isRBF) {
295298 handleRBFUpdate(newTxId, currentActivity)
296299 } else {
297- handleCPFPUpdate(currentActivity)
300+ handleCPFPUpdate(currentActivity, newTxId )
298301 }
299302 }
300303
301304 /* *
302- * Handles CPFP (Child Pays For Parent) update by simply updating the current activity
305+ * Handles CPFP (Child Pays For Parent) update by appending child txId to parent's boostTxIds
303306 */
304- private suspend fun handleCPFPUpdate (currentActivity : OnchainActivity ): Result <Unit > {
307+ private suspend fun handleCPFPUpdate (currentActivity : OnchainActivity , childTxId : Txid ): Result <Unit > {
305308 val updatedActivity = Activity .Onchain (
306309 v1 = currentActivity.copy(
307310 isBoosted = true ,
308- updatedAt = nowTimestamp().toEpochMilli().toULong()
311+ boostTxIds = currentActivity.boostTxIds + childTxId,
312+ updatedAt = nowMillis().toULong(),
309313 )
310314 )
311315
312316 return activityRepo.updateActivity(
313317 id = updatedActivity.v1.id,
314- activity = updatedActivity
318+ activity = updatedActivity,
315319 )
316320 }
317321
@@ -328,13 +332,13 @@ class BoostTransactionViewModel @Inject constructor(
328332 isBoosted = true ,
329333 feeRate = _uiState .value.feeRate,
330334 fee = _uiState .value.totalFeeSats,
331- updatedAt = nowTimestamp ().toEpochMilli(). toULong()
335+ updatedAt = nowMillis ().toULong(),
332336 )
333337 )
334338
335339 activityRepo.updateActivity(
336340 id = updatedCurrentActivity.v1.id,
337- activity = updatedCurrentActivity
341+ activity = updatedCurrentActivity,
338342 )
339343
340344 // Then find and replace with the new activity
@@ -379,7 +383,7 @@ class BoostTransactionViewModel @Inject constructor(
379383 v1 = newOnChainActivity.v1.copy(
380384 isBoosted = true ,
381385 feeRate = _uiState .value.feeRate,
382- updatedAt = nowTimestamp ().toEpochMilli(). toULong()
386+ updatedAt = nowMillis ().toULong(),
383387 )
384388 )
385389
@@ -412,13 +416,25 @@ class BoostTransactionViewModel @Inject constructor(
412416
413417 /* *
414418 * Caches activity data for pending boost operation
419+ * - For RBF: stores parent chain (existing boostTxIds + current txId)
420+ * - For CPFP: stores empty list (child tx is added to parent's boostTxIds during sync)
415421 */
416422 private suspend fun cachePendingBoostActivity (newTxId : Txid , activityToDelete : String? ) {
423+ val currentActivity = activity?.v1
424+ val boostTxIds = if (activityToDelete != null && currentActivity != null ) {
425+ // RBF: Track full parent chain (existing boostTxIds + current txId being replaced)
426+ currentActivity.boostTxIds + currentActivity.txId
427+ } else {
428+ // CPFP: No parent tracking needed
429+ emptyList()
430+ }
431+
417432 activityRepo.addActivityToPendingBoost(
418433 PendingBoostActivity (
419434 txId = newTxId,
420- updatedAt = nowTimestamp().toEpochMilli().toULong(),
421- activityToDelete = activityToDelete
435+ updatedAt = nowMillis().toULong(),
436+ activityToDelete = activityToDelete,
437+ boostTxIds = boostTxIds,
422438 )
423439 )
424440 }
0 commit comments