Skip to content

Commit

Permalink
Add and implement getTx
Browse files Browse the repository at this point in the history
  • Loading branch information
intricate committed Jun 26, 2019
1 parent 20cac90 commit 706b772
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ouroboros-consensus/src/Ouroboros/Consensus/Mempool/API.hs
Expand Up @@ -107,6 +107,9 @@ data Mempool m blk idx = Mempool {
-- transaction/.
, getTxs :: STM m (Seq (GenTx blk, idx))

-- |
, getTx :: idx -> STM m (Maybe (GenTx blk))

-- |
, zeroIdx :: idx
}
10 changes: 9 additions & 1 deletion ouroboros-consensus/src/Ouroboros/Consensus/Mempool/Impl.hs
Expand Up @@ -21,7 +21,7 @@ import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.Extended
import Ouroboros.Consensus.Mempool.API
import Ouroboros.Consensus.Mempool.TxSeq (TicketNo, TxSeq (..),
appendTx, fromTxSeq, zeroTicketNo)
appendTx, fromTxSeq, lookupByTicketNo, zeroTicketNo)
import qualified Ouroboros.Consensus.Mempool.TxSeq as TxSeq
import Ouroboros.Consensus.Util (repeatedly)

Expand All @@ -38,6 +38,7 @@ openMempool chainDB cfg = do
return Mempool {
addTxs = implAddTxs env
, getTxs = implGetTxs env
, getTx = implGetTx env
, zeroIdx = zeroTicketNo
}

Expand Down Expand Up @@ -109,6 +110,13 @@ implGetTxs mpEnv@MempoolEnv{mpEnvStateVar} = do
}
pure $ fromTxSeq vrValid

implGetTx :: (MonadSTM m, ApplyTx blk)
=> MempoolEnv m blk hdr
-> TicketNo
-> STM m (Maybe (GenTx blk))
implGetTx MempoolEnv{mpEnvStateVar} tn =
(`lookupByTicketNo` tn) . isTxs <$> readTVar mpEnvStateVar

{-------------------------------------------------------------------------------
Validation
-------------------------------------------------------------------------------}
Expand Down

0 comments on commit 706b772

Please sign in to comment.