Skip to content

Commit

Permalink
Merge pull request #1154 from input-output-hk/code-format-workflow
Browse files Browse the repository at this point in the history
Add a code formatting PR workflow
  • Loading branch information
ch1bo authored Nov 7, 2023
2 parents 8a451dd + 837c00b commit 424671d
Show file tree
Hide file tree
Showing 184 changed files with 833 additions and 759 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/formatting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Check code formatting

on:
pull_request:

jobs:
formatting:
name: Check code formatting
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4

- name: ❄ Prepare nix
uses: cachix/install-nix-action@v23
with:
extra_nix_config: |
accept-flake-config = true
log-lines = 1000
- name: ❄ Cachix cache of nix derivations
uses: cachix/cachix-action@v12
with:
name: cardano-scaling
authToken: '${{ secrets.CACHIX_CARDANO_SCALING_AUTH_TOKEN }}'

- name: 📐 Check code formatting
run: |
nix develop .#ci --command treefmt --fail-on-change
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ you can:
- Build & run the `hydra-node`: `cabal build hydra-node && cabal exec hydra-node -- --version`
- Build & run all tests: `cabal test all`
- Build & run all benchmarks: `cabal bench all`
- Format code as enforced by CI: `treefmt`
- Run `haskell-language-server` for an IDE experience
- Run `hoogle` for symbol & documentation lookup

Expand Down
3 changes: 3 additions & 0 deletions fourmolu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ respectful: true # don't be too opinionated about newlines etc.
haddock-style: single-line # '--' vs. '{-'
newlines-between-decls: 1 # number of newlines between top-level declarations
single-constraint-parens: never # whether or not to put braces around single constraints: https://fourmolu.github.io/config/single-constraint-parens/
fixities:
- infixr 0 $
- infixr 1 &
8 changes: 4 additions & 4 deletions hydra-cardano-api/src/Cardano/Api/UTxO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
module Cardano.Api.UTxO where

import Cardano.Api hiding (UTxO, toLedgerUTxO)
import qualified Cardano.Api
import Cardano.Api qualified
import Data.Coerce (coerce)
import qualified Data.List as List
import Data.List qualified as List
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Map qualified as Map
import Data.Set (Set)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text qualified as T
import Prelude

type Era = BabbageEra
Expand Down
16 changes: 8 additions & 8 deletions hydra-cardano-api/src/Hydra/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ import Hydra.Cardano.Api.Value as Extras
import Hydra.Cardano.Api.VerificationKey ()
import Hydra.Cardano.Api.Witness as Extras

import qualified Cardano.Api
import qualified Cardano.Api.Shelley
import qualified Cardano.Ledger.Alonzo.TxAuxData as Ledger
import qualified Cardano.Ledger.Alonzo.TxWits as Ledger
import qualified Cardano.Ledger.Core as Ledger
import qualified Cardano.Ledger.Keys as Ledger
import qualified Cardano.Ledger.Keys.Bootstrap as Ledger
import qualified Cardano.Ledger.Keys.WitVKey as Ledger
import Cardano.Api qualified
import Cardano.Api.Shelley qualified
import Cardano.Ledger.Alonzo.TxAuxData qualified as Ledger
import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
import Cardano.Ledger.Core qualified as Ledger
import Cardano.Ledger.Keys qualified as Ledger
import Cardano.Ledger.Keys.Bootstrap qualified as Ledger
import Cardano.Ledger.Keys.WitVKey qualified as Ledger
import Data.ByteString.Short (ShortByteString)
import Prelude

Expand Down
4 changes: 2 additions & 2 deletions hydra-cardano-api/src/Hydra/Cardano/Api/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Hydra.Cardano.Api.Prelude

