Skip to content

Commit

Permalink
Add type class roots to weeder and remove unused type classes. (#1767)
Browse files Browse the repository at this point in the history
  • Loading branch information
locallycompact authored Jan 2, 2025
2 parents 3cec2ff + 05e7721 commit c3fe7c1
Show file tree
Hide file tree
Showing 56 changed files with 57 additions and 418 deletions.
3 changes: 0 additions & 3 deletions hydra-cardano-api/hydra-cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,13 @@ library
Hydra.Cardano.Api.UTxO
Hydra.Cardano.Api.ValidityInterval
Hydra.Cardano.Api.Value
Hydra.Cardano.Api.VerificationKey
Hydra.Cardano.Api.Witness

-- NOTE: We only use an upper bound on cardano-api and have the other
-- dependencies on cardano-ledger* and plutus-ledger-api follow.
build-depends:
, aeson >=2
, base >=4.16
, base16-bytestring
, bytestring
, cardano-api ^>=10.1
, cardano-binary
Expand All @@ -97,5 +95,4 @@ library
, lens
, plutus-ledger-api
, QuickCheck
, serialise
, text >=2
3 changes: 0 additions & 3 deletions hydra-cardano-api/src/Cardano/Api/UTxO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ newtype UTxO' out = UTxO
, FromJSON
)

instance Traversable UTxO' where
traverse fn (UTxO m) = UTxO <$> traverse fn m

-- | Create a 'UTxO' from a list of 'TxIn' and 'out' pairs.
fromPairs :: [(TxIn, out)] -> UTxO' out
fromPairs = UTxO . Map.fromList
Expand Down
1 change: 0 additions & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ import Hydra.Cardano.Api.TxOutValue as Extras
import Hydra.Cardano.Api.UTxO as Extras
import Hydra.Cardano.Api.ValidityInterval as Extras
import Hydra.Cardano.Api.Value as Extras
import Hydra.Cardano.Api.VerificationKey ()
import Hydra.Cardano.Api.Witness as Extras

import Cardano.Api qualified
Expand Down
10 changes: 0 additions & 10 deletions hydra-cardano-api/src/Hydra/Cardano/Api/PlutusScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ fromPlutusScript =

-- * Orphans

instance IsPlutusScriptLanguage lang => ToJSON (PlutusScript lang) where
toJSON = toJSON . serialiseToTextEnvelope Nothing

instance IsPlutusScriptLanguage lang => FromJSON (PlutusScript lang) where
parseJSON v = do
env <- parseJSON v
case deserialiseFromTextEnvelope (proxyToAsType Proxy) env of
Left e -> fail $ show e
Right a -> pure a

instance Arbitrary (PlutusScript lang) where
arbitrary =
PlutusScriptSerialised . SBS.pack <$> listOf arbitrary
29 changes: 0 additions & 29 deletions hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import Hydra.Cardano.Api.Prelude hiding (left)

import Cardano.Ledger.Era qualified as Ledger
import Cardano.Ledger.Plutus.Data qualified as Ledger
import Codec.Serialise (deserialiseOrFail, serialise)
import Control.Arrow (left)
import Data.Aeson (Value (String), withText)
import Data.ByteString qualified as BS
import Data.ByteString.Base16 qualified as Base16
import PlutusLedgerApi.V3 qualified as Plutus
import Test.QuickCheck (arbitrarySizedNatural, choose, oneof, scale, sized, vector)

Expand Down Expand Up @@ -58,22 +54,6 @@ toLedgerData =

-- * Orphans

instance ToJSON ScriptData where
toJSON =
String
. decodeUtf8
. Base16.encode
. toStrict
. serialise
. toPlutusData

instance FromJSON ScriptData where
parseJSON v = do
text :: Text <- parseJSON v
either fail (pure . fromPlutusData) $ do
bytes <- Base16.decode (encodeUtf8 text)
left show $ deserialiseOrFail $ fromStrict bytes

instance Arbitrary ScriptData where
arbitrary =
scale (`div` 2) $
Expand All @@ -88,15 +68,6 @@ instance Arbitrary ScriptData where
arbitraryBS = sized $ \n ->
BS.pack <$> (choose (0, min n 64) >>= vector)

