Skip to content

Commit

Permalink
Apply formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Jul 9, 2024
1 parent a64ffc3 commit f2363ec
Show file tree
Hide file tree
Showing 42 changed files with 1,225 additions and 1,249 deletions.
2 changes: 1 addition & 1 deletion cardano-api-gen/src/Test/Gen/Cardano/Api/Empty.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Test.Gen.Cardano.Api.Empty where

import Test.Gen.Cardano.Api ()
import Test.Gen.Cardano.Api ()

-- | This module is empty, but it is needed to prevent unused-packages warning
61 changes: 32 additions & 29 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,51 +126,54 @@ module Test.Gen.Cardano.Api.Typed
)
where

import Cardano.Api hiding (txIns)
import Cardano.Api hiding (txIns)
import qualified Cardano.Api as Api
import Cardano.Api.Byron
( KeyWitness (ByronKeyWitness)
, WitnessNetworkIdOrByronAddress (..)
)
import Cardano.Api.Byron (KeyWitness (ByronKeyWitness),
WitnessNetworkIdOrByronAddress (..))
import qualified Cardano.Api.Byron as Byron
import Cardano.Api.Eon.AllegraEraOnwards (allegraEraOnwardsToShelleyBasedEra)
import Cardano.Api.Error
import Cardano.Api.Eon.AllegraEraOnwards (allegraEraOnwardsToShelleyBasedEra)
import Cardano.Api.Error
import qualified Cardano.Api.Ledger as L
import qualified Cardano.Api.Ledger.Lens as A
import Cardano.Api.Script (scriptInEraToRefScript)
import Cardano.Api.Shelley
import Cardano.Api.Script (scriptInEraToRefScript)
import Cardano.Api.Shelley
import qualified Cardano.Api.Shelley as ShelleyApi

import qualified Cardano.Binary as CBOR
import qualified Cardano.Crypto.Hash as Crypto
import qualified Cardano.Crypto.Hash.Class as CRYPTO
import qualified Cardano.Crypto.Seed as Crypto
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
import qualified Cardano.Ledger.BaseTypes as Ledger
import qualified Cardano.Ledger.Core as Ledger
import Cardano.Ledger.SafeHash (unsafeMakeSafeHash)
import Control.Applicative (Alternative (..), optional)
import Data.ByteString (ByteString)
import Cardano.Ledger.SafeHash (unsafeMakeSafeHash)

import Control.Applicative (Alternative (..), optional)
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Short as SBS
import Data.Coerce
import Data.Int (Int64)
import Data.Maybe
import Data.OSet.Strict (OSet)
import Data.Coerce
import Data.Int (Int64)
import Data.Maybe
import Data.OSet.Strict (OSet)
import qualified Data.OSet.Strict as OSet
import Data.Ratio (Ratio, (%))
import Data.String
import Data.Word (Word16, Word32, Word64)
import Hedgehog (Gen, MonadGen, Range)
import Data.Ratio (Ratio, (%))
import Data.String
import Data.Word (Word16, Word32, Word64)
import Numeric.Natural (Natural)

import Test.Gen.Cardano.Api.Era
import Test.Gen.Cardano.Api.Metadata (genTxMetadata)

import Test.Cardano.Chain.UTxO.Gen (genVKWitness)
import Test.Cardano.Crypto.Gen (genProtocolMagicId)
import Test.Cardano.Ledger.Conway.Arbitrary ()
import Test.Cardano.Ledger.Core.Arbitrary ()

import Hedgehog (Gen, MonadGen, Range)
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Gen.QuickCheck as Q
import qualified Hedgehog.Range as Range
import Numeric.Natural (Natural)
import Test.Cardano.Chain.UTxO.Gen (genVKWitness)
import Test.Cardano.Crypto.Gen (genProtocolMagicId)
import Test.Cardano.Ledger.Conway.Arbitrary ()
import Test.Cardano.Ledger.Core.Arbitrary ()
import Test.Gen.Cardano.Api.Era
import Test.Gen.Cardano.Api.Metadata (genTxMetadata)

{- HLINT ignore "Reduce duplication" -}
{- HLINT ignore "Use let" -}
Expand Down Expand Up @@ -987,7 +990,7 @@ genProtocolParameters era = do
protocolParamUTxOCostPerByte <-
inEonForEra @BabbageEraOnwards (pure Nothing) (const (Just <$> genLovelace)) era

pure ProtocolParameters {..}
pure ProtocolParameters{..}