import Cardano.Api.Byron (Address (..))
import Cardano.Binary (unsafeDeserialize')
import qualified Cardano.Chain.Common as Ledger
import qualified Data.ByteString as BS
import Cardano.Chain.Common qualified as Ledger
import Data.ByteString qualified as BS
import Test.QuickCheck (frequency, oneof, vector)

-- * Orphans
Expand Down
12 changes: 6 additions & 6 deletions hydra-cardano-api/src/Hydra/Cardano/Api/AddressInEra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ module Hydra.Cardano.Api.AddressInEra where
import Hydra.Cardano.Api.Prelude

import Cardano.Api.Byron (Address (..))
import qualified Cardano.Ledger.Address as Ledger
import qualified Cardano.Ledger.BaseTypes as Ledger
import qualified Cardano.Ledger.Credential as Ledger
import qualified Cardano.Ledger.Hashes as Ledger
import qualified Cardano.Ledger.Keys as Ledger
import Cardano.Ledger.Address qualified as Ledger
import Cardano.Ledger.BaseTypes qualified as Ledger
import Cardano.Ledger.Credential qualified as Ledger
import Cardano.Ledger.Hashes qualified as Ledger
import Cardano.Ledger.Keys qualified as Ledger
import Hydra.Cardano.Api.Network (Network)
import PlutusLedgerApi.V2 (
Address (..),
Credential (..),
StakingCredential (StakingHash, StakingPtr),
fromBuiltin,
)
import qualified PlutusLedgerApi.V2 as Plutus
import PlutusLedgerApi.V2 qualified as Plutus

-- * Extras

Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/BlockHeader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Hydra.Cardano.Api.BlockHeader where

import Hydra.Cardano.Api.Prelude

import qualified Data.ByteString as BS
import Data.ByteString qualified as BS
import Test.QuickCheck (vectorOf)

unsafeBlockHeaderHashFromBytes :: HasCallStack => ByteString -> Hash BlockHeader
Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/ExecutionUnits.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Hydra.Cardano.Api.ExecutionUnits where

import Hydra.Cardano.Api.Prelude

import qualified Cardano.Ledger.Alonzo.Scripts as Ledger
import Cardano.Ledger.Alonzo.Scripts qualified as Ledger

-- * Type Conversions

Expand Down
10 changes: 5 additions & 5 deletions hydra-cardano-api/src/Hydra/Cardano/Api/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ module Hydra.Cardano.Api.Hash where

import Hydra.Cardano.Api.Prelude

import qualified Cardano.Ledger.Alonzo.TxInfo as Ledger
import qualified Cardano.Ledger.Keys as Ledger
import Cardano.Ledger.Alonzo.TxInfo qualified as Ledger
import Cardano.Ledger.Keys qualified as Ledger
import Cardano.Ledger.SafeHash (unsafeMakeSafeHash)
import qualified Cardano.Ledger.Shelley.Scripts as Ledger
import qualified Data.ByteString as BS
import qualified PlutusLedgerApi.V2 as Plutus
import Cardano.Ledger.Shelley.Scripts qualified as Ledger
import Data.ByteString qualified as BS
import PlutusLedgerApi.V2 qualified as Plutus

-- | Convert a cardano-api 'Hash' into a plutus 'PubKeyHash'
toPlutusKeyHash :: Hash PaymentKey -> Plutus.PubKeyHash
Expand Down
12 changes: 6 additions & 6 deletions hydra-cardano-api/src/Hydra/Cardano/Api/KeyWitness.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ module Hydra.Cardano.Api.KeyWitness where

import Hydra.Cardano.Api.Prelude

import qualified Cardano.Ledger.Alonzo.TxWits as Ledger
import qualified Cardano.Ledger.Era as Ledger
import qualified Cardano.Ledger.Keys as Ledger
import qualified Cardano.Ledger.Shelley.API as Ledger
import qualified Data.Set as Set
import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
import Cardano.Ledger.Era qualified as Ledger
import Cardano.Ledger.Keys qualified as Ledger
import Cardano.Ledger.Shelley.API qualified as Ledger
import Data.Set qualified as Set

-- * Extras

-- | Construct a 'KeyWitness' from a transaction id and credentials.
signWith ::
forall era.
(IsShelleyBasedEra era) =>
IsShelleyBasedEra era =>
TxId ->
SigningKey PaymentKey ->
KeyWitness era
Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/Lovelace.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Hydra.Cardano.Api.Lovelace where

import Hydra.Cardano.Api.Prelude

import qualified Cardano.Ledger.Coin as Ledger
import Cardano.Ledger.Coin qualified as Ledger

-- * Extras

Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Hydra.Cardano.Api.Network (
networkIdToNetwork,
) where

import qualified Cardano.Api as Api
import Cardano.Api qualified as Api
import Cardano.Ledger.BaseTypes (Network (..))

networkIdToNetwork :: Api.NetworkId -> Network
Expand Down
10 changes: 5 additions & 5 deletions hydra-cardano-api/src/Hydra/Cardano/Api/PlutusScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module Hydra.Cardano.Api.PlutusScript where

import Hydra.Cardano.Api.Prelude

import qualified Cardano.Ledger.Alonzo.Language as Ledger
import qualified Cardano.Ledger.Alonzo.Scripts as Ledger
import qualified Data.ByteString.Short as SBS
import qualified PlutusLedgerApi.Common as Plutus
import Cardano.Ledger.Alonzo.Language qualified as Ledger
import Cardano.Ledger.Alonzo.Scripts qualified as Ledger
import Data.ByteString.Short qualified as SBS
import PlutusLedgerApi.Common qualified as Plutus
import Test.QuickCheck (listOf)

-- * Type Conversions
Expand All @@ -26,7 +26,7 @@ fromLedgerScript = \case
-- | Convert a cardano-api 'PlutusScript' into a cardano-ledger 'Script'.
toLedgerScript ::
forall lang.
(IsPlutusScriptLanguage lang) =>
IsPlutusScriptLanguage lang =>
PlutusScript lang ->
Ledger.AlonzoScript (ShelleyLedgerEra Era)
toLedgerScript (PlutusScriptSerialised bytes) =
Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/PolicyId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Hydra.Cardano.Api.PolicyId where

import Hydra.Cardano.Api.Prelude

import qualified Cardano.Ledger.Hashes as Ledger
import Cardano.Ledger.Hashes qualified as Ledger

toLedgerScriptHash :: PolicyId -> Ledger.ScriptHash StandardCrypto
toLedgerScriptHash (PolicyId scriptHash) = toShelleyScriptHash scriptHash
8 changes: 4 additions & 4 deletions hydra-cardano-api/src/Hydra/Cardano/Api/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ import Cardano.Api.Shelley hiding (
toLedgerUTxO,
)
import Cardano.Api.UTxO (UTxO, UTxO' (..))
import qualified Cardano.Crypto.Hash.Class as CC
import qualified Cardano.Ledger.Babbage as Ledger
import qualified Cardano.Ledger.Binary as Ledger
import qualified Cardano.Ledger.Core as Ledger
import Cardano.Crypto.Hash.Class qualified as CC
import Cardano.Ledger.Babbage qualified as Ledger
import Cardano.Ledger.Binary qualified as Ledger
import Cardano.Ledger.Core qualified as Ledger
import Cardano.Ledger.Crypto (StandardCrypto)
import Cardano.Ledger.Era (EraCrypto)
import Data.Aeson (FromJSON (..), ToJSON (..))
Expand Down
20 changes: 10 additions & 10 deletions hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
-- | Pretty printing transactions and utxo's
module Hydra.Cardano.Api.Pretty where

import qualified Hydra.Cardano.Api as Api
import Hydra.Cardano.Api qualified as Api
import Hydra.Cardano.Api.Prelude

import qualified Cardano.Api.UTxO as UTxO
import Cardano.Api.UTxO qualified as UTxO
import Cardano.Binary (serialize)
import qualified Cardano.Ledger.Alonzo.Scripts as Ledger
import qualified Cardano.Ledger.Alonzo.TxWits as Ledger
import qualified Cardano.Ledger.Core as Ledger
import qualified Cardano.Ledger.SafeHash as Ledger
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Lazy as BL
import Cardano.Ledger.Alonzo.Scripts qualified as Ledger
import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
import Cardano.Ledger.Core qualified as Ledger
import Cardano.Ledger.SafeHash qualified as Ledger
import Data.Aeson qualified as Aeson
import Data.ByteString.Lazy qualified as BL
import Data.Function (on)
import Data.List (intercalate, sort, sortBy)
import qualified Data.Map.Strict as Map
import qualified Data.Text as T
import Data.Map.Strict qualified as Map
import Data.Text qualified as T
import Hydra.Cardano.Api.ScriptData (fromLedgerData)

-- | Obtain a human-readable pretty text representation of a transaction.
Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/ReferenceScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Hydra.Cardano.Api.Prelude

import Hydra.Cardano.Api.PlutusScript (fromPlutusScript)
import Hydra.Cardano.Api.ReferenceTxInsScriptsInlineDatumsSupportedInEra (HasInlineDatums (..))
import qualified PlutusLedgerApi.V2 as Plutus
import PlutusLedgerApi.V2 qualified as Plutus

-- | Construct a 'ReferenceScript' from any given Plutus script.
--
Expand Down
14 changes: 7 additions & 7 deletions hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ module Hydra.Cardano.Api.ScriptData where
import Hydra.Cardano.Api.Prelude

import Cardano.Api.Byron (TxBody (..))
import qualified Cardano.Ledger.Alonzo.Scripts.Data as Ledger
import qualified Cardano.Ledger.Alonzo.TxWits as Ledger
import qualified Cardano.Ledger.Era as Ledger
import Cardano.Ledger.Alonzo.Scripts.Data qualified as Ledger
import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
import Cardano.Ledger.Era qualified as Ledger
import Codec.Serialise (deserialiseOrFail, serialise)
import Control.Arrow (left)
import Data.Aeson (Value (String), withText)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Base16 as Base16
import qualified Data.Map as Map
import qualified PlutusLedgerApi.V2 as Plutus
import Data.ByteString qualified as BS
import Data.ByteString.Base16 qualified as Base16
import Data.Map qualified as Map
import PlutusLedgerApi.V2 qualified as Plutus
import Test.QuickCheck (arbitrarySizedNatural, choose, oneof, scale, sized, vector)

-- * Extras
Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/ScriptDatum.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import Hydra.Cardano.Api.ScriptData (ToScriptData, toScriptData)
-- * Extras

-- | Construct a 'ScriptDatum' for use as transaction witness.
mkScriptDatum :: (ToScriptData a) => a -> ScriptDatum WitCtxTxIn
mkScriptDatum :: ToScriptData a => a -> ScriptDatum WitCtxTxIn
mkScriptDatum =
ScriptDatumForTxIn . toScriptData
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/ScriptHash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Hydra.Cardano.Api.ScriptHash where

import Hydra.Cardano.Api.Prelude

import qualified Cardano.Ledger.Credential as Ledger
import Cardano.Ledger.Credential qualified as Ledger

-- | Extract the payment part of an address, as a script hash.
getPaymentScriptHash :: AddressInEra era -> Maybe ScriptHash
Expand Down
10 changes: 5 additions & 5 deletions hydra-cardano-api/src/Hydra/Cardano/Api/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import Hydra.Cardano.Api.KeyWitness (
)
import Hydra.Cardano.Api.TxScriptValidity (toLedgerScriptValidity)

import qualified Cardano.Api.UTxO as UTxO
import qualified Cardano.Ledger.Alonzo.TxWits as Ledger
import qualified Cardano.Ledger.Babbage.Tx as Ledger
import Cardano.Api.UTxO qualified as UTxO
import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
import Cardano.Ledger.Babbage.Tx qualified as Ledger
import Cardano.Ledger.BaseTypes (maybeToStrictMaybe, strictMaybeToMaybe)
import qualified Cardano.Ledger.Core as Ledger (Tx, hashScript)
import Cardano.Ledger.Core qualified as Ledger (Tx, hashScript)
import Data.Bifunctor (bimap)
import Data.Functor ((<&>))
import qualified Data.Map as Map
import Data.Map qualified as Map
import Hydra.Cardano.Api.TxIn (mkTxIn)

-- * Extras
Expand Down
18 changes: 8 additions & 10 deletions hydra-cardano-api/src/Hydra/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ import Hydra.Cardano.Api.ScriptData (FromScriptData)
import Hydra.Cardano.Api.TxIn (toLedgerTxIn)
import Hydra.Cardano.Api.Value (toLedgerPolicyID)

import qualified Cardano.Ledger.Alonzo.Scripts.Data as Ledger
import qualified Cardano.Ledger.Alonzo.TxWits as Ledger
import qualified Cardano.Ledger.Babbage.Tx as Ledger
import Cardano.Ledger.Alonzo.Scripts.Data qualified as Ledger
import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
import Cardano.Ledger.Babbage.Tx qualified as Ledger
import Cardano.Ledger.BaseTypes (strictMaybeToMaybe)
import qualified Cardano.Ledger.Core as Ledger
import Cardano.Ledger.Core qualified as Ledger
import Data.List (find)
import qualified Data.Map as Map
import qualified PlutusLedgerApi.V2 as Plutus
import Data.Map qualified as Map
import PlutusLedgerApi.V2 qualified as Plutus

-- | Find and deserialise from 'ScriptData', a redeemer from the transaction
-- associated to the given input.
findRedeemerSpending ::
( FromScriptData a
) =>
FromScriptData a =>
Tx Era ->
TxIn ->
Maybe a
Expand All @@ -31,8 +30,7 @@ findRedeemerSpending (getTxBody -> ShelleyTxBody _ body _ scriptData _ _) txIn =

findRedeemerMinting ::
forall a.
( FromScriptData a
) =>
FromScriptData a =>
Tx Era ->
PolicyId ->
Maybe a
Expand Down
Loading

0 comments on commit 424671d

Please sign in to comment.