instance ToJSON HashableScriptData where
toJSON = String . decodeUtf8 . Base16.encode . serialiseToCBOR

instance FromJSON HashableScriptData where
parseJSON =
withText "HashableScriptData" $ \text -> do
bytes <- either (fail . show) pure $ Base16.decode $ encodeUtf8 text
either (fail . show) pure $ deserialiseFromCBOR (proxyToAsType Proxy) bytes

instance Arbitrary HashableScriptData where
arbitrary =
-- NOTE: Safe to use here as the data was not available in serialized form.
Expand Down
19 changes: 0 additions & 19 deletions hydra-cardano-api/src/Hydra/Cardano/Api/VerificationKey.hs

This file was deleted.

3 changes: 0 additions & 3 deletions hydra-chain-observer/src/Hydra/ChainObserver/NodeClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ data ChainObservation
}
deriving stock (Eq, Show, Generic)

instance Arbitrary ChainObservation where
arbitrary = genericArbitrary

defaultObserverHandler :: Applicative m => ObserverHandler m
defaultObserverHandler = const $ pure ()

Expand Down
1 change: 0 additions & 1 deletion hydra-cluster/bench/Bench/EndToEnd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ data Event = Event
, confirmedAt :: Maybe UTCTime
}
deriving stock (Generic, Eq, Show)
deriving anyclass (ToJSON)

processTransactions :: [HydraClient] -> [ClientDataset] -> IO (Map.Map TxId Event)
processTransactions clients clientDatasets = do
Expand Down
2 changes: 0 additions & 2 deletions hydra-cluster/bench/Bench/Summary.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DuplicateRecordFields #-}

module Bench.Summary where
Expand Down Expand Up @@ -29,7 +28,6 @@ data Summary = Summary
, quantiles :: Vector Double
}
deriving stock (Generic, Eq, Show)
deriving anyclass (ToJSON)

errorSummary :: Dataset -> HUnitFailure -> Summary
errorSummary Dataset{title, clientDatasets} (HUnitFailure sourceLocation reason) =
Expand Down
1 change: 0 additions & 1 deletion hydra-cluster/hydra-cluster.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ library
, hydra-tx
, hydra-tx:testlib
, io-classes
, iohk-monitoring
, lens
, lens-aeson
, optparse-applicative
Expand Down
8 changes: 2 additions & 6 deletions hydra-cluster/src/CardanoNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ data NodeLog
| MsgSynchronizing {percentDone :: Centi}
| MsgQueryGenesisParametersFailed {err :: Text}
deriving stock (Eq, Show, Generic)
deriving anyclass (ToJSON, FromJSON)
deriving anyclass (ToJSON)

type Port = Int

newtype NodeId = NodeId Int
deriving newtype (Eq, Show, Num, ToJSON, FromJSON)
deriving newtype (Eq, Show, Num)

-- | Configuration parameters for a single node devnet
data DevnetConfig = DevnetConfig
Expand All @@ -67,7 +67,6 @@ data DevnetConfig = DevnetConfig
-- ^ A list of port
}
deriving stock (Eq, Show, Generic)
deriving anyclass (ToJSON, FromJSON)

-- | Arguments given to the 'cardano-node' command-line to run a node.
data CardanoNodeArgs = CardanoNodeArgs
Expand Down Expand Up @@ -115,7 +114,6 @@ data PortsConfig = PortsConfig
-- ^ Other peers TCP ports.
}
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)

getCardanoNodeVersion :: IO String
getCardanoNodeVersion =
Expand Down Expand Up @@ -461,8 +459,6 @@ mkTopology peers =
data ProcessHasExited = ProcessHasExited Text ExitCode
deriving stock (Show)

instance Exception ProcessHasExited