-- | Generate valid protocol parameters which pass validations in Cardano.Api.ProtocolParameters
genValidProtocolParameters :: ShelleyBasedEra era -> Gen (LedgerProtocolParameters era)
Expand Down Expand Up @@ -1024,7 +1027,7 @@ genProtocolParametersUpdate era = do
protocolUpdateUTxOCostPerByte <-
inEonForEra @BabbageEraOnwards (pure Nothing) (const (Just <$> genLovelace)) era

pure ProtocolParametersUpdate {..}
pure ProtocolParametersUpdate{..}

genUpdateProposal :: CardanoEra era -> Gen UpdateProposal
genUpdateProposal era =
Expand Down
76 changes: 39 additions & 37 deletions cardano-api/internal/Cardano/Api/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,35 +90,37 @@ module Cardano.Api.Address
)
where

import Cardano.Api.Eon.ShelleyBasedEra
import Cardano.Api.Eras
import Cardano.Api.HasTypeProxy
import Cardano.Api.Hash
import Cardano.Api.Keys.Byron
import Cardano.Api.Keys.Shelley
import Cardano.Api.NetworkId
import Cardano.Api.Script
import Cardano.Api.SerialiseBech32
import Cardano.Api.SerialiseRaw
import Cardano.Api.Utils
import Cardano.Api.Eon.ShelleyBasedEra
import Cardano.Api.Eras
import Cardano.Api.Hash
import Cardano.Api.HasTypeProxy
import Cardano.Api.Keys.Byron
import Cardano.Api.Keys.Shelley
import Cardano.Api.NetworkId
import Cardano.Api.Script
import Cardano.Api.SerialiseBech32
import Cardano.Api.SerialiseRaw
import Cardano.Api.Utils

import qualified Cardano.Chain.Common as Byron
import qualified Cardano.Ledger.Address as Shelley
import qualified Cardano.Ledger.BaseTypes as Shelley
import qualified Cardano.Ledger.Credential as Shelley
import Cardano.Ledger.Crypto (StandardCrypto)
import Cardano.Ledger.Crypto (StandardCrypto)
import qualified Cardano.Ledger.Plutus.TxInfo as Plutus
import Control.Applicative ((<|>))
import Control.DeepSeq (NFData (..), deepseq)
import Data.Aeson (FromJSON (..), ToJSON (..), withText, (.=))
import qualified PlutusLedgerApi.V1 as PlutusAPI

import Control.Applicative ((<|>))
import Control.DeepSeq (NFData (..), deepseq)
import Data.Aeson (FromJSON (..), ToJSON (..), withText, (.=))
import qualified Data.Aeson as Aeson
import Data.Bifunctor (first)
import Data.Bifunctor (first)
import qualified Data.ByteString.Base58 as Base58
import Data.Char (isAsciiLower, isAsciiUpper, isDigit)
import Data.Either.Combinators (rightToMaybe)
import Data.Text (Text)
import Data.Char (isAsciiLower, isAsciiUpper, isDigit)
import Data.Either.Combinators (rightToMaybe)
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import qualified PlutusLedgerApi.V1 as PlutusAPI
import qualified Text.Parsec as Parsec
import qualified Text.Parsec.String as Parsec

Expand Down Expand Up @@ -229,7 +231,7 @@ instance SerialiseAsRawBytes (Address ByronAddr) where
deserialiseFromRawBytes (AsAddress AsByronAddr) bs =
case Shelley.decodeAddr bs :: Maybe (Shelley.Addr StandardCrypto) of
Nothing -> Left (SerialiseAsRawBytesError "Unable to deserialise Address ByronAddr")
Just Shelley.Addr {} -> Left (SerialiseAsRawBytesError "Unable to deserialise Address ByronAddr")
Just Shelley.Addr{} -> Left (SerialiseAsRawBytesError "Unable to deserialise Address ByronAddr")
Just (Shelley.AddrBootstrap (Shelley.BootstrapAddress addr)) ->
Right (ByronAddress addr)

Expand All @@ -241,7 +243,7 @@ instance SerialiseAsRawBytes (Address ShelleyAddr) where
case Shelley.decodeAddr bs of
Nothing ->
Left (SerialiseAsRawBytesError "Unable to deserialise bootstrap Address ShelleyAddr")
Just Shelley.AddrBootstrap {} -> Left (SerialiseAsRawBytesError "Unable to deserialise bootstrap Address ShelleyAddr")
Just Shelley.AddrBootstrap{} -> Left (SerialiseAsRawBytesError "Unable to deserialise bootstrap Address ShelleyAddr")
Just (Shelley.Addr nw pc scr) -> Right (ShelleyAddress nw pc scr)

