Skip to content

Commit

Permalink
Moved ToExpr instances to modules where the type is defined. Removed …
Browse files Browse the repository at this point in the history
…the ToExprOrphans module.
  • Loading branch information
TimSheard committed Dec 2, 2022
1 parent 39ac9e7 commit f4f60f8
Show file tree
Hide file tree
Showing 31 changed files with 245 additions and 246 deletions.
3 changes: 1 addition & 2 deletions eras/shelley-ma/impl/src/Cardano/Ledger/Mary/Value.hs
Expand Up @@ -57,9 +57,8 @@ import Cardano.Ledger.Binary.Coders
import Cardano.Ledger.Coin (Coin (..), CompactForm (..), integerToWord64)
import Cardano.Ledger.Compactible (Compactible (..))
import qualified Cardano.Ledger.Crypto as CC
import Cardano.Ledger.Shelley.LedgerState.ToExprOrphans (trimExprViaShow)
import Cardano.Ledger.Shelley.Scripts (ScriptHash (..))
import Cardano.Ledger.TreeDiff (Expr (App), ToExpr (..))
import Cardano.Ledger.TreeDiff (Expr (App), ToExpr (..), trimExprViaShow)
import Cardano.Ledger.Val (DecodeNonNegative (..), Val (..))
import Control.DeepSeq (NFData (..), deepseq, rwhnf)
import Control.Monad (forM_)
Expand Down
Expand Up @@ -13,7 +13,6 @@ import Cardano.Ledger.Core
import Cardano.Ledger.Mary (MaryEra)
import Cardano.Ledger.Shelley.API (LedgerEnv (..), ShelleyLEDGER)
import Cardano.Ledger.Shelley.LedgerState (LedgerState (..), UTxOState (..), smartUTxOState)
import Cardano.Ledger.Shelley.LedgerState.ToExprOrphans ()
import Cardano.Ledger.Shelley.PParams (ShelleyPParamsHKD (..))
import Cardano.Ledger.Shelley.Tx (ShelleyTx (..))
import Cardano.Ledger.ShelleyMA.Rules ()
Expand Down
3 changes: 0 additions & 3 deletions eras/shelley/impl/cardano-ledger-shelley.cabal
Expand Up @@ -69,7 +69,6 @@ library
Cardano.Ledger.Shelley.TxOut
Cardano.Ledger.Shelley.UTxO
Cardano.Ledger.Shelley.LedgerState.DPState
Cardano.Ledger.Shelley.LedgerState.ToExprOrphans
other-modules:
Cardano.Ledger.Shelley.Era
Cardano.Ledger.Shelley.LedgerState.Types
Expand Down Expand Up @@ -112,11 +111,9 @@ library
deepseq,
groups,
heapwords,
iproute,
mtl,
microlens,
nothunks,
primitive,
quiet,
set-algebra,
small-steps,
Expand Down
Expand Up @@ -70,6 +70,7 @@ import Cardano.Ledger.Slot
( EpochNo (..),
SlotNo (..),
)
import Cardano.Ledger.TreeDiff (ToExpr)
import Cardano.Ledger.UnifiedMap (UMap (UnifiedMap), UnifiedMap, View (Delegations, Rewards), ViewMap)
import Cardano.Ledger.Val ((<+>), (<×>))
import Control.DeepSeq (NFData)
Expand Down Expand Up @@ -418,3 +419,15 @@ keyTxRefunds ::
TxBody era ->
Coin
keyTxRefunds pp dpstate tx = keyCertsRefunds pp dpstate (toList $ tx ^. certsTxBodyL)

-- =====================================================

instance ToExpr (DPState c)

instance ToExpr (PState c)

instance ToExpr (DState c)

instance ToExpr (FutureGenDeleg c)

instance ToExpr (InstantaneousRewards c)

This file was deleted.