-- | Cardano-cli wrapper to query protocol parameters. While we have also client
-- functions in Hydra.Chain.CardanoClient and Hydra.Cluster.CardanoClient,
-- sometimes we deliberately want to use the cardano-cli to ensure
Expand Down
2 changes: 1 addition & 1 deletion hydra-cluster/src/Hydra/Cluster/Faucet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data FaucetLog
= TraceResourceExhaustedHandled Text
| ReturnedFunds {returnAmount :: Coin}
deriving stock (Eq, Show, Generic)
deriving anyclass (ToJSON, FromJSON)
deriving anyclass (ToJSON)

-- | Create a specially marked "seed" UTXO containing requested 'Lovelace' by
-- redeeming funds available to the well-known faucet.
Expand Down
2 changes: 1 addition & 1 deletion hydra-cluster/src/Hydra/Cluster/Fixture.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ data KnownNetwork
| Mainnet
| Sanchonet
deriving stock (Generic, Show, Eq, Enum, Bounded)
deriving anyclass (ToJSON, FromJSON)
deriving anyclass (ToJSON)

toNetworkId :: KnownNetwork -> NetworkId
toNetworkId = \case
Expand Down
2 changes: 1 addition & 1 deletion hydra-cluster/src/Hydra/Cluster/Mithril.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ data MithrilLog
| -- | Output captured directly from mithril-client stderr.
StdErr {output :: Value}
deriving stock (Eq, Show, Generic)
deriving anyclass (ToJSON, FromJSON)
deriving anyclass (ToJSON)

-- | Downloads and unpacks latest snapshot for given network in db/ of given
-- directory.
Expand Down
8 changes: 4 additions & 4 deletions hydra-cluster/src/Hydra/Cluster/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ data Options = Options
, scenario :: Scenario
}
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)
deriving anyclass (ToJSON)

data PublishOrReuse = Publish | Reuse [TxId]
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)
deriving anyclass (ToJSON)

data UseMithril = NotUseMithril | UseMithril
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)
deriving anyclass (ToJSON)

data Scenario = Idle | RespendUTxO
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)
deriving anyclass (ToJSON)

parseOptions :: Parser Options
parseOptions =
Expand Down
2 changes: 1 addition & 1 deletion hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ data EndToEndLog
| UsingHydraScriptsAt {hydraScriptsTxId :: [TxId]}
| CreatedKey {keyPath :: FilePath}
deriving stock (Eq, Show, Generic)
deriving anyclass (ToJSON, FromJSON)
deriving anyclass (ToJSON)

restartedNodeCanObserveCommitTx :: Tracer IO EndToEndLog -> FilePath -> RunningNode -> [TxId] -> IO ()
restartedNodeCanObserveCommitTx tracer workDir cardanoNode hydraScriptsTxId = do
Expand Down
3 changes: 1 addition & 2 deletions hydra-cluster/src/HydraNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module HydraNode where
import Hydra.Cardano.Api
import Hydra.Prelude hiding (delete)

import Cardano.BM.Tracing (ToObject)
import CardanoNode (cliQueryProtocolParameters)
import Control.Concurrent.Async (forConcurrently_)
import Control.Concurrent.Class.MonadSTM (modifyTVar', newTVarIO, readTVarIO)
Expand Down Expand Up @@ -470,4 +469,4 @@ data HydraNodeLog
| ReceivedMessage {nodeId :: Int, message :: Aeson.Value}
| EndWaiting {nodeId :: Int}
deriving stock (Eq, Show, Generic)
deriving anyclass (ToJSON, FromJSON, ToObject)
deriving anyclass (ToJSON)
1 change: 0 additions & 1 deletion hydra-node/hydra-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ library
build-depends:
, aeson
, base
, base16-bytestring
, bytestring
, cardano-api:internal
, cardano-binary
Expand Down
10 changes: 1 addition & 9 deletions hydra-node/src/Hydra/API/APIServerLog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data APIServerLog
, path :: PathInfo
}
deriving stock (Eq, Show, Generic)
deriving anyclass (ToJSON, FromJSON)
deriving anyclass (ToJSON)

instance Arbitrary APIServerLog where
arbitrary =
Expand Down Expand Up @@ -50,10 +50,6 @@ instance ToJSON PathInfo where
toJSON (PathInfo bytes) =
Aeson.String $ decodeUtf8 bytes