instance SerialiseAsBech32 (Address ShelleyAddr) where
Expand All @@ -251,7 +253,7 @@ instance SerialiseAsBech32 (Address ShelleyAddr) where
bech32PrefixesPermitted (AsAddress AsShelleyAddr) = ["addr", "addr_test"]

instance SerialiseAddress (Address ByronAddr) where
serialiseAddress addr@ByronAddress {} =
serialiseAddress addr@ByronAddress{} =
Text.decodeLatin1
. Base58.encodeBase58 Base58.bitcoinAlphabet
. serialiseToRawBytes
Expand All @@ -262,7 +264,7 @@ instance SerialiseAddress (Address ByronAddr) where
rightToMaybe (deserialiseFromRawBytes (AsAddress AsByronAddr) bs)

instance SerialiseAddress (Address ShelleyAddr) where
serialiseAddress addr@ShelleyAddress {} =
serialiseAddress addr@ShelleyAddress{} =
serialiseToBech32 addr

deserialiseAddress (AsAddress AsShelleyAddr) t =
Expand Down Expand Up @@ -404,27 +406,27 @@ instance Eq (AddressInEra era) where
(AddressInEra ByronAddressInAnyEra addr1)
(AddressInEra ByronAddressInAnyEra addr2) = addr1 == addr2
(==)
(AddressInEra ShelleyAddressInEra {} addr1)
(AddressInEra ShelleyAddressInEra {} addr2) = addr1 == addr2
(AddressInEra ShelleyAddressInEra{} addr1)
(AddressInEra ShelleyAddressInEra{} addr2) = addr1 == addr2
(==)
(AddressInEra ByronAddressInAnyEra _)
(AddressInEra ShelleyAddressInEra {} _) = False
(AddressInEra ShelleyAddressInEra{} _) = False
(==)
(AddressInEra ShelleyAddressInEra {} _)
(AddressInEra ShelleyAddressInEra{} _)
(AddressInEra ByronAddressInAnyEra _) = False

instance Ord (AddressInEra era) where
compare
(AddressInEra ByronAddressInAnyEra addr1)
(AddressInEra ByronAddressInAnyEra addr2) = compare addr1 addr2
compare
(AddressInEra ShelleyAddressInEra {} addr1)
(AddressInEra ShelleyAddressInEra {} addr2) = compare addr1 addr2
(AddressInEra ShelleyAddressInEra{} addr1)
(AddressInEra ShelleyAddressInEra{} addr2) = compare addr1 addr2
compare
(AddressInEra ByronAddressInAnyEra _)
(AddressInEra ShelleyAddressInEra {} _) = LT
(AddressInEra ShelleyAddressInEra{} _) = LT
compare
(AddressInEra ShelleyAddressInEra {} _)
(AddressInEra ShelleyAddressInEra{} _)
(AddressInEra ByronAddressInAnyEra _) = GT

deriving instance Show (AddressInEra era)
Expand All @@ -449,7 +451,7 @@ instance HasTypeProxy era => HasTypeProxy (AddressInEra era) where
instance IsCardanoEra era => SerialiseAsRawBytes (AddressInEra era) where
serialiseToRawBytes (AddressInEra ByronAddressInAnyEra addr) =
serialiseToRawBytes addr
serialiseToRawBytes (AddressInEra ShelleyAddressInEra {} addr) =
serialiseToRawBytes (AddressInEra ShelleyAddressInEra{} addr) =
serialiseToRawBytes addr

deserialiseFromRawBytes _ bs =
Expand All @@ -460,7 +462,7 @@ instance IsCardanoEra era => SerialiseAsRawBytes (AddressInEra era) where
instance IsCardanoEra era => SerialiseAddress (AddressInEra era) where
serialiseAddress (AddressInEra ByronAddressInAnyEra addr) =
serialiseAddress addr
serialiseAddress (AddressInEra ShelleyAddressInEra {} addr) =
serialiseAddress (AddressInEra ShelleyAddressInEra{} addr) =
serialiseAddress addr

deserialiseAddress _ t =
Expand Down Expand Up @@ -500,8 +502,8 @@ anyAddressInEra era = \case
(\sbe -> Right (AddressInEra (ShelleyAddressInEra sbe) addr))

toAddressAny :: Address addr -> AddressAny
toAddressAny a@ShelleyAddress {} = AddressShelley a
toAddressAny a@ByronAddress {} = AddressByron a
toAddressAny a@ShelleyAddress{} = AddressShelley a
toAddressAny a@ByronAddress{} = AddressByron a

