metaToTx :: Monad m => Kernel.DB -> SlotCount -> SlotId -> TxMeta -> ExceptT HD.UnknownHdAccount m V1.Transaction
metaToTx db slotCount current TxMeta{..} = do
    mSlotwithState <- withExceptT identity $ exceptT $
                        Kernel.currentTxSlotId db _txMetaId hdAccountId
    isPending      <- withExceptT identity $ exceptT $
                        Kernel.currentTxIsPending db _txMetaId hdAccountId
    assuranceLevel <- withExceptT HD.embedUnknownHdRoot $ exceptT $
                        Kernel.rootAssuranceLevel db hdRootId
    let (status, confirmations) = buildDynamicTxMeta assuranceLevel slotCount mSlotwithState current isPending
    return V1.Transaction {
        txId = V1 _txMetaId,
        txConfirmations = fromIntegral confirmations,
        txAmount = V1 _txMetaAmount,
        txInputs = inputsToPayDistr <$> _txMetaInputs,
        txOutputs = outputsToPayDistr <$> _txMetaOutputs,
        txType = if _txMetaIsLocal then V1.LocalTransaction else V1.ForeignTransaction,
        txDirection = if _txMetaIsOutgoing then V1.OutgoingTransaction else V1.IncomingTransaction,
        txCreationTime = V1 _txMetaCreationAt,
        txStatus = status
    }
        where
            hdRootId    = HD.HdRootId $ InDb _txMetaWalletId
            hdAccountId = HD.HdAccountId hdRootId (HD.HdAccountIx _txMetaAccountIx)

            inputsToPayDistr :: (a , b, Address, Coin) -> V1.PaymentDistribution
            inputsToPayDistr (_, _, addr, c) = V1.PaymentDistribution (V1 addr) (V1 c)

            outputsToPayDistr :: (Address, Coin) -> V1.PaymentDistribution
            outputsToPayDistr (addr, c) = V1.PaymentDistribution (V1 addr) (V1 c)
metaToTx :: Monad m => Kernel.DB -> SlotCount -> SlotId -> TxMeta -> ExceptT HD.UnknownHdAccount m V1.Transaction
metaToTx db slotCount current TxMeta{..} = do
    mSlotwithState <- withExceptT identity $ exceptT $
                        Kernel.currentTxSlotId db _txMetaId hdAccountId
    isPending      <- withExceptT identity $ exceptT $
                        Kernel.currentTxIsPending db _txMetaId hdAccountId
    assuranceLevel <- withExceptT HD.embedUnknownHdRoot $ exceptT $
                        Kernel.rootAssuranceLevel db hdRootId
    let (status, confirmations) = buildDynamicTxMeta assuranceLevel slotCount mSlotwithState current isPending
    return V1.Transaction {
        txId = V1 _txMetaId,
        txConfirmations = fromIntegral confirmations,
        txAmount = V1 _txMetaAmount,
        txInputs = inputsToPayDistr <$> _txMetaInputs,
        txOutputs = outputsToPayDistr <$> _txMetaOutputs,
        txType = if _txMetaIsLocal then V1.LocalTransaction else V1.ForeignTransaction,
        txDirection = if _txMetaIsOutgoing then V1.OutgoingTransaction else V1.IncomingTransaction,
        txCreationTime = V1 _txMetaCreationAt,
        txStatus = status
    }
        where
            hdRootId    = HD.HdRootId $ InDb _txMetaWalletId
            hdAccountId = HD.HdAccountId hdRootId (HD.HdAccountIx _txMetaAccountIx)

            inputsToPayDistr :: (a , b, Address, Coin) -> V1.PaymentDistribution
            inputsToPayDistr (_, _, addr, c) = V1.PaymentDistribution (V1 addr) (V1 c)

            outputsToPayDistr :: (Address, Coin) -> V1.PaymentDistribution
            outputsToPayDistr (addr, c) = V1.PaymentDistribution (V1 addr) (V1 c)
metaToTx db slotCount current TxMeta{..} = do
    mSlotwithState <- withExceptT identity $ exceptT $
                        Kernel.currentTxSlotId db _txMetaId hdAccountId
    isPending      <- withExceptT identity $ exceptT $
                        Kernel.currentTxIsPending db _txMetaId hdAccountId
    assuranceLevel <- withExceptT HD.embedUnknownHdRoot $ exceptT $
                        Kernel.rootAssuranceLevel db hdRootId
    let (status, confirmations) = buildDynamicTxMeta assuranceLevel slotCount mSlotwithState current isPending
    return V1.Transaction {
        txId = V1 _txMetaId,
        txConfirmations = fromIntegral confirmations,
        txAmount = V1 _txMetaAmount,
        txInputs = inputsToPayDistr <$> _txMetaInputs,
        txOutputs = outputsToPayDistr <$> _txMetaOutputs,
        txType = if _txMetaIsLocal then V1.LocalTransaction else V1.ForeignTransaction,
        txDirection = if _txMetaIsOutgoing then V1.OutgoingTransaction else V1.IncomingTransaction,
        txCreationTime = V1 _txMetaCreationAt,
        txStatus = status
    }
        where
            hdRootId    = HD.HdRootId $ InDb _txMetaWalletId
            hdAccountId = HD.HdAccountId hdRootId (HD.HdAccountIx _txMetaAccountIx)

            inputsToPayDistr :: (a , b, Address, Coin) -> V1.PaymentDistribution
            inputsToPayDistr (_, _, addr, c) = V1.PaymentDistribution (V1 addr) (V1 c)

            outputsToPayDistr :: (Address, Coin) -> V1.PaymentDistribution
            outputsToPayDistr (addr, c) = V1.PaymentDistribution (V1 addr) (V1 c)