instance FromJSON PathInfo where
parseJSON = Aeson.withText "PathInfo" $ \t ->
pure . PathInfo $ encodeUtf8 t

-- | New type wrapper to define JSON instances.
--
-- NOTE: We are not using http-types 'StdMethod' as we do not want to be
Expand All @@ -67,7 +63,3 @@ instance Arbitrary Method where
instance ToJSON Method where
toJSON (Method bytes) =
Aeson.String $ decodeUtf8 bytes

instance FromJSON Method where
parseJSON = Aeson.withText "Method" $ \t ->
pure . Method $ encodeUtf8 t
4 changes: 0 additions & 4 deletions hydra-node/src/Hydra/Chain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ data OnChainTx tx
deriving stock instance IsTx tx => Eq (OnChainTx tx)
deriving stock instance IsTx tx => Show (OnChainTx tx)
deriving anyclass instance IsTx tx => ToJSON (OnChainTx tx)
deriving anyclass instance IsTx tx => FromJSON (OnChainTx tx)

instance ArbitraryIsTx tx => Arbitrary (OnChainTx tx) where
arbitrary = genericArbitrary
Expand Down Expand Up @@ -243,8 +242,6 @@ rollbackHistory rollbackChainSlot h@UnsafeChainStateHistory{history, defaultChai

deriving stock instance Eq (ChainStateType tx) => Eq (ChainStateHistory tx)
deriving stock instance Show (ChainStateType tx) => Show (ChainStateHistory tx)
deriving anyclass instance ToJSON (ChainStateType tx) => ToJSON (ChainStateHistory tx)
deriving anyclass instance FromJSON (ChainStateType tx) => FromJSON (ChainStateHistory tx)

instance Arbitrary (ChainStateType tx) => Arbitrary (ChainStateHistory tx) where
arbitrary = genericArbitrary
Expand Down Expand Up @@ -312,7 +309,6 @@ data ChainEvent tx
deriving stock instance (IsTx tx, IsChainState tx) => Eq (ChainEvent tx)
deriving stock instance (IsTx tx, IsChainState tx) => Show (ChainEvent tx)
deriving anyclass instance (IsTx tx, IsChainState tx) => ToJSON (ChainEvent tx)
deriving anyclass instance (IsTx tx, IsChainState tx) => FromJSON (ChainEvent tx)

instance (ArbitraryIsTx tx, IsChainState tx) => Arbitrary (ChainEvent tx) where
arbitrary = genericArbitrary
Expand Down
12 changes: 0 additions & 12 deletions hydra-node/src/Hydra/Chain/CardanoClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Data.Aeson (eitherDecode', encode)
import Data.Set qualified as Set
import Data.Text qualified as Text
import Ouroboros.Consensus.Cardano.Block (EraMismatch (..))
import Test.QuickCheck (oneof)
import Text.Printf (printf)

-- XXX: This should be re-exported by cardano-api
Expand Down Expand Up @@ -198,17 +197,6 @@ awaitTransaction networkId socket tx =
data QueryPoint = QueryTip | QueryAt ChainPoint
deriving stock (Eq, Show, Generic)

deriving anyclass instance ToJSON QueryPoint

instance Arbitrary QueryPoint where
-- XXX: This is not complete as we lack an 'Arbitrary ChainPoint' and we have
-- not bothered about it yet.
arbitrary =
oneof
[ pure QueryTip
, pure $ QueryAt ChainPointAtGenesis
]

-- | Query the latest chain point aka "the tip".
queryTip :: NetworkId -> SocketPath -> IO ChainPoint
queryTip networkId socket =
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/src/Hydra/Chain/Direct/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ data DirectChainLog
| RolledBackward {point :: ChainPoint}
| Wallet TinyWalletLog
deriving stock (Eq, Show, Generic)
deriving anyclass (ToJSON, FromJSON)
deriving anyclass (ToJSON)

instance Arbitrary DirectChainLog where
arbitrary = genericArbitrary
Expand Down
Loading

0 comments on commit c3fe7c1

Please sign in to comment.