makeByronAddressInEra
:: NetworkId
Expand Down Expand Up @@ -581,7 +583,7 @@ instance SerialiseAsBech32 StakeAddress where
bech32PrefixesPermitted AsStakeAddress = ["stake", "stake_test"]

instance SerialiseAddress StakeAddress where
serialiseAddress addr@StakeAddress {} =
serialiseAddress addr@StakeAddress{} =
serialiseToBech32 addr

deserialiseAddress AsStakeAddress t =
Expand Down
44 changes: 23 additions & 21 deletions cardano-api/internal/Cardano/Api/Block.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,23 @@ module Cardano.Api.Block
)
where

import Cardano.Api.Eon.ShelleyBasedEra
import Cardano.Api.Eras
import Cardano.Api.HasTypeProxy
import Cardano.Api.Hash
import Cardano.Api.Keys.Shelley
import Cardano.Api.Modes
import Cardano.Api.SerialiseRaw
import Cardano.Api.SerialiseUsing
import Cardano.Api.Tx.Sign
import Cardano.Api.Eon.ShelleyBasedEra
import Cardano.Api.Eras
import Cardano.Api.Hash
import Cardano.Api.HasTypeProxy
import Cardano.Api.Keys.Shelley
import Cardano.Api.Modes
import Cardano.Api.SerialiseRaw
import Cardano.Api.SerialiseUsing
import Cardano.Api.Tx.Sign

import qualified Cardano.Crypto.Hash.Class as Crypto
import qualified Cardano.Crypto.Hashing
import qualified Cardano.Ledger.Api as L
import qualified Cardano.Ledger.Block as Ledger
import qualified Cardano.Ledger.Era as Ledger
import Cardano.Slotting.Block (BlockNo)
import Cardano.Slotting.Slot (EpochNo, SlotNo, WithOrigin (..))
import Data.Aeson (FromJSON (..), ToJSON (..), Value (..), object, withObject, (.:), (.=))
import qualified Data.Aeson as Aeson
import qualified Data.ByteString as BS
import qualified Data.ByteString.Short as SBS
import Data.Foldable (Foldable (toList))
import Data.String (IsString)
import Data.Text (Text)
import Cardano.Slotting.Block (BlockNo)
import Cardano.Slotting.Slot (EpochNo, SlotNo, WithOrigin (..))
import qualified Ouroboros.Consensus.Block as Consensus
import qualified Ouroboros.Consensus.Byron.Ledger as Consensus
import qualified Ouroboros.Consensus.Cardano.Block as Consensus
Expand All @@ -79,6 +73,14 @@ import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus
import qualified Ouroboros.Consensus.Shelley.Protocol.Abstract as Consensus
import qualified Ouroboros.Network.Block as Consensus

import Data.Aeson (FromJSON (..), ToJSON (..), Value (..), object, withObject, (.:), (.=))
import qualified Data.Aeson as Aeson
import qualified Data.ByteString as BS
import qualified Data.ByteString.Short as SBS
import Data.Foldable (Foldable (toList))
import Data.String (IsString)
import Data.Text (Text)

{- HLINT ignore "Use lambda" -}
{- HLINT ignore "Use lambda-case" -}

Expand Down Expand Up @@ -154,8 +156,8 @@ getBlockTxs :: forall era. Block era -> [Tx era]
getBlockTxs = \case
-- In the context of foldBlocks we don't care about the Byron era.
-- Testing leans on ledger events which is a Shelley onwards feature.
ByronBlock Consensus.ByronBlock {} -> []
ShelleyBlock sbe Consensus.ShelleyBlock {Consensus.shelleyBlockRaw} ->
ByronBlock Consensus.ByronBlock{} -> []
ShelleyBlock sbe Consensus.ShelleyBlock{Consensus.shelleyBlockRaw} ->
shelleyBasedEraConstraints sbe $
getShelleyBlockTxs sbe shelleyBlockRaw

Expand Down Expand Up @@ -230,7 +232,7 @@ data BlockHeader
newtype instance Hash BlockHeader = HeaderHash SBS.ShortByteString
deriving (Eq, Ord, Show)
deriving (ToJSON, FromJSON) via UsingRawBytesHex (Hash BlockHeader)
deriving (IsString) via UsingRawBytesHex (Hash BlockHeader)
deriving IsString via UsingRawBytesHex (Hash BlockHeader)

instance SerialiseAsRawBytes (Hash BlockHeader) where
serialiseToRawBytes (HeaderHash bs) = SBS.fromShort bs
Expand Down
Loading

0 comments on commit f2363ec

Please sign in to comment.