buildDynamicTxMeta :: HD.AssuranceLevel -> SlotCount -> HD.CombinedWithAccountState (Maybe SlotId) -> SlotId -> Bool -> (V1.TransactionStatus, Word64)
buildDynamicTxMeta assuranceLevel slotCount mSlotwithState currentSlot isPending =
    let currentSlot' = flattenSlotId slotCount currentSlot
        goWithSlot confirmedIn =
            let confirmedIn'  = flattenSlotId slotCount confirmedIn
                confirmations = currentSlot' - confirmedIn'
            in case (confirmations < getBlockCount (HD.assuredBlockDepth assuranceLevel)) of
                True  -> (V1.InNewestBlocks, confirmations)
                False -> (V1.Persisted, confirmations)
    in case isPending of
        True  -> (V1.Applying, 0)
        False ->
            case mSlotwithState of
                HD.UpToDate Nothing     -> (V1.WontApply, 0)
                HD.Incomplete Nothing   -> (V1.Applying, 0)  -- during restoration, we report txs not found yet as Applying.
                HD.UpToDate (Just sl)   -> goWithSlot sl
                HD.Incomplete (Just sl) -> goWithSlot sl

-- | We don`t fitler in memory, so totalEntries is unknown, unless TxMeta Database counts them for us.
-- It is possible due to some error, to have length ls < Page.
-- This can happen when a Tx is found without Inputs.
buildDynamicTxMeta :: HD.AssuranceLevel -> SlotCount -> HD.CombinedWithAccountState (Maybe SlotId) -> SlotId -> Bool -> (V1.TransactionStatus, Word64)
buildDynamicTxMeta assuranceLevel slotCount mSlotwithState currentSlot isPending =
    let currentSlot' = flattenSlotId slotCount currentSlot
        goWithSlot confirmedIn =
            let confirmedIn'  = flattenSlotId slotCount confirmedIn
                confirmations = currentSlot' - confirmedIn'
            in case (confirmations < getBlockCount (HD.assuredBlockDepth assuranceLevel)) of
                True  -> (V1.InNewestBlocks, confirmations)
                False -> (V1.Persisted, confirmations)
    in case isPending of
        True  -> (V1.Applying, 0)
        False ->
            case mSlotwithState of
                HD.UpToDate Nothing     -> (V1.WontApply, 0)
                HD.Incomplete Nothing   -> (V1.Applying, 0)  -- during restoration, we report txs not found yet as Applying.
                HD.UpToDate (Just sl)   -> goWithSlot sl
                HD.Incomplete (Just sl) -> goWithSlot sl

-- | We don`t fitler in memory, so totalEntries is unknown, unless TxMeta Database counts them for us.
-- It is possible due to some error, to have length ls < Page.
-- This can happen when a Tx is found without Inputs.
buildDynamicTxMeta assuranceLevel slotCount mSlotwithState currentSlot isPending =
    let currentSlot' = flattenSlotId slotCount currentSlot
        goWithSlot confirmedIn =
            let confirmedIn'  = flattenSlotId slotCount confirmedIn
                confirmations = currentSlot' - confirmedIn'
            in case (confirmations < getBlockCount (HD.assuredBlockDepth assuranceLevel)) of
                True  -> (V1.InNewestBlocks, confirmations)
                False -> (V1.Persisted, confirmations)
    in case isPending of
        True  -> (V1.Applying, 0)
        False ->
            case mSlotwithState of
                HD.UpToDate Nothing     -> (V1.WontApply, 0)
                HD.Incomplete Nothing   -> (V1.Applying, 0)  -- during restoration, we report txs not found yet as Applying.
                HD.UpToDate (Just sl)   -> goWithSlot sl
                HD.Incomplete (Just sl) -> goWithSlot sl

-- | We don`t fitler in memory, so totalEntries is unknown, unless TxMeta Database counts them for us.
-- It is possible due to some error, to have length ls < Page.
-- This can happen when a Tx is found without Inputs.