processTx
    :: ProtocolMagic
    -> TxValidationRules
    -> TxpConfiguration
    -> BlockVersionData
    -> EpochIndex
    -> (TxId, TxAux)
    -> ExceptT ToilVerFailure LocalToilM TxUndo
processTx pm txValRules txpConfig bvd curEpoch tx@(id, aux) = do
    whenM (lift $ hasTx id) $ throwError ToilKnown
    whenM ((>= memPoolLimitTx txpConfig) <$> lift memPoolSize) $
        throwError (ToilOverwhelmed $ memPoolLimitTx txpConfig)
    undo <- mapExceptT utxoMToLocalToilM $ verifyAndApplyTx pm txValRules bvd (tcAssetLockedSrcAddrs txpConfig) curEpoch True tx
    undo <$ lift (putTxWithUndo id aux undo)

-- | Get rid of invalid transactions.
-- All valid transactions will be added to mem pool and applied to utxo.
processTx
    :: ProtocolMagic
    -> TxValidationRules
    -> TxpConfiguration
    -> BlockVersionData
    -> EpochIndex
    -> (TxId, TxAux)
    -> ExceptT ToilVerFailure LocalToilM TxUndo
processTx pm txValRules txpConfig bvd curEpoch tx@(id, aux) = do
    whenM (lift $ hasTx id) $ throwError ToilKnown
    whenM ((>= memPoolLimitTx txpConfig) <$> lift memPoolSize) $
        throwError (ToilOverwhelmed $ memPoolLimitTx txpConfig)
    undo <- mapExceptT utxoMToLocalToilM $ verifyAndApplyTx pm txValRules bvd (tcAssetLockedSrcAddrs txpConfig) curEpoch True tx
    undo <$ lift (putTxWithUndo id aux undo)

-- | Get rid of invalid transactions.
-- All valid transactions will be added to mem pool and applied to utxo.
processTx pm txValRules txpConfig bvd curEpoch tx@(id, aux) = do
    whenM (lift $ hasTx id) $ throwError ToilKnown
    whenM ((>= memPoolLimitTx txpConfig) <$> lift memPoolSize) $
        throwError (ToilOverwhelmed $ memPoolLimitTx txpConfig)
    undo <- mapExceptT utxoMToLocalToilM $ verifyAndApplyTx pm txValRules bvd (tcAssetLockedSrcAddrs txpConfig) curEpoch True tx
    undo <$ lift (putTxWithUndo id aux undo)

-- | Get rid of invalid transactions.
-- All valid transactions will be added to mem pool and applied to utxo.