35 changes: 35 additions & 0 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState/Types.hs
Expand Up @@ -57,6 +57,7 @@ import Cardano.Ledger.Shelley.RewardUpdate
( PulsingRewUpdate (..),
)
import Cardano.Ledger.Slot (EpochNo (..))
import Cardano.Ledger.TreeDiff (ToExpr)
import Cardano.Ledger.UTxO (UTxO (..))
import Control.DeepSeq (NFData)
import Control.Monad.State.Strict (evalStateT)
Expand Down Expand Up @@ -518,3 +519,37 @@ instance Default (UTxOState era) => Default (LedgerState era) where

instance Default AccountState where
def = AccountState (Coin 0) (Coin 0)

-- =============================================================
-- TreeDiff ToExpr instances

instance ToExpr AccountState

instance
( ToExpr (TxOut era),
ToExpr (State (EraRule "PPUP" era)),
ToExpr (PParams era),
ToExpr (StashedAVVMAddresses era)
) =>
ToExpr (NewEpochState era)

instance
( ToExpr (TxOut era),
ToExpr (State (EraRule "PPUP" era)),
ToExpr (PParams era)
) =>
ToExpr (EpochState era)

instance
( ToExpr (TxOut era),
ToExpr (State (EraRule "PPUP" era))
) =>
ToExpr (LedgerState era)

instance
( ToExpr (TxOut era),
ToExpr (State (EraRule "PPUP" era))
) =>
ToExpr (UTxOState era)

instance ToExpr (IncrementalStake c)
11 changes: 11 additions & 0 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/PParams.hs
Expand Up @@ -70,6 +70,7 @@ import Cardano.Ledger.Keys (GenDelegs, KeyHash, KeyRole (..))
import Cardano.Ledger.Orphans ()
import Cardano.Ledger.Shelley.Era (ShelleyEra)
import Cardano.Ledger.Slot (EpochNo (..), SlotNo (..))
import Cardano.Ledger.TreeDiff (ToExpr)
import Control.DeepSeq (NFData)
import Control.Monad (unless)
import Data.Aeson (FromJSON (..), ToJSON (..), (.!=), (.:), (.:?), (.=))
Expand Down Expand Up @@ -513,3 +514,13 @@ pvCanFollow :: BT.ProtVer -> StrictMaybe BT.ProtVer -> Bool
pvCanFollow _ SNothing = True
pvCanFollow (BT.ProtVer m n) (SJust (BT.ProtVer m' n')) =
(succVersion m, 0) == (Just m', n') || (m, n + 1) == (m', n')

-- ==============================================

instance ToExpr (Core.PParamsUpdate era) => ToExpr (PPUPState era)

instance ToExpr (Core.PParamsUpdate era) => ToExpr (ProposedPPUpdates era)

instance ToExpr (ShelleyPParamsHKD StrictMaybe era)

instance ToExpr (ShelleyPParamsHKD Identity era)
9 changes: 9 additions & 0 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/PoolRank.hs
Expand Up @@ -53,6 +53,7 @@ import Cardano.Ledger.EpochBoundary (maxPool)
import Cardano.Ledger.Keys (KeyHash, KeyRole (..))
import Cardano.Ledger.Shelley.Rewards (StakeShare (..), memberRew)
import Cardano.Ledger.Shelley.TxBody (PoolParams (..))
import Cardano.Ledger.TreeDiff (ToExpr)
import Cardano.Slotting.Slot (EpochSize (..))
import Control.DeepSeq (NFData)
import Control.Monad.Trans
Expand Down Expand Up @@ -374,3 +375,11 @@ nonMyopicMemberRew
f = maxPool pp rPot (unStakeShare nm) (unStakeShare s)
fHat = floor (p * (fromRational . coinToRational) f)
in memberRew (Coin fHat) pool t nm

-- =====================================================================

instance ToExpr Likelihood

instance ToExpr LogWeight

instance ToExpr (NonMyopic c)

0 comments on commit f4f60f8

Please sign in to comment.