diff --git a/ouroboros-consensus/ouroboros-consensus-mock/src/Ouroboros/Consensus/Mock/Ledger/Block.hs b/ouroboros-consensus/ouroboros-consensus-mock/src/Ouroboros/Consensus/Mock/Ledger/Block.hs index b2facece1d6..f4549aa2f1c 100644 --- a/ouroboros-consensus/ouroboros-consensus-mock/src/Ouroboros/Consensus/Mock/Ledger/Block.hs +++ b/ouroboros-consensus/ouroboros-consensus-mock/src/Ouroboros/Consensus/Mock/Ledger/Block.hs @@ -223,14 +223,14 @@ instance (SimpleCrypto c, Typeable ext) => HasHeader (SimpleBlock c ext) where instance (SimpleCrypto c, Typeable ext) => StandardHash (SimpleBlock c ext) {------------------------------------------------------------------------------- - HasTxs instance + HasMockTxs instance -------------------------------------------------------------------------------} -instance Mock.HasTxs (SimpleBlock' c ext ext') where - getTxs = Mock.getTxs . simpleBody +instance Mock.HasMockTxs (SimpleBlock' c ext ext') where + getMockTxs = Mock.getMockTxs . simpleBody -instance Mock.HasTxs SimpleBody where - getTxs = simpleTxs +instance Mock.HasMockTxs SimpleBody where + getMockTxs = simpleTxs {------------------------------------------------------------------------------- Envelope validation @@ -320,7 +320,7 @@ updateSimpleLedgerState :: (SimpleCrypto c, Typeable ext) updateSimpleLedgerState b (SimpleLedgerState st) = SimpleLedgerState <$> updateMockState b st -updateSimpleUTxO :: Mock.HasTxs a +updateSimpleUTxO :: Mock.HasMockTxs a => a -> TickedLedgerState (SimpleBlock c ext) -> Except (MockError (SimpleBlock c ext)) @@ -364,8 +364,8 @@ instance (Typeable p, Typeable c) => NoUnexpectedThunks (GenTx (SimpleBlock p c) instance HasTxs (SimpleBlock c ext) where extractTxs = map mkSimpleGenTx . simpleTxs . simpleBody -instance Mock.HasTxs (GenTx (SimpleBlock p c)) where - getTxs = Mock.getTxs . simpleGenTx +instance Mock.HasMockTxs (GenTx (SimpleBlock p c)) where + getMockTxs = Mock.getMockTxs . simpleGenTx instance Condense (GenTx (SimpleBlock p c)) where condense = condense . simpleGenTx diff --git a/ouroboros-consensus/ouroboros-consensus-mock/src/Ouroboros/Consensus/Mock/Ledger/State.hs b/ouroboros-consensus/ouroboros-consensus-mock/src/Ouroboros/Consensus/Mock/Ledger/State.hs index ced3000717e..c47e6b96611 100644 --- a/ouroboros-consensus/ouroboros-consensus-mock/src/Ouroboros/Consensus/Mock/Ledger/State.hs +++ b/ouroboros-consensus/ouroboros-consensus-mock/src/Ouroboros/Consensus/Mock/Ledger/State.hs @@ -62,7 +62,7 @@ deriving instance Serialise (HeaderHash blk) => Serialise (MockError blk) updateMockState :: ( GetHeader blk , HasHeader (Header blk) , StandardHash blk - , HasTxs blk + , HasMockTxs blk ) => blk -> MockState blk @@ -82,12 +82,12 @@ updateMockTip hdr (MockState u c t) | otherwise = throwError $ MockInvalidHash (headerPrevHash hdr) (pointHash t) -updateMockUTxO :: HasTxs a +updateMockUTxO :: HasMockTxs a => SlotNo -> a -> MockState blk -> Except (MockError blk) (MockState blk) -updateMockUTxO now = repeatedlyM (updateMockUTxO1 now) . getTxs +updateMockUTxO now = repeatedlyM (updateMockUTxO1 now) . getMockTxs updateMockUTxO1 :: forall blk. SlotNo diff --git a/ouroboros-consensus/ouroboros-consensus-mock/src/Ouroboros/Consensus/Mock/Ledger/UTxO.hs b/ouroboros-consensus/ouroboros-consensus-mock/src/Ouroboros/Consensus/Mock/Ledger/UTxO.hs index e123476d77d..1b678010c3e 100644 --- a/ouroboros-consensus/ouroboros-consensus-mock/src/Ouroboros/Consensus/Mock/Ledger/UTxO.hs +++ b/ouroboros-consensus/ouroboros-consensus-mock/src/Ouroboros/Consensus/Mock/Ledger/UTxO.hs @@ -17,7 +17,7 @@ module Ouroboros.Consensus.Mock.Ledger.UTxO ( , Utxo , Expiry(..) -- * Computing UTxO - , HasTxs(..) + , HasMockTxs(..) , txIns , txOuts , confirmed @@ -104,25 +104,27 @@ data UtxoError instance Condense UtxoError where condense = show -class HasTxs a where - getTxs :: a -> [Tx] +class HasMockTxs a where + -- | The transactions in the order they are to be applied + -- + getMockTxs :: a -> [Tx] -instance HasTxs Tx where - getTxs = (:[]) +instance HasMockTxs Tx where + getMockTxs = (:[]) -instance HasTxs a => HasTxs [a] where - getTxs = concatMap getTxs +instance HasMockTxs a => HasMockTxs [a] where + getMockTxs = concatMap getMockTxs -instance HasTxs a => HasTxs (Chain a) where - getTxs = getTxs . toOldestFirst +instance HasMockTxs a => HasMockTxs (Chain a) where + getMockTxs = getMockTxs . toOldestFirst -txIns :: HasTxs a => a -> Set TxIn -txIns = Set.unions . map each . getTxs +txIns :: HasMockTxs a => a -> Set TxIn +txIns = Set.unions . map each . getMockTxs where each (Tx _expiry ins _outs) = ins -txOuts :: HasTxs a => a -> Utxo -txOuts = Map.unions . map each . getTxs +txOuts :: HasMockTxs a => a -> Utxo +txOuts = Map.unions . map each . getMockTxs where each tx@(Tx _expiry _ins outs) = Map.fromList $ zipWith aux [0..] outs @@ -130,11 +132,11 @@ txOuts = Map.unions . map each . getTxs aux :: Ix -> TxOut -> (TxIn, TxOut) aux ix out = ((hash tx, ix), out) -confirmed :: HasTxs a => a -> Set TxId -confirmed = Set.fromList . map hash . getTxs +confirmed :: HasMockTxs a => a -> Set TxId +confirmed = Set.fromList . map hash . getMockTxs -updateUtxo :: HasTxs a => a -> Utxo -> Except UtxoError Utxo -updateUtxo = repeatedlyM each . getTxs +updateUtxo :: HasMockTxs a => a -> Utxo -> Except UtxoError Utxo +updateUtxo = repeatedlyM each . getMockTxs where each tx = execStateT $ do -- Remove all inputs from the Utxo and calculate the sum of all the