From f8d72ea6fbab4d9398f26ce18c03037bf42c5d19 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Tue, 9 Jul 2024 00:38:14 +0200 Subject: [PATCH 1/5] Apply adjustments to fourmolu --- fourmolu.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fourmolu.yaml b/fourmolu.yaml index 7362755bc9..9eb66064d3 100644 --- a/fourmolu.yaml +++ b/fourmolu.yaml @@ -3,15 +3,15 @@ column-limit: 100 function-arrows: leading comma-style: leading import-export-style: leading -indent-wheres: true -record-brace-space: true +indent-wheres: false +record-brace-space: false newlines-between-decls: 1 haddock-style: single-line haddock-style-module: let-style: auto -indent-wheres: false in-style: right-align unicode: never respectful: false fixities: [] single-constraint-parens: never +single-deriving-parens: never From a64ffc31fd25ba39e176923ea66cc76114d12da6 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Tue, 9 Jul 2024 01:09:38 +0200 Subject: [PATCH 2/5] Add stylish-haskell after fourmolu --- ...heck-fourmolu.yml => check-formatting.yml} | 20 ++- .stylish-haskell.yaml | 114 ++++++++++++++++++ scripts/githooks/haskell-style-lint | 1 + 3 files changed, 131 insertions(+), 4 deletions(-) rename .github/workflows/{check-fourmolu.yml => check-formatting.yml} (76%) create mode 100644 .stylish-haskell.yaml diff --git a/.github/workflows/check-fourmolu.yml b/.github/workflows/check-formatting.yml similarity index 76% rename from .github/workflows/check-fourmolu.yml rename to .github/workflows/check-formatting.yml index 5e56c5c46d..8812347f28 100644 --- a/.github/workflows/check-fourmolu.yml +++ b/.github/workflows/check-formatting.yml @@ -1,4 +1,4 @@ -name: Check Fourmolu +name: Check Haskell formatting on: merge_group: @@ -19,11 +19,12 @@ concurrency: cancel-in-progress: true jobs: - check-fourmolu: + check-formatting: runs-on: ubuntu-latest env: FOURMOLU_VERSION: "0.16.2.0" + STYLISH_HASKELL_VERSION: "0.14.5.0" steps: - name: Download Fourmolu @@ -35,9 +36,18 @@ jobs: echo "PATH=$fourmolu_path:$PATH" >> "$GITHUB_ENV" chmod u+rwx "$fourmolu_path/fourmolu" + - name: Download stylish-haskell + run: | + stylish_haskell_path="$(mktemp -d)" + version="${{ env.STYLISH_HASKELL_VERSION }}" + curl -sL \ + "https://github.com/haskell/stylish-haskell/releases/download/v$version/stylish-haskell-v$version-linux-x86_64.tar.gz" \ + | tar -C "$stylish_haskell_path" -xz + echo "PATH=$stylish_haskell_path/stylish-haskell-v$version-linux-x86_64:$PATH" >> "$GITHUB_ENV" + - uses: actions/checkout@v3 - - name: Run Fourmolu over all Haskell files (always succeeds) + - name: Run formatting over all Haskell files (always succeeds) run: | git add . git stash @@ -48,13 +58,14 @@ jobs: echo "$x contains CPP. Skipping." else fourmolu -q -i "$x" + stylish-haskell -i "$x" fi fi done git --no-pager diff - - name: Run Fourmolu over all modified files + - name: Run formatting over all modified files run: | git add . git stash @@ -65,6 +76,7 @@ jobs: echo "$x contains CPP. Skipping." else fourmolu -q -i "$x" + stylish-haskell -i "$x" fi fi done diff --git a/.stylish-haskell.yaml b/.stylish-haskell.yaml new file mode 100644 index 0000000000..7218ef5069 --- /dev/null +++ b/.stylish-haskell.yaml @@ -0,0 +1,114 @@ +# Stylish-haskell configuration file. + +# Principles: +# +# 1. Amount of indent should not be dependent on the length of the previous line +# 2. Imports lists should be compact +# 3. All linting rules that delete comments should be disabled +# 4. No inline indenting, for example indent of ->, =, <-, as +# 5. Redunant imports and pragmas should be removed +# 6. Consistent syntax +# 7. No trailing whitespaces +# 8. Slightly generous screen width assumed +# 9. All Haskell files in the project are subject to code formatting style +# 10. Import grouping is handled by stylish-haskell + +steps: + # Principle 4 + - simple_align: + cases: false + top_level_patterns: false + # Principle 3 + records: false + + # Import cleanup + - imports: + align: global + + # Principle 1,2 + list_align: with_module_name + + # Principle 4 + pad_module_names: false + + # Principle 2 + long_list_align: inline + + empty_list_align: inherit + + list_padding: 2 + + separate_lists: true + + space_surround: false + + # Principle 10 + group_imports: true + + group_rules: + - match: ^Cardano.Api\> + - match: ^(Cardano|Ouroboros|PlutusCore|PlutusLedgerApi)\> + - match: ^Prelude\> + - match: ^(Control|Codec|Data|Formatting|GHC|Lens|Network|Numeric|Options|Prettyprinter|System|Text)\> + - match: ^(Test.Gen.Cardano.Api)\> + - match: ^(Test.Cardano|Test.Gen.Cardano)\> + - match: ^(Hedgehog|HaskellWorks.Hspec|Test)\> + + - language_pragmas: + style: vertical + + align: false + + # Principle 5 + remove_redundant: true + + # Principle 6 + language_prefix: LANGUAGE + + # Principle 7 + - trailing_whitespace: {} + +# Principle 8 +columns: 100 + +newline: native + +# Principle 9 +# +# These syntax-affecting language extensions are enabled so that +# stylish-haskell wouldn't fail with parsing errors when processing files +# in projects that have those extensions enabled in the .cabal file +# rather than locally. +# +# In particular language extensions with British and American spellings +# that we use should be included here until stylish-haskell supports +# the British spelling. +language_extensions: + - BangPatterns + - ConstraintKinds + - DataKinds + - DefaultSignatures + - DeriveDataTypeable + - DeriveGeneric + - ExistentialQuantification + - FlexibleContexts + - FlexibleInstances + - FunctionalDependencies + - GADTs + - GeneralizedNewtypeDeriving + - LambdaCase + - MultiParamTypeClasses + - MultiWayIf + - OverloadedStrings + - PolyKinds + - RecordWildCards + - ScopedTypeVariables + - StandaloneDeriving + - TemplateHaskell + - TupleSections + - TypeApplications + - TypeFamilies + - ViewPatterns + - ExplicitNamespaces + +cabal: true diff --git a/scripts/githooks/haskell-style-lint b/scripts/githooks/haskell-style-lint index 95aabcb7f0..6717287b08 100755 --- a/scripts/githooks/haskell-style-lint +++ b/scripts/githooks/haskell-style-lint @@ -15,6 +15,7 @@ for x in $(git diff --staged --name-only --diff-filter=ACM "*.hs" | tr '\n' ' ') echo "$x contains CPP. Skipping." else fourmolu -q -i "$x" + stylish-haskell -i "$x" fi hlint "$x" || hlint_rc="1" done From 10664b9c316e7fc83ce9fd7c9f0206f82f8af771 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Tue, 9 Jul 2024 18:12:22 +0200 Subject: [PATCH 3/5] Add script for formatting --- flake.nix | 3 ++ scripts/devshell/format | 64 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100755 scripts/devshell/format diff --git a/flake.nix b/flake.nix index 4cdf94d48b..215a3236e8 100644 --- a/flake.nix +++ b/flake.nix @@ -121,6 +121,9 @@ shell.withHoogle = false; # Skip cross compilers for the shell shell.crossPlatforms = _: []; + shell.shellHook = '' + export PATH="$(git rev-parse --show-toplevel)/scripts/devshell:$PATH" + ''; # package customizations as needed. Where cabal.project is not # specific enough, or doesn't allow setting these. diff --git a/scripts/devshell/format b/scripts/devshell/format new file mode 100755 index 0000000000..f544ef810b --- /dev/null +++ b/scripts/devshell/format @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +# Function to display help message +show_help() { + echo "Usage: format " + echo "Format Haskell source files using fourmolu and stylish-haskell." + echo "" + echo "Options:" + echo " -t, --tracked Format all tracked Haskell (*.hs) files in the repository" + echo " -s, --staged Format all staged Haskell (*.hs) files" + echo " -m, --modified Format all modified Haskell (*.hs) files, including staged and unstaged" + echo " -n, --not-staged Format all non-staged modified Haskell (*.hs) files" + echo " -h, --help Show this help message" +} + +# Function to run the formatting commands +run_format() { + for file in "$@"; do + if [[ $file == *.hs ]]; then + if grep -qE '^#' "$file"; then + echo "$file contains CPP. Skipping." + else + echo "Formatting: $file" + fourmolu -q -i "$file" + fourmolu -q -i "$file" + stylish-haskell -i "$file" + fi + + fi + done +} + +# Parse command line arguments +case $1 in + -t|--tracked) + files=$(git ls-files '*.hs') + ;; + -s|--staged) + files=$(git diff --cached --name-only --diff-filter=ACM '*.hs') + ;; + -m|--modified) + files=$(git diff --name-only --diff-filter=ACM HEAD '*.hs') + ;; + -n|--not-staged) + files=$(git diff --name-only --diff-filter=ACM '*.hs') + ;; + -h|--help) + show_help + exit 0 + ;; + *) + files="$@" + ;; +esac + +if [[ -z $files ]]; then + echo "No files to format!" + echo -e + show_help + exit 1 +fi + +run_format $files + From 299868d72251a7f15210533683117dc48d572a5a Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Thu, 11 Jul 2024 02:42:43 +0200 Subject: [PATCH 4/5] Address reviews --- .github/workflows/check-formatting.yml | 6 ++---- scripts/devshell/{format => prettify} | 25 ++++++++++++++++++++++--- scripts/githooks/haskell-style-lint | 3 +-- 3 files changed, 25 insertions(+), 9 deletions(-) rename scripts/devshell/{format => prettify} (78%) diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml index 8812347f28..142c592966 100644 --- a/.github/workflows/check-formatting.yml +++ b/.github/workflows/check-formatting.yml @@ -57,8 +57,7 @@ jobs: if grep -qE '^#' "$x"; then echo "$x contains CPP. Skipping." else - fourmolu -q -i "$x" - stylish-haskell -i "$x" + "$(git rev-parse --show-toplevel)/scripts/devshell/prettify" "$x" fi fi done @@ -75,8 +74,7 @@ jobs: if grep -qE '^#' "$x"; then echo "$x contains CPP. Skipping." else - fourmolu -q -i "$x" - stylish-haskell -i "$x" + "$(git rev-parse --show-toplevel)/scripts/devshell/prettify" "$x" fi fi done diff --git a/scripts/devshell/format b/scripts/devshell/prettify similarity index 78% rename from scripts/devshell/format rename to scripts/devshell/prettify index f544ef810b..d78dcf5e10 100755 --- a/scripts/devshell/format +++ b/scripts/devshell/prettify @@ -53,12 +53,31 @@ case $1 in ;; esac -if [[ -z $files ]]; then - echo "No files to format!" +if !(which stylish-haskell > /dev/null 2>&1); then + echo "ERROR: stylish-haskell is not available!" + echo -e + echo "Try entering the development shell with:" + echo " nix develop" + exit 1 +fi + +if !(which fourmolu > /dev/null 2>&1); then + echo "ERROR: fourmolu is not available!" echo -e - show_help + echo "Try entering the development shell with:" + echo " nix develop" exit 1 fi + +if [[ -z $files ]]; then + echo "No files to format!" + if [[ -z $1 ]]; then + echo -e + show_help + exit 1 + fi +fi + run_format $files diff --git a/scripts/githooks/haskell-style-lint b/scripts/githooks/haskell-style-lint index 6717287b08..2efc2d77a0 100755 --- a/scripts/githooks/haskell-style-lint +++ b/scripts/githooks/haskell-style-lint @@ -14,8 +14,7 @@ for x in $(git diff --staged --name-only --diff-filter=ACM "*.hs" | tr '\n' ' ') if grep -qE '^#' "$x"; then echo "$x contains CPP. Skipping." else - fourmolu -q -i "$x" - stylish-haskell -i "$x" + "$(git rev-parse --show-toplevel)/scripts/devshell/prettify" "$x" fi hlint "$x" || hlint_rc="1" done From e28fadbebc18b87991f84af72d8611393ae8875a Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Tue, 9 Jul 2024 01:26:46 +0200 Subject: [PATCH 5/5] Apply formatting --- .../src/Test/Gen/Cardano/Api/Empty.hs | 2 +- cardano-api/gen/Test/Gen/Cardano/Api.hs | 11 +- cardano-api/gen/Test/Gen/Cardano/Api/Byron.hs | 19 +- cardano-api/gen/Test/Gen/Cardano/Api/Era.hs | 14 +- .../gen/Test/Gen/Cardano/Api/Metadata.hs | 14 +- .../Gen/Cardano/Api/ProtocolParameters.hs | 17 +- cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs | 61 +++--- .../gen/Test/Gen/Cardano/Crypto/Seed.hs | 8 +- .../gen/Test/Hedgehog/Golden/ErrorMessage.hs | 18 +- .../gen/Test/Hedgehog/Roundtrip/Bech32.hs | 5 +- .../gen/Test/Hedgehog/Roundtrip/CBOR.hs | 6 +- cardano-api/internal/Cardano/Api/Address.hs | 76 +++---- cardano-api/internal/Cardano/Api/Block.hs | 44 ++-- .../internal/Cardano/Api/Certificate.hs | 110 +++++----- .../Cardano/Api/Convenience/Construction.hs | 24 +- .../internal/Cardano/Api/Convenience/Query.hs | 64 +++--- .../internal/Cardano/Api/DRepMetadata.hs | 22 +- .../internal/Cardano/Api/DeserialiseAnyOf.hs | 42 ++-- .../Cardano/Api/Eon/AllegraEraOnwards.hs | 16 +- .../Cardano/Api/Eon/AlonzoEraOnwards.hs | 16 +- .../Cardano/Api/Eon/BabbageEraOnwards.hs | 16 +- .../Cardano/Api/Eon/ByronToAlonzoEra.hs | 5 +- .../Cardano/Api/Eon/ConwayEraOnwards.hs | 16 +- .../Cardano/Api/Eon/MaryEraOnwards.hs | 16 +- .../Cardano/Api/Eon/ShelleyBasedEra.hs | 34 ++- .../Cardano/Api/Eon/ShelleyEraOnly.hs | 16 +- .../Cardano/Api/Eon/ShelleyToAllegraEra.hs | 16 +- .../Cardano/Api/Eon/ShelleyToAlonzoEra.hs | 16 +- .../Cardano/Api/Eon/ShelleyToBabbageEra.hs | 16 +- .../Cardano/Api/Eon/ShelleyToMaryEra.hs | 16 +- cardano-api/internal/Cardano/Api/Eras.hs | 4 +- cardano-api/internal/Cardano/Api/Eras/Case.hs | 26 +-- cardano-api/internal/Cardano/Api/Eras/Core.hs | 18 +- cardano-api/internal/Cardano/Api/Error.hs | 17 +- cardano-api/internal/Cardano/Api/Feature.hs | 4 +- cardano-api/internal/Cardano/Api/Fees.hs | 110 +++++----- cardano-api/internal/Cardano/Api/Genesis.hs | 63 +++--- .../internal/Cardano/Api/GenesisParameters.hs | 12 +- .../Governance/Actions/ProposalProcedure.hs | 36 +-- .../Api/Governance/Actions/VotingProcedure.hs | 24 +- .../internal/Cardano/Api/Governance/Poll.hs | 60 ++--- .../internal/Cardano/Api/HasTypeProxy.hs | 6 +- cardano-api/internal/Cardano/Api/Hash.hs | 6 +- cardano-api/internal/Cardano/Api/IO.hs | 17 +- cardano-api/internal/Cardano/Api/IO/Base.hs | 6 +- cardano-api/internal/Cardano/Api/IO/Compat.hs | 15 +- .../internal/Cardano/Api/IO/Compat/Posix.hs | 54 ++--- .../internal/Cardano/Api/IO/Compat/Win32.hs | 31 +-- cardano-api/internal/Cardano/Api/IPC.hs | 82 +++---- cardano-api/internal/Cardano/Api/IPC/Monad.hs | 20 +- .../internal/Cardano/Api/IPC/Version.hs | 2 +- cardano-api/internal/Cardano/Api/InMode.hs | 28 +-- cardano-api/internal/Cardano/Api/Json.hs | 4 +- .../internal/Cardano/Api/Keys/Byron.hs | 48 ++-- .../internal/Cardano/Api/Keys/Class.hs | 16 +- .../internal/Cardano/Api/Keys/Praos.hs | 42 ++-- cardano-api/internal/Cardano/Api/Keys/Read.hs | 21 +- .../internal/Cardano/Api/Keys/Shelley.hs | 166 +++++++------- .../internal/Cardano/Api/Ledger/Lens.hs | 30 +-- .../Api/LedgerEvents/ConvertLedgerEvent.hs | 62 +++--- .../Cardano/Api/LedgerEvents/LedgerEvent.hs | 26 ++- .../Api/LedgerEvents/Rule/BBODY/DELEGS.hs | 3 +- .../Api/LedgerEvents/Rule/BBODY/LEDGER.hs | 17 +- .../Api/LedgerEvents/Rule/BBODY/UTXOW.hs | 21 +- .../Api/LedgerEvents/Rule/TICK/NEWEPOCH.hs | 34 +-- .../Api/LedgerEvents/Rule/TICK/RUPD.hs | 10 +- .../internal/Cardano/Api/LedgerState.hs | 205 ++++++++---------- cardano-api/internal/Cardano/Api/Modes.hs | 17 +- .../internal/Cardano/Api/Monad/Error.hs | 25 +-- cardano-api/internal/Cardano/Api/NetworkId.hs | 10 +- .../Cardano/Api/OperationalCertificate.hs | 36 +-- cardano-api/internal/Cardano/Api/Orphans.hs | 64 +++--- cardano-api/internal/Cardano/Api/Pretty.hs | 9 +- cardano-api/internal/Cardano/Api/Protocol.hs | 29 +-- .../internal/Cardano/Api/Protocol/Version.hs | 5 +- .../Cardano/Api/ProtocolParameters.hs | 136 ++++++------ cardano-api/internal/Cardano/Api/Query.hs | 156 ++++++------- .../internal/Cardano/Api/Query/Expr.hs | 42 ++-- .../internal/Cardano/Api/Query/Types.hs | 10 +- .../internal/Cardano/Api/ReexposeLedger.hs | 176 ++++----------- .../internal/Cardano/Api/ReexposeNetwork.hs | 2 +- cardano-api/internal/Cardano/Api/Rewards.hs | 12 +- cardano-api/internal/Cardano/Api/Script.hs | 86 ++++---- .../internal/Cardano/Api/ScriptData.hs | 52 ++--- .../internal/Cardano/Api/SerialiseBech32.hs | 23 +- .../internal/Cardano/Api/SerialiseCBOR.hs | 8 +- .../internal/Cardano/Api/SerialiseJSON.hs | 19 +- .../Cardano/Api/SerialiseLedgerCddl.hs | 62 +++--- .../internal/Cardano/Api/SerialiseRaw.hs | 19 +- .../Cardano/Api/SerialiseTextEnvelope.hs | 48 ++-- .../internal/Cardano/Api/SerialiseUsing.hs | 21 +- .../internal/Cardano/Api/SpecialByron.hs | 57 ++--- .../internal/Cardano/Api/StakePoolMetadata.hs | 36 +-- cardano-api/internal/Cardano/Api/Tx/Body.hs | 194 ++++++++--------- cardano-api/internal/Cardano/Api/Tx/Sign.hs | 44 ++-- cardano-api/internal/Cardano/Api/TxIn.hs | 34 +-- .../internal/Cardano/Api/TxMetadata.hs | 32 +-- cardano-api/internal/Cardano/Api/Value.hs | 52 ++--- .../internal/Cardano/Api/ValueParser.hs | 27 +-- .../internal/Cardano/Api/Via/ShowOf.hs | 6 +- cardano-api/src/Cardano/Api.hs | 132 +++++------ cardano-api/src/Cardano/Api/Byron.hs | 18 +- .../src/Cardano/Api/ChainSync/Client.hs | 2 +- .../Cardano/Api/ChainSync/ClientPipelined.hs | 7 +- .../src/Cardano/Api/Crypto/Ed25519Bip32.hs | 34 +-- cardano-api/src/Cardano/Api/Experimental.hs | 2 +- cardano-api/src/Cardano/Api/Ledger.hs | 2 +- cardano-api/src/Cardano/Api/Network.hs | 2 +- cardano-api/src/Cardano/Api/Shelley.hs | 56 ++--- .../Test/Golden/Cardano/Api/Genesis.hs | 44 ++-- .../Test/Golden/Cardano/Api/Ledger.hs | 9 +- .../Golden/Cardano/Api/ProtocolParameters.hs | 52 +++-- .../Test/Golden/Cardano/Api/Typed/Script.hs | 22 +- .../Test/Golden/Cardano/Api/Value.hs | 37 ++-- .../Test/Golden/ErrorsSpec.hs | 29 +-- .../Test/Cardano/Api/Crypto.hs | 19 +- .../Test/Cardano/Api/EpochLeadership.hs | 68 +++--- .../cardano-api-test/Test/Cardano/Api/Eras.hs | 14 +- .../cardano-api-test/Test/Cardano/Api/IO.hs | 16 +- .../cardano-api-test/Test/Cardano/Api/Json.hs | 19 +- .../Test/Cardano/Api/KeysByron.hs | 16 +- .../Test/Cardano/Api/Ledger.hs | 29 ++- .../Test/Cardano/Api/Metadata.hs | 23 +- .../Test/Cardano/Api/ProtocolParameters.hs | 40 ++-- .../Test/Cardano/Api/Typed/Address.hs | 16 +- .../Test/Cardano/Api/Typed/Bech32.hs | 14 +- .../Test/Cardano/Api/Typed/CBOR.hs | 22 +- .../Test/Cardano/Api/Typed/Envelope.hs | 15 +- .../Test/Cardano/Api/Typed/JSON.hs | 18 +- .../Test/Cardano/Api/Typed/Ord.hs | 17 +- .../Test/Cardano/Api/Typed/Orphans.hs | 12 +- .../Test/Cardano/Api/Typed/RawBytes.hs | 15 +- .../Test/Cardano/Api/Typed/TxBody.hs | 22 +- .../Test/Cardano/Api/Typed/Value.hs | 35 ++- .../test/cardano-api-test/cardano-api-test.hs | 12 +- 135 files changed, 2272 insertions(+), 2269 deletions(-) diff --git a/cardano-api-gen/src/Test/Gen/Cardano/Api/Empty.hs b/cardano-api-gen/src/Test/Gen/Cardano/Api/Empty.hs index 0ce0529e8f..487ed9254e 100644 --- a/cardano-api-gen/src/Test/Gen/Cardano/Api/Empty.hs +++ b/cardano-api-gen/src/Test/Gen/Cardano/Api/Empty.hs @@ -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 diff --git a/cardano-api/gen/Test/Gen/Cardano/Api.hs b/cardano-api/gen/Test/Gen/Cardano/Api.hs index 21f4c42e6d..ac5e2fe956 100644 --- a/cardano-api/gen/Test/Gen/Cardano/Api.hs +++ b/cardano-api/gen/Test/Gen/Cardano/Api.hs @@ -16,13 +16,16 @@ import qualified Cardano.Ledger.BaseTypes as Ledger import qualified Cardano.Ledger.Coin as Ledger import qualified Cardano.Ledger.Plutus.CostModels as Plutus import qualified Cardano.Ledger.Plutus.Language as Alonzo -import Cardano.Ledger.Shelley.TxAuxData (Metadatum (..), ShelleyTxAuxData (..)) +import Cardano.Ledger.Shelley.TxAuxData (Metadatum (..), ShelleyTxAuxData (..)) + import qualified Data.Map.Strict as Map -import Data.Word (Word64) -import Hedgehog (Gen, Range) +import Data.Word (Word64) + +import Test.Gen.Cardano.Api.Typed (genCostModel, genRational) + +import Hedgehog (Gen, Range) import qualified Hedgehog.Gen as Gen import qualified Hedgehog.Internal.Range as Range -import Test.Gen.Cardano.Api.Typed (genCostModel, genRational) genMetadata :: Ledger.Era era => Gen (ShelleyTxAuxData era) genMetadata = do diff --git a/cardano-api/gen/Test/Gen/Cardano/Api/Byron.hs b/cardano-api/gen/Test/Gen/Cardano/Api/Byron.hs index 884ff13519..94361c0c5e 100644 --- a/cardano-api/gen/Test/Gen/Cardano/Api/Byron.hs +++ b/cardano-api/gen/Test/Gen/Cardano/Api/Byron.hs @@ -7,14 +7,17 @@ module Test.Gen.Cardano.Api.Byron ) where -import Cardano.Api hiding (txIns) -import Cardano.Api.Byron -import Data.Proxy -import Hedgehog -import Test.Gen.Cardano.Api.Typed -import Test.Hedgehog.Roundtrip.CBOR -import Test.Tasty -import Test.Tasty.Hedgehog +import Cardano.Api hiding (txIns) +import Cardano.Api.Byron + +import Data.Proxy + +import Test.Gen.Cardano.Api.Typed + +import Hedgehog +import Test.Hedgehog.Roundtrip.CBOR +import Test.Tasty +import Test.Tasty.Hedgehog prop_byron_roundtrip_txbody_CBOR :: Property prop_byron_roundtrip_txbody_CBOR = property $ do diff --git a/cardano-api/gen/Test/Gen/Cardano/Api/Era.hs b/cardano-api/gen/Test/Gen/Cardano/Api/Era.hs index cd620b555d..ce3c91734f 100644 --- a/cardano-api/gen/Test/Gen/Cardano/Api/Era.hs +++ b/cardano-api/gen/Test/Gen/Cardano/Api/Era.hs @@ -10,14 +10,18 @@ module Test.Gen.Cardano.Api.Era ) where -import Cardano.Api hiding (txIns) -import Cardano.Api.Shelley +import Cardano.Api hiding (txIns) +import Cardano.Api.Shelley + import qualified Cardano.Ledger.BaseTypes as Ledger import qualified Cardano.Ledger.Core as Ledger + import qualified Data.Functor.Identity as Ledger -import Test.Cardano.Ledger.Conway.Arbitrary () -import Test.Cardano.Ledger.Core.Arbitrary () -import Test.QuickCheck (Arbitrary (..)) + +import Test.Cardano.Ledger.Conway.Arbitrary () +import Test.Cardano.Ledger.Core.Arbitrary () + +import Test.QuickCheck (Arbitrary (..)) shelleyBasedEraTestConstraints :: () diff --git a/cardano-api/gen/Test/Gen/Cardano/Api/Metadata.hs b/cardano-api/gen/Test/Gen/Cardano/Api/Metadata.hs index 9aa676e652..606ff3b57f 100644 --- a/cardano-api/gen/Test/Gen/Cardano/Api/Metadata.hs +++ b/cardano-api/gen/Test/Gen/Cardano/Api/Metadata.hs @@ -7,19 +7,21 @@ module Test.Gen.Cardano.Api.Metadata ) where -import Cardano.Api -import Data.Aeson (ToJSON (..)) +import Cardano.Api + +import Data.Aeson (ToJSON (..)) import qualified Data.Aeson as Aeson import qualified Data.Aeson.Key as Aeson -import Data.ByteString (ByteString) +import Data.ByteString (ByteString) import qualified Data.ByteString as BS import qualified Data.ByteString.Base16 as Base16 import qualified Data.Map.Strict as Map -import Data.Text (Text) +import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Encoding as Text -import Data.Word (Word64) -import Hedgehog (Gen) +import Data.Word (Word64) + +import Hedgehog (Gen) import qualified Hedgehog.Gen as Gen import qualified Hedgehog.Internal.Gen as Gen import qualified Hedgehog.Range as Range diff --git a/cardano-api/gen/Test/Gen/Cardano/Api/ProtocolParameters.hs b/cardano-api/gen/Test/Gen/Cardano/Api/ProtocolParameters.hs index f05434ddc2..833b4adbb7 100644 --- a/cardano-api/gen/Test/Gen/Cardano/Api/ProtocolParameters.hs +++ b/cardano-api/gen/Test/Gen/Cardano/Api/ProtocolParameters.hs @@ -1,14 +1,17 @@ module Test.Gen.Cardano.Api.ProtocolParameters where -import Cardano.Api -import Cardano.Api.Ledger -import Cardano.Api.ProtocolParameters -import Hedgehog (MonadGen) +import Cardano.Api +import Cardano.Api.Ledger +import Cardano.Api.ProtocolParameters + +import Test.Gen.Cardano.Api.Typed (genCostModels) + +import Test.Cardano.Ledger.Alonzo.Arbitrary () +import Test.Cardano.Ledger.Conway.Arbitrary () + +import Hedgehog (MonadGen) import qualified Hedgehog.Gen as Gen import qualified Hedgehog.Gen.QuickCheck as Q -import Test.Cardano.Ledger.Alonzo.Arbitrary () -import Test.Cardano.Ledger.Conway.Arbitrary () -import Test.Gen.Cardano.Api.Typed (genCostModels) genStrictMaybe :: MonadGen m => m a -> m (StrictMaybe a) genStrictMaybe gen = diff --git a/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs b/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs index 9de83d4119..fb2ac41761 100644 --- a/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs +++ b/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs @@ -126,20 +126,19 @@ 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 @@ -147,30 +146,34 @@ 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" -} @@ -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) @@ -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 = diff --git a/cardano-api/gen/Test/Gen/Cardano/Crypto/Seed.hs b/cardano-api/gen/Test/Gen/Cardano/Crypto/Seed.hs index abd5e5511e..906a2ec209 100644 --- a/cardano-api/gen/Test/Gen/Cardano/Crypto/Seed.hs +++ b/cardano-api/gen/Test/Gen/Cardano/Crypto/Seed.hs @@ -4,11 +4,13 @@ module Test.Gen.Cardano.Crypto.Seed ) where -import Cardano.Api (AsType, Key) +import Cardano.Api (AsType, Key) import qualified Cardano.Api as API -import Cardano.Crypto.Seed (Seed) + +import Cardano.Crypto.Seed (Seed) import qualified Cardano.Crypto.Seed as C -import Hedgehog (MonadGen, Range) + +import Hedgehog (MonadGen, Range) import qualified Hedgehog.Gen as G import qualified Hedgehog.Range as R diff --git a/cardano-api/gen/Test/Hedgehog/Golden/ErrorMessage.hs b/cardano-api/gen/Test/Hedgehog/Golden/ErrorMessage.hs index 0c4170da99..afb3d58de9 100644 --- a/cardano-api/gen/Test/Hedgehog/Golden/ErrorMessage.hs +++ b/cardano-api/gen/Test/Hedgehog/Golden/ErrorMessage.hs @@ -2,16 +2,18 @@ module Test.Hedgehog.Golden.ErrorMessage where -import Cardano.Api (Error (..)) -import Cardano.Api.Pretty -import Data.Data -import GHC.Stack (HasCallStack, withFrozenCallStack) -import Hedgehog +import Cardano.Api (Error (..)) +import Cardano.Api.Pretty + +import Data.Data +import GHC.Stack (HasCallStack, withFrozenCallStack) +import System.FilePath (()) + +import Hedgehog import qualified Hedgehog.Extras.Test.Base as H import qualified Hedgehog.Extras.Test.Golden as H -import System.FilePath (()) -import Test.Tasty -import Test.Tasty.Hedgehog +import Test.Tasty +import Test.Tasty.Hedgehog -- | Generate test tree for the list of values. This 'TestTree' will serialize the values using 'Error' -- instance and compare them against golden files in the provided location. diff --git a/cardano-api/gen/Test/Hedgehog/Roundtrip/Bech32.hs b/cardano-api/gen/Test/Hedgehog/Roundtrip/Bech32.hs index e6f84ed37f..2d1074b2d8 100644 --- a/cardano-api/gen/Test/Hedgehog/Roundtrip/Bech32.hs +++ b/cardano-api/gen/Test/Hedgehog/Roundtrip/Bech32.hs @@ -3,8 +3,9 @@ module Test.Hedgehog.Roundtrip.Bech32 ) where -import Cardano.Api -import Hedgehog (Gen, Property) +import Cardano.Api + +import Hedgehog (Gen, Property) import qualified Hedgehog as H roundtrip_Bech32 diff --git a/cardano-api/gen/Test/Hedgehog/Roundtrip/CBOR.hs b/cardano-api/gen/Test/Hedgehog/Roundtrip/CBOR.hs index 07a4898569..1c543b3318 100644 --- a/cardano-api/gen/Test/Hedgehog/Roundtrip/CBOR.hs +++ b/cardano-api/gen/Test/Hedgehog/Roundtrip/CBOR.hs @@ -7,9 +7,11 @@ module Test.Hedgehog.Roundtrip.CBOR ) where -import Cardano.Api -import GHC.Stack (HasCallStack) +import Cardano.Api + +import GHC.Stack (HasCallStack) import qualified GHC.Stack as GHC + import qualified Hedgehog as H {- HLINT ignore "Use camelCase" -} diff --git a/cardano-api/internal/Cardano/Api/Address.hs b/cardano-api/internal/Cardano/Api/Address.hs index 22b7345ae1..3bd83a7056 100644 --- a/cardano-api/internal/Cardano/Api/Address.hs +++ b/cardano-api/internal/Cardano/Api/Address.hs @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 = @@ -404,13 +406,13 @@ 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 @@ -418,13 +420,13 @@ instance Ord (AddressInEra era) where (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) @@ -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 = @@ -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 = @@ -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 @@ -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 = diff --git a/cardano-api/internal/Cardano/Api/Block.hs b/cardano-api/internal/Cardano/Api/Block.hs index 3ec24aa134..7e3a0ae83f 100644 --- a/cardano-api/internal/Cardano/Api/Block.hs +++ b/cardano-api/internal/Cardano/Api/Block.hs @@ -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 @@ -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" -} @@ -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 @@ -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 diff --git a/cardano-api/internal/Cardano/Api/Certificate.hs b/cardano-api/internal/Cardano/Api/Certificate.hs index 5b74639f77..e616296fbf 100644 --- a/cardano-api/internal/Cardano/Api/Certificate.hs +++ b/cardano-api/internal/Cardano/Api/Certificate.hs @@ -71,38 +71,40 @@ module Cardano.Api.Certificate ) where -import Cardano.Api.Address -import Cardano.Api.DRepMetadata -import Cardano.Api.Eon.ConwayEraOnwards -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eon.ShelleyToBabbageEra -import Cardano.Api.Eras -import Cardano.Api.Governance.Actions.VotingProcedure -import Cardano.Api.HasTypeProxy -import Cardano.Api.Keys.Praos -import Cardano.Api.Keys.Shelley -import Cardano.Api.ReexposeLedger (EraCrypto, StandardCrypto) +import Cardano.Api.Address +import Cardano.Api.DRepMetadata +import Cardano.Api.Eon.ConwayEraOnwards +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eon.ShelleyToBabbageEra +import Cardano.Api.Eras +import Cardano.Api.Governance.Actions.VotingProcedure +import Cardano.Api.HasTypeProxy +import Cardano.Api.Keys.Praos +import Cardano.Api.Keys.Shelley +import Cardano.Api.ReexposeLedger (EraCrypto, StandardCrypto) import qualified Cardano.Api.ReexposeLedger as Ledger -import Cardano.Api.Script -import Cardano.Api.SerialiseCBOR -import Cardano.Api.SerialiseTextEnvelope -import Cardano.Api.StakePoolMetadata -import Cardano.Api.Utils (noInlineMaybeToStrictMaybe) -import Cardano.Api.Value +import Cardano.Api.Script +import Cardano.Api.SerialiseCBOR +import Cardano.Api.SerialiseTextEnvelope +import Cardano.Api.StakePoolMetadata +import Cardano.Api.Utils (noInlineMaybeToStrictMaybe) +import Cardano.Api.Value + import qualified Cardano.Ledger.Coin as L import qualified Cardano.Ledger.Keys as Ledger -import Data.ByteString (ByteString) + +import Data.ByteString (ByteString) import qualified Data.ByteString as BS import qualified Data.Foldable as Foldable -import Data.IP (IPv4, IPv6) -import Data.Maybe +import Data.IP (IPv4, IPv6) +import Data.Maybe import qualified Data.Sequence.Strict as Seq import qualified Data.Set as Set -import Data.Text (Text) +import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Encoding as Text -import Data.Typeable -import Network.Socket (PortNumber) +import Data.Typeable +import Network.Socket (PortNumber) -- ---------------------------------------------------------------------------- -- Certificates embedded in transactions @@ -127,7 +129,7 @@ data Certificate era where :: ConwayEraOnwards era -> Ledger.ConwayTxCert (ShelleyLedgerEra era) -> Certificate era - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deriving instance Eq (Certificate era) @@ -164,26 +166,26 @@ instance "CertificateShelley" (const "CertificateConway") textEnvelopeDefaultDescr cert = case cert of - ShelleyRelatedCertificate _ (Ledger.ShelleyTxCertDelegCert Ledger.ShelleyRegCert {}) -> "Stake address registration" - ShelleyRelatedCertificate _ (Ledger.ShelleyTxCertDelegCert Ledger.ShelleyUnRegCert {}) -> "Stake address deregistration" - ShelleyRelatedCertificate _ (Ledger.ShelleyTxCertDelegCert Ledger.ShelleyDelegCert {}) -> "Stake address delegation" - ShelleyRelatedCertificate _ (Ledger.ShelleyTxCertPool Ledger.RetirePool {}) -> "Pool retirement" - ShelleyRelatedCertificate _ (Ledger.ShelleyTxCertPool Ledger.RegPool {}) -> "Pool registration" - ShelleyRelatedCertificate _ Ledger.ShelleyTxCertGenesisDeleg {} -> "Genesis key delegation" - ShelleyRelatedCertificate _ Ledger.ShelleyTxCertMir {} -> "MIR" + ShelleyRelatedCertificate _ (Ledger.ShelleyTxCertDelegCert Ledger.ShelleyRegCert{}) -> "Stake address registration" + ShelleyRelatedCertificate _ (Ledger.ShelleyTxCertDelegCert Ledger.ShelleyUnRegCert{}) -> "Stake address deregistration" + ShelleyRelatedCertificate _ (Ledger.ShelleyTxCertDelegCert Ledger.ShelleyDelegCert{}) -> "Stake address delegation" + ShelleyRelatedCertificate _ (Ledger.ShelleyTxCertPool Ledger.RetirePool{}) -> "Pool retirement" + ShelleyRelatedCertificate _ (Ledger.ShelleyTxCertPool Ledger.RegPool{}) -> "Pool registration" + ShelleyRelatedCertificate _ Ledger.ShelleyTxCertGenesisDeleg{} -> "Genesis key delegation" + ShelleyRelatedCertificate _ Ledger.ShelleyTxCertMir{} -> "MIR" -- Conway and onwards related -- Constitutional Committee related - ConwayCertificate _ (Ledger.ConwayTxCertGov Ledger.ConwayRegDRep {}) -> "Constitution committee member key registration" - ConwayCertificate _ (Ledger.ConwayTxCertGov Ledger.ConwayUnRegDRep {}) -> "Constitution committee member key unregistration" - ConwayCertificate _ (Ledger.ConwayTxCertGov Ledger.ConwayUpdateDRep {}) -> "Constitution committee member key registration update" - ConwayCertificate _ (Ledger.ConwayTxCertGov Ledger.ConwayAuthCommitteeHotKey {}) -> "Constitution committee member hot key registration" - ConwayCertificate _ (Ledger.ConwayTxCertGov Ledger.ConwayResignCommitteeColdKey {}) -> "Constitution committee member hot key resignation" - ConwayCertificate _ (Ledger.ConwayTxCertDeleg Ledger.ConwayRegCert {}) -> "Stake address registration" - ConwayCertificate _ (Ledger.ConwayTxCertDeleg Ledger.ConwayUnRegCert {}) -> "Stake address deregistration" - ConwayCertificate _ (Ledger.ConwayTxCertDeleg Ledger.ConwayDelegCert {}) -> "Stake address delegation" - ConwayCertificate _ (Ledger.ConwayTxCertDeleg Ledger.ConwayRegDelegCert {}) -> "Stake address registration and delegation" - ConwayCertificate _ (Ledger.ConwayTxCertPool Ledger.RegPool {}) -> "Pool registration" - ConwayCertificate _ (Ledger.ConwayTxCertPool Ledger.RetirePool {}) -> "Pool retirement" + ConwayCertificate _ (Ledger.ConwayTxCertGov Ledger.ConwayRegDRep{}) -> "Constitution committee member key registration" + ConwayCertificate _ (Ledger.ConwayTxCertGov Ledger.ConwayUnRegDRep{}) -> "Constitution committee member key unregistration" + ConwayCertificate _ (Ledger.ConwayTxCertGov Ledger.ConwayUpdateDRep{}) -> "Constitution committee member key registration update" + ConwayCertificate _ (Ledger.ConwayTxCertGov Ledger.ConwayAuthCommitteeHotKey{}) -> "Constitution committee member hot key registration" + ConwayCertificate _ (Ledger.ConwayTxCertGov Ledger.ConwayResignCommitteeColdKey{}) -> "Constitution committee member hot key resignation" + ConwayCertificate _ (Ledger.ConwayTxCertDeleg Ledger.ConwayRegCert{}) -> "Stake address registration" + ConwayCertificate _ (Ledger.ConwayTxCertDeleg Ledger.ConwayUnRegCert{}) -> "Stake address deregistration" + ConwayCertificate _ (Ledger.ConwayTxCertDeleg Ledger.ConwayDelegCert{}) -> "Stake address delegation" + ConwayCertificate _ (Ledger.ConwayTxCertDeleg Ledger.ConwayRegDelegCert{}) -> "Stake address registration and delegation" + ConwayCertificate _ (Ledger.ConwayTxCertPool Ledger.RegPool{}) -> "Pool registration" + ConwayCertificate _ (Ledger.ConwayTxCertPool Ledger.RetirePool{}) -> "Pool retirement" -- ---------------------------------------------------------------------------- -- Stake pool parameters @@ -523,7 +525,7 @@ filterUnRegCreds = Ledger.RegPoolTxCert _ -> Nothing Ledger.RetirePoolTxCert _ _ -> Nothing Ledger.MirTxCert _ -> Nothing - Ledger.GenesisDelegTxCert {} -> Nothing + Ledger.GenesisDelegTxCert{} -> Nothing ConwayCertificate cEra conwayCert -> conwayEraOnwardsConstraints cEra $ case conwayCert of Ledger.RegTxCert _ -> Nothing @@ -533,12 +535,12 @@ filterUnRegCreds = Ledger.RegDepositTxCert _ _ -> Nothing Ledger.UnRegDepositTxCert _ _ -> Nothing Ledger.DelegTxCert _ _ -> Nothing - Ledger.RegDepositDelegTxCert {} -> Nothing - Ledger.AuthCommitteeHotKeyTxCert {} -> Nothing - Ledger.ResignCommitteeColdTxCert {} -> Nothing - Ledger.RegDRepTxCert {} -> Nothing - Ledger.UnRegDRepTxCert {} -> Nothing - Ledger.UpdateDRepTxCert {} -> Nothing + Ledger.RegDepositDelegTxCert{} -> Nothing + Ledger.AuthCommitteeHotKeyTxCert{} -> Nothing + Ledger.ResignCommitteeColdTxCert{} -> Nothing + Ledger.RegDRepTxCert{} -> Nothing + Ledger.UnRegDRepTxCert{} -> Nothing + Ledger.UpdateDRepTxCert{} -> Nothing filterUnRegDRepCreds :: Certificate era -> Maybe (Ledger.Credential Ledger.DRepRole Ledger.StandardCrypto) @@ -553,12 +555,12 @@ filterUnRegDRepCreds = \case Ledger.RegDepositTxCert _ _ -> Nothing Ledger.UnRegDepositTxCert _ _ -> Nothing Ledger.DelegTxCert _ _ -> Nothing - Ledger.RegDepositDelegTxCert {} -> Nothing - Ledger.AuthCommitteeHotKeyTxCert {} -> Nothing - Ledger.ResignCommitteeColdTxCert {} -> Nothing - Ledger.RegDRepTxCert {} -> Nothing + Ledger.RegDepositDelegTxCert{} -> Nothing + Ledger.AuthCommitteeHotKeyTxCert{} -> Nothing + Ledger.ResignCommitteeColdTxCert{} -> Nothing + Ledger.RegDRepTxCert{} -> Nothing Ledger.UnRegDRepTxCert cred _ -> Just cred - Ledger.UpdateDRepTxCert {} -> Nothing + Ledger.UpdateDRepTxCert{} -> Nothing -- ---------------------------------------------------------------------------- -- Internal conversion functions diff --git a/cardano-api/internal/Cardano/Api/Convenience/Construction.hs b/cardano-api/internal/Cardano/Api/Convenience/Construction.hs index a46bc74e9b..95c4a549f9 100644 --- a/cardano-api/internal/Cardano/Api/Convenience/Construction.hs +++ b/cardano-api/internal/Cardano/Api/Convenience/Construction.hs @@ -14,24 +14,26 @@ module Cardano.Api.Convenience.Construction ) where -import Cardano.Api.Address -import Cardano.Api.Certificate -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Fees -import Cardano.Api.ProtocolParameters -import Cardano.Api.Query -import Cardano.Api.Tx.Body -import Cardano.Api.Tx.Sign -import Cardano.Api.Utils +import Cardano.Api.Address +import Cardano.Api.Certificate +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Fees +import Cardano.Api.ProtocolParameters +import Cardano.Api.Query +import Cardano.Api.Tx.Body +import Cardano.Api.Tx.Sign +import Cardano.Api.Utils + import qualified Cardano.Ledger.Api as L import qualified Cardano.Ledger.Coin as L import qualified Cardano.Ledger.Credential as L import qualified Cardano.Ledger.Keys as L + import qualified Data.List as List import qualified Data.Map.Strict as Map -import Data.Set (Set) +import Data.Set (Set) import qualified Data.Set as Set -import Data.Text (Text) +import Data.Text (Text) import qualified Data.Text as Text -- | Construct a balanced transaction. diff --git a/cardano-api/internal/Cardano/Api/Convenience/Query.hs b/cardano-api/internal/Cardano/Api/Convenience/Query.hs index 36febbc62d..10edfd4d73 100644 --- a/cardano-api/internal/Cardano/Api/Convenience/Query.hs +++ b/cardano-api/internal/Cardano/Api/Convenience/Query.hs @@ -20,41 +20,43 @@ module Cardano.Api.Convenience.Query ) where -import Cardano.Api.Address -import Cardano.Api.Certificate -import Cardano.Api.Eon.ConwayEraOnwards -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras -import Cardano.Api.Feature (Featured (..)) -import Cardano.Api.IO -import Cardano.Api.IPC -import Cardano.Api.IPC.Monad -import Cardano.Api.Monad.Error -import Cardano.Api.NetworkId -import Cardano.Api.ProtocolParameters -import Cardano.Api.Query -import Cardano.Api.Query.Expr -import Cardano.Api.Tx.Body -import Cardano.Api.Utils +import Cardano.Api.Address +import Cardano.Api.Certificate +import Cardano.Api.Eon.ConwayEraOnwards +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras +import Cardano.Api.Feature (Featured (..)) +import Cardano.Api.IO +import Cardano.Api.IPC +import Cardano.Api.IPC.Monad +import Cardano.Api.Monad.Error +import Cardano.Api.NetworkId +import Cardano.Api.ProtocolParameters +import Cardano.Api.Query +import Cardano.Api.Query.Expr +import Cardano.Api.Tx.Body +import Cardano.Api.Utils + import qualified Cardano.Ledger.Api as L -import Cardano.Ledger.CertState (DRepState (..)) +import Cardano.Ledger.CertState (DRepState (..)) import qualified Cardano.Ledger.Coin as L import qualified Cardano.Ledger.Credential as L import qualified Cardano.Ledger.Keys as L import qualified Cardano.Ledger.Shelley.LedgerState as L -import Control.Exception.Safe (SomeException, displayException) -import Control.Monad -import Data.Bifunctor (first) -import Data.Function ((&)) -import Data.Map (Map) +import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (EraMismatch (..)) +import Ouroboros.Network.Protocol.LocalStateQuery.Type (Target (..)) + +import Control.Exception.Safe (SomeException, displayException) +import Control.Monad +import Data.Bifunctor (first) +import Data.Function ((&)) +import Data.Map (Map) import qualified Data.Map as Map -import Data.Maybe (mapMaybe) -import Data.Set (Set) +import Data.Maybe (mapMaybe) +import Data.Set (Set) import qualified Data.Set as Set -import Data.Text (Text) -import GHC.Exts (IsString (..)) -import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (EraMismatch (..)) -import Ouroboros.Network.Protocol.LocalStateQuery.Type (Target (..)) +import Data.Text (Text) +import GHC.Exts (IsString (..)) data QueryConvenienceError = AcqFailure AcquiringFailure @@ -62,7 +64,7 @@ data QueryConvenienceError | ByronEraNotSupported | QceUnsupportedNtcVersion !UnsupportedNtcVersionError | QceUnexpectedException !SomeException - deriving (Show) + deriving Show renderQueryConvenienceError :: QueryConvenienceError -> Text renderQueryConvenienceError (AcqFailure e) = @@ -88,7 +90,7 @@ renderQueryConvenienceError (QceUnexpectedException e) = "Unexpected exception while processing query:\n" <> fromString (displayException e) newtype TxCurrentTreasuryValue = TxCurrentTreasuryValue {unTxCurrentTreasuryValue :: L.Coin} - deriving newtype (Show) + deriving newtype Show -- | A convenience function to query the relevant information, from -- the local node, for Cardano.Api.Convenience.Construction.constructBalancedTx @@ -165,7 +167,7 @@ queryStateForBalancedTx era allTxIns certs = runExceptT $ do caseShelleyToBabbageOrConwayEraOnwards (const $ pure Nothing) ( \cOnwards -> do - L.AccountState {L.asTreasury} <- + L.AccountState{L.asTreasury} <- lift (queryAccountState cOnwards) & onLeft (left . QceUnsupportedNtcVersion) & onLeft (left . QueryEraMismatch) diff --git a/cardano-api/internal/Cardano/Api/DRepMetadata.hs b/cardano-api/internal/Cardano/Api/DRepMetadata.hs index 589b474c75..d883d311ff 100644 --- a/cardano-api/internal/Cardano/Api/DRepMetadata.hs +++ b/cardano-api/internal/Cardano/Api/DRepMetadata.hs @@ -13,18 +13,20 @@ module Cardano.Api.DRepMetadata ) where -import Cardano.Api.Eras -import Cardano.Api.HasTypeProxy -import Cardano.Api.Hash -import Cardano.Api.Keys.Byron -import Cardano.Api.Keys.Praos -import Cardano.Api.Script -import Cardano.Api.SerialiseRaw +import Cardano.Api.Eras +import Cardano.Api.Hash +import Cardano.Api.HasTypeProxy +import Cardano.Api.Keys.Byron +import Cardano.Api.Keys.Praos +import Cardano.Api.Script +import Cardano.Api.SerialiseRaw + import qualified Cardano.Crypto.Hash.Class as Crypto -import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Crypto (StandardCrypto) import qualified Cardano.Ledger.Keys as Shelley -import Data.ByteString (ByteString) -import Data.Either.Combinators (maybeToRight) + +import Data.ByteString (ByteString) +import Data.Either.Combinators (maybeToRight) -- ---------------------------------------------------------------------------- -- DRep metadata diff --git a/cardano-api/internal/Cardano/Api/DeserialiseAnyOf.hs b/cardano-api/internal/Cardano/Api/DeserialiseAnyOf.hs index db524de708..57e15d4720 100644 --- a/cardano-api/internal/Cardano/Api/DeserialiseAnyOf.hs +++ b/cardano-api/internal/Cardano/Api/DeserialiseAnyOf.hs @@ -21,29 +21,31 @@ module Cardano.Api.DeserialiseAnyOf ) where -import Cardano.Api.Address -import Cardano.Api.Error -import Cardano.Api.Keys.Byron -import Cardano.Api.Keys.Class -import Cardano.Api.Keys.Praos -import Cardano.Api.Keys.Shelley -import Cardano.Api.SerialiseBech32 -import Cardano.Api.SerialiseRaw -import Cardano.Api.SerialiseTextEnvelope +import Cardano.Api.Address +import Cardano.Api.Error +import Cardano.Api.Keys.Byron +import Cardano.Api.Keys.Class +import Cardano.Api.Keys.Praos +import Cardano.Api.Keys.Shelley +import Cardano.Api.SerialiseBech32 +import Cardano.Api.SerialiseRaw +import Cardano.Api.SerialiseTextEnvelope + import qualified Cardano.Chain.Common as Common import qualified Cardano.Crypto.Signing as Crypto + import qualified Data.Aeson as Aeson -import Data.Bifunctor (first) -import Data.ByteString (ByteString) +import Data.Bifunctor (first) +import Data.ByteString (ByteString) import qualified Data.ByteString.Char8 as BSC -import Data.Char (toLower) -import Data.Data (Data) -import Data.List.NonEmpty (NonEmpty) +import Data.Char (toLower) +import Data.Data (Data) +import Data.List.NonEmpty (NonEmpty) import qualified Data.List.NonEmpty as NE -import Data.Text (Text) +import Data.Text (Text) import qualified Data.Text.Encoding as Text -import Formatting (build, sformat, (%)) -import Prettyprinter +import Formatting (build, sformat, (%)) +import Prettyprinter ------------------------------------------------------------------------------ -- Formatted/encoded input deserialisation @@ -139,7 +141,7 @@ deserialiseInput asType acceptedFormats inputBs = Right res -> DeserialiseInputSuccess res -- The input was valid a text envelope, but there was a type mismatch -- error. - Left err@TextEnvelopeTypeError {} -> + Left err@TextEnvelopeTypeError{} -> DeserialiseInputError (InputTextEnvelopeError err) -- The input was not valid a text envelope. Left _ -> DeserialiseInputErrorFormatMismatch @@ -208,7 +210,7 @@ deserialiseInputAnyOf bech32Types textEnvTypes inputBs = Right res -> DeserialiseInputSuccess res -- The input was valid a text envelope, but there was a type mismatch -- error. - Left err@TextEnvelopeTypeError {} -> + Left err@TextEnvelopeTypeError{} -> DeserialiseInputError (InputTextEnvelopeError err) -- The input was not valid a text envelope. Left _ -> DeserialiseInputErrorFormatMismatch @@ -240,7 +242,7 @@ data SomeAddressVerificationKey | ACommitteeColdExtendedVerificationKey (VerificationKey CommitteeColdExtendedKey) | ACommitteeHotVerificationKey (VerificationKey CommitteeHotKey) | ACommitteeHotExtendedVerificationKey (VerificationKey CommitteeHotExtendedKey) - deriving (Show) + deriving Show renderSomeAddressVerificationKey :: SomeAddressVerificationKey -> Text renderSomeAddressVerificationKey = diff --git a/cardano-api/internal/Cardano/Api/Eon/AllegraEraOnwards.hs b/cardano-api/internal/Cardano/Api/Eon/AllegraEraOnwards.hs index ddd7870e06..aae2dd17b0 100644 --- a/cardano-api/internal/Cardano/Api/Eon/AllegraEraOnwards.hs +++ b/cardano-api/internal/Cardano/Api/Eon/AllegraEraOnwards.hs @@ -16,11 +16,12 @@ module Cardano.Api.Eon.AllegraEraOnwards ) where -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Core -import Cardano.Api.Modes -import Cardano.Api.Query.Types -import Cardano.Binary +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Core +import Cardano.Api.Modes +import Cardano.Api.Query.Types + +import Cardano.Binary import qualified Cardano.Crypto.Hash.Blake2b as Blake2b import qualified Cardano.Crypto.Hash.Class as C import qualified Cardano.Crypto.VRF as C @@ -28,12 +29,13 @@ import qualified Cardano.Ledger.Api as L import qualified Cardano.Ledger.BaseTypes as L import qualified Cardano.Ledger.Core as L import qualified Cardano.Ledger.SafeHash as L -import Data.Aeson -import Data.Typeable (Typeable) import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus +import Data.Aeson +import Data.Typeable (Typeable) + data AllegraEraOnwards era where AllegraEraOnwardsAllegra :: AllegraEraOnwards AllegraEra AllegraEraOnwardsMary :: AllegraEraOnwards MaryEra diff --git a/cardano-api/internal/Cardano/Api/Eon/AlonzoEraOnwards.hs b/cardano-api/internal/Cardano/Api/Eon/AlonzoEraOnwards.hs index bd67019114..2a581029c3 100644 --- a/cardano-api/internal/Cardano/Api/Eon/AlonzoEraOnwards.hs +++ b/cardano-api/internal/Cardano/Api/Eon/AlonzoEraOnwards.hs @@ -16,11 +16,12 @@ module Cardano.Api.Eon.AlonzoEraOnwards ) where -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Core -import Cardano.Api.Modes -import Cardano.Api.Query.Types -import Cardano.Binary +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Core +import Cardano.Api.Modes +import Cardano.Api.Query.Types + +import Cardano.Binary import qualified Cardano.Crypto.Hash.Blake2b as Blake2b import qualified Cardano.Crypto.Hash.Class as C import qualified Cardano.Crypto.VRF as C @@ -35,12 +36,13 @@ import qualified Cardano.Ledger.Core as L import qualified Cardano.Ledger.Mary.Value as L import qualified Cardano.Ledger.SafeHash as L import qualified Cardano.Ledger.UTxO as L -import Data.Aeson -import Data.Typeable (Typeable) import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus +import Data.Aeson +import Data.Typeable (Typeable) + data AlonzoEraOnwards era where AlonzoEraOnwardsAlonzo :: AlonzoEraOnwards AlonzoEra AlonzoEraOnwardsBabbage :: AlonzoEraOnwards BabbageEra diff --git a/cardano-api/internal/Cardano/Api/Eon/BabbageEraOnwards.hs b/cardano-api/internal/Cardano/Api/Eon/BabbageEraOnwards.hs index b408da0209..cba37e9434 100644 --- a/cardano-api/internal/Cardano/Api/Eon/BabbageEraOnwards.hs +++ b/cardano-api/internal/Cardano/Api/Eon/BabbageEraOnwards.hs @@ -16,11 +16,12 @@ module Cardano.Api.Eon.BabbageEraOnwards ) where -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Core -import Cardano.Api.Modes -import Cardano.Api.Query.Types -import Cardano.Binary +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Core +import Cardano.Api.Modes +import Cardano.Api.Query.Types + +import Cardano.Binary import qualified Cardano.Crypto.Hash.Blake2b as Blake2b import qualified Cardano.Crypto.Hash.Class as C import qualified Cardano.Crypto.VRF as C @@ -33,12 +34,13 @@ import qualified Cardano.Ledger.Core as L import qualified Cardano.Ledger.Mary.Value as L import qualified Cardano.Ledger.SafeHash as L import qualified Cardano.Ledger.UTxO as L -import Data.Aeson -import Data.Typeable (Typeable) import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus +import Data.Aeson +import Data.Typeable (Typeable) + data BabbageEraOnwards era where BabbageEraOnwardsBabbage :: BabbageEraOnwards BabbageEra BabbageEraOnwardsConway :: BabbageEraOnwards ConwayEra diff --git a/cardano-api/internal/Cardano/Api/Eon/ByronToAlonzoEra.hs b/cardano-api/internal/Cardano/Api/Eon/ByronToAlonzoEra.hs index 5606e59d62..d53b780a48 100644 --- a/cardano-api/internal/Cardano/Api/Eon/ByronToAlonzoEra.hs +++ b/cardano-api/internal/Cardano/Api/Eon/ByronToAlonzoEra.hs @@ -14,8 +14,9 @@ module Cardano.Api.Eon.ByronToAlonzoEra ) where -import Cardano.Api.Eras.Core -import Data.Typeable (Typeable) +import Cardano.Api.Eras.Core + +import Data.Typeable (Typeable) data ByronToAlonzoEra era where ByronToAlonzoEraByron :: ByronToAlonzoEra ByronEra diff --git a/cardano-api/internal/Cardano/Api/Eon/ConwayEraOnwards.hs b/cardano-api/internal/Cardano/Api/Eon/ConwayEraOnwards.hs index 789bcc2a69..6bf52ce3bd 100644 --- a/cardano-api/internal/Cardano/Api/Eon/ConwayEraOnwards.hs +++ b/cardano-api/internal/Cardano/Api/Eon/ConwayEraOnwards.hs @@ -16,11 +16,12 @@ module Cardano.Api.Eon.ConwayEraOnwards ) where -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Core -import Cardano.Api.Modes -import Cardano.Api.Query.Types -import Cardano.Binary +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Core +import Cardano.Api.Modes +import Cardano.Api.Query.Types + +import Cardano.Binary import qualified Cardano.Crypto.Hash.Blake2b as Blake2b import qualified Cardano.Crypto.Hash.Class as C import qualified Cardano.Crypto.VRF as C @@ -34,12 +35,13 @@ import qualified Cardano.Ledger.Conway.TxCert as L import qualified Cardano.Ledger.Mary.Value as L import qualified Cardano.Ledger.SafeHash as L import qualified Cardano.Ledger.UTxO as L -import Data.Aeson -import Data.Typeable (Typeable) import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus +import Data.Aeson +import Data.Typeable (Typeable) + data ConwayEraOnwards era where ConwayEraOnwardsConway :: ConwayEraOnwards ConwayEra diff --git a/cardano-api/internal/Cardano/Api/Eon/MaryEraOnwards.hs b/cardano-api/internal/Cardano/Api/Eon/MaryEraOnwards.hs index b79a5e36ed..2fe9d2ea0a 100644 --- a/cardano-api/internal/Cardano/Api/Eon/MaryEraOnwards.hs +++ b/cardano-api/internal/Cardano/Api/Eon/MaryEraOnwards.hs @@ -16,11 +16,12 @@ module Cardano.Api.Eon.MaryEraOnwards ) where -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Core -import Cardano.Api.Modes -import Cardano.Api.Query.Types -import Cardano.Binary +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Core +import Cardano.Api.Modes +import Cardano.Api.Query.Types + +import Cardano.Binary import qualified Cardano.Crypto.Hash.Blake2b as Blake2b import qualified Cardano.Crypto.Hash.Class as C import qualified Cardano.Crypto.VRF as C @@ -30,12 +31,13 @@ import qualified Cardano.Ledger.Core as L import qualified Cardano.Ledger.Mary.Value as L import qualified Cardano.Ledger.SafeHash as L import qualified Cardano.Ledger.UTxO as L -import Data.Aeson -import Data.Typeable (Typeable) import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus +import Data.Aeson +import Data.Typeable (Typeable) + data MaryEraOnwards era where MaryEraOnwardsMary :: MaryEraOnwards MaryEra MaryEraOnwardsAlonzo :: MaryEraOnwards AlonzoEra diff --git a/cardano-api/internal/Cardano/Api/Eon/ShelleyBasedEra.hs b/cardano-api/internal/Cardano/Api/Eon/ShelleyBasedEra.hs index 2e7a788e66..aa279c2afc 100644 --- a/cardano-api/internal/Cardano/Api/Eon/ShelleyBasedEra.hs +++ b/cardano-api/internal/Cardano/Api/Eon/ShelleyBasedEra.hs @@ -34,37 +34,33 @@ module Cardano.Api.Eon.ShelleyBasedEra ) where -import Cardano.Api.Eras.Core -import Cardano.Api.Modes -import Cardano.Api.Orphans () -import Cardano.Api.Pretty (Pretty) +import Cardano.Api.Eras.Core +import Cardano.Api.Modes +import Cardano.Api.Orphans () +import Cardano.Api.Pretty (Pretty) + import qualified Cardano.Crypto.Hash.Blake2b as Blake2b import qualified Cardano.Crypto.Hash.Class as C import qualified Cardano.Crypto.VRF as C import qualified Cardano.Ledger.Api as L import qualified Cardano.Ledger.BaseTypes as L -import Cardano.Ledger.Binary (FromCBOR) +import Cardano.Ledger.Binary (FromCBOR) import qualified Cardano.Ledger.Core as L import qualified Cardano.Ledger.SafeHash as L import qualified Cardano.Ledger.Shelley.Rules as L import qualified Cardano.Ledger.UTxO as L -import Control.DeepSeq -import Data.Aeson (FromJSON (..), ToJSON, toJSON, withText) -import qualified Data.Text as Text -import Data.Type.Equality (TestEquality (..), (:~:) (Refl)) -import Data.Typeable (Typeable) import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus -import Ouroboros.Consensus.Shelley.Eras as Consensus - ( StandardAllegra - , StandardAlonzo - , StandardBabbage - , StandardConway - , StandardMary - , StandardShelley - ) +import Ouroboros.Consensus.Shelley.Eras as Consensus (StandardAllegra, StandardAlonzo, + StandardBabbage, StandardConway, StandardMary, StandardShelley) import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus -import Text.Pretty (Pretty (..)) + +import Control.DeepSeq +import Data.Aeson (FromJSON (..), ToJSON, toJSON, withText) +import qualified Data.Text as Text +import Data.Type.Equality (TestEquality (..), (:~:) (Refl)) +import Data.Typeable (Typeable) +import Text.Pretty (Pretty (..)) -- | Determine the value to use for a feature in a given 'ShelleyBasedEra'. inEonForShelleyBasedEra diff --git a/cardano-api/internal/Cardano/Api/Eon/ShelleyEraOnly.hs b/cardano-api/internal/Cardano/Api/Eon/ShelleyEraOnly.hs index 83cad1f69a..027088ddc1 100644 --- a/cardano-api/internal/Cardano/Api/Eon/ShelleyEraOnly.hs +++ b/cardano-api/internal/Cardano/Api/Eon/ShelleyEraOnly.hs @@ -16,11 +16,12 @@ module Cardano.Api.Eon.ShelleyEraOnly ) where -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Core -import Cardano.Api.Modes -import Cardano.Api.Query.Types -import Cardano.Binary +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Core +import Cardano.Api.Modes +import Cardano.Api.Query.Types + +import Cardano.Binary import qualified Cardano.Crypto.Hash.Blake2b as Blake2b import qualified Cardano.Crypto.Hash.Class as C import qualified Cardano.Crypto.VRF as C @@ -30,12 +31,13 @@ import qualified Cardano.Ledger.Coin as L import qualified Cardano.Ledger.Core as L import qualified Cardano.Ledger.SafeHash as L import qualified Cardano.Ledger.Shelley.TxCert as L -import Data.Aeson -import Data.Typeable (Typeable) import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus +import Data.Aeson +import Data.Typeable (Typeable) + data ShelleyEraOnly era where ShelleyEraOnlyShelley :: ShelleyEraOnly ShelleyEra diff --git a/cardano-api/internal/Cardano/Api/Eon/ShelleyToAllegraEra.hs b/cardano-api/internal/Cardano/Api/Eon/ShelleyToAllegraEra.hs index 98fa3861df..3fe4232c17 100644 --- a/cardano-api/internal/Cardano/Api/Eon/ShelleyToAllegraEra.hs +++ b/cardano-api/internal/Cardano/Api/Eon/ShelleyToAllegraEra.hs @@ -16,11 +16,12 @@ module Cardano.Api.Eon.ShelleyToAllegraEra ) where -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Core -import Cardano.Api.Modes -import Cardano.Api.Query.Types -import Cardano.Binary +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Core +import Cardano.Api.Modes +import Cardano.Api.Query.Types + +import Cardano.Binary import qualified Cardano.Crypto.Hash.Blake2b as Blake2b import qualified Cardano.Crypto.Hash.Class as C import qualified Cardano.Crypto.VRF as C @@ -31,12 +32,13 @@ import qualified Cardano.Ledger.Core as L import qualified Cardano.Ledger.SafeHash as L import qualified Cardano.Ledger.Shelley.TxCert as L import qualified Cardano.Ledger.UTxO as L -import Data.Aeson -import Data.Typeable (Typeable) import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus +import Data.Aeson +import Data.Typeable (Typeable) + data ShelleyToAllegraEra era where ShelleyToAllegraEraShelley :: ShelleyToAllegraEra ShelleyEra ShelleyToAllegraEraAllegra :: ShelleyToAllegraEra AllegraEra diff --git a/cardano-api/internal/Cardano/Api/Eon/ShelleyToAlonzoEra.hs b/cardano-api/internal/Cardano/Api/Eon/ShelleyToAlonzoEra.hs index 8f14eb5f86..c428d2a6f3 100644 --- a/cardano-api/internal/Cardano/Api/Eon/ShelleyToAlonzoEra.hs +++ b/cardano-api/internal/Cardano/Api/Eon/ShelleyToAlonzoEra.hs @@ -16,11 +16,12 @@ module Cardano.Api.Eon.ShelleyToAlonzoEra ) where -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Core -import Cardano.Api.Modes -import Cardano.Api.Query.Types -import Cardano.Binary +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Core +import Cardano.Api.Modes +import Cardano.Api.Query.Types + +import Cardano.Binary import qualified Cardano.Crypto.Hash.Blake2b as Blake2b import qualified Cardano.Crypto.Hash.Class as C import qualified Cardano.Crypto.VRF as C @@ -29,12 +30,13 @@ import qualified Cardano.Ledger.BaseTypes as L import qualified Cardano.Ledger.Core as L import qualified Cardano.Ledger.SafeHash as L import qualified Cardano.Ledger.Shelley.TxCert as L -import Data.Aeson -import Data.Typeable (Typeable) import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus +import Data.Aeson +import Data.Typeable (Typeable) + data ShelleyToAlonzoEra era where ShelleyToAlonzoEraShelley :: ShelleyToAlonzoEra ShelleyEra ShelleyToAlonzoEraAllegra :: ShelleyToAlonzoEra AllegraEra diff --git a/cardano-api/internal/Cardano/Api/Eon/ShelleyToBabbageEra.hs b/cardano-api/internal/Cardano/Api/Eon/ShelleyToBabbageEra.hs index aa4f6ca99a..b2deca73bc 100644 --- a/cardano-api/internal/Cardano/Api/Eon/ShelleyToBabbageEra.hs +++ b/cardano-api/internal/Cardano/Api/Eon/ShelleyToBabbageEra.hs @@ -16,11 +16,12 @@ module Cardano.Api.Eon.ShelleyToBabbageEra ) where -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Core -import Cardano.Api.Modes -import Cardano.Api.Query.Types -import Cardano.Binary +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Core +import Cardano.Api.Modes +import Cardano.Api.Query.Types + +import Cardano.Binary import qualified Cardano.Crypto.Hash.Blake2b as Blake2b import qualified Cardano.Crypto.Hash.Class as C import qualified Cardano.Crypto.VRF as C @@ -29,12 +30,13 @@ import qualified Cardano.Ledger.BaseTypes as L import qualified Cardano.Ledger.Core as L import qualified Cardano.Ledger.SafeHash as L import qualified Cardano.Ledger.Shelley.TxCert as L -import Data.Aeson -import Data.Typeable (Typeable) import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus +import Data.Aeson +import Data.Typeable (Typeable) + data ShelleyToBabbageEra era where ShelleyToBabbageEraShelley :: ShelleyToBabbageEra ShelleyEra ShelleyToBabbageEraAllegra :: ShelleyToBabbageEra AllegraEra diff --git a/cardano-api/internal/Cardano/Api/Eon/ShelleyToMaryEra.hs b/cardano-api/internal/Cardano/Api/Eon/ShelleyToMaryEra.hs index 06ab79e707..9c3f064562 100644 --- a/cardano-api/internal/Cardano/Api/Eon/ShelleyToMaryEra.hs +++ b/cardano-api/internal/Cardano/Api/Eon/ShelleyToMaryEra.hs @@ -16,11 +16,12 @@ module Cardano.Api.Eon.ShelleyToMaryEra ) where -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Core -import Cardano.Api.Modes -import Cardano.Api.Query.Types -import Cardano.Binary +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Core +import Cardano.Api.Modes +import Cardano.Api.Query.Types + +import Cardano.Binary import qualified Cardano.Crypto.Hash.Blake2b as Blake2b import qualified Cardano.Crypto.Hash.Class as C import qualified Cardano.Crypto.VRF as C @@ -29,12 +30,13 @@ import qualified Cardano.Ledger.BaseTypes as L import qualified Cardano.Ledger.Core as L import qualified Cardano.Ledger.SafeHash as L import qualified Cardano.Ledger.Shelley.TxCert as L -import Data.Aeson -import Data.Typeable (Typeable) import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus +import Data.Aeson +import Data.Typeable (Typeable) + data ShelleyToMaryEra era where ShelleyToMaryEraShelley :: ShelleyToMaryEra ShelleyEra ShelleyToMaryEraAllegra :: ShelleyToMaryEra AllegraEra diff --git a/cardano-api/internal/Cardano/Api/Eras.hs b/cardano-api/internal/Cardano/Api/Eras.hs index 4889a904ca..b54554bb9c 100644 --- a/cardano-api/internal/Cardano/Api/Eras.hs +++ b/cardano-api/internal/Cardano/Api/Eras.hs @@ -48,5 +48,5 @@ module Cardano.Api.Eras ) where -import Cardano.Api.Eras.Case -import Cardano.Api.Eras.Core +import Cardano.Api.Eras.Case +import Cardano.Api.Eras.Core diff --git a/cardano-api/internal/Cardano/Api/Eras/Case.hs b/cardano-api/internal/Cardano/Api/Eras/Case.hs index 7c205cbdbf..e081fccef2 100644 --- a/cardano-api/internal/Cardano/Api/Eras/Case.hs +++ b/cardano-api/internal/Cardano/Api/Eras/Case.hs @@ -21,19 +21,19 @@ module Cardano.Api.Eras.Case ) where -import Cardano.Api.Eon.AllegraEraOnwards -import Cardano.Api.Eon.AlonzoEraOnwards -import Cardano.Api.Eon.BabbageEraOnwards -import Cardano.Api.Eon.ByronToAlonzoEra -import Cardano.Api.Eon.ConwayEraOnwards -import Cardano.Api.Eon.MaryEraOnwards -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eon.ShelleyEraOnly -import Cardano.Api.Eon.ShelleyToAllegraEra -import Cardano.Api.Eon.ShelleyToAlonzoEra -import Cardano.Api.Eon.ShelleyToBabbageEra -import Cardano.Api.Eon.ShelleyToMaryEra -import Cardano.Api.Eras.Core +import Cardano.Api.Eon.AllegraEraOnwards +import Cardano.Api.Eon.AlonzoEraOnwards +import Cardano.Api.Eon.BabbageEraOnwards +import Cardano.Api.Eon.ByronToAlonzoEra +import Cardano.Api.Eon.ConwayEraOnwards +import Cardano.Api.Eon.MaryEraOnwards +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eon.ShelleyEraOnly +import Cardano.Api.Eon.ShelleyToAllegraEra +import Cardano.Api.Eon.ShelleyToAlonzoEra +import Cardano.Api.Eon.ShelleyToBabbageEra +import Cardano.Api.Eon.ShelleyToMaryEra +import Cardano.Api.Eras.Core -- | @caseByronOrShelleyBasedEra f g era@ returns @f@ in Byron and applies @g@ to Shelley-based eras. caseByronOrShelleyBasedEra diff --git a/cardano-api/internal/Cardano/Api/Eras/Core.hs b/cardano-api/internal/Cardano/Api/Eras/Core.hs index 9c21545a3d..3167b67854 100644 --- a/cardano-api/internal/Cardano/Api/Eras/Core.hs +++ b/cardano-api/internal/Cardano/Api/Eras/Core.hs @@ -48,16 +48,18 @@ module Cardano.Api.Eras.Core ) where -import Cardano.Api.HasTypeProxy -import Cardano.Api.Pretty +import Cardano.Api.HasTypeProxy +import Cardano.Api.Pretty + import qualified Cardano.Ledger.Api as L -import Data.Aeson (FromJSON (..), ToJSON, toJSON, withText) -import Data.Kind -import Data.Maybe (isJust) -import Data.String (IsString) + +import Data.Aeson (FromJSON (..), ToJSON, toJSON, withText) +import Data.Kind +import Data.Maybe (isJust) +import Data.String (IsString) import qualified Data.Text as Text -import Data.Type.Equality (TestEquality (..), (:~:) (Refl)) -import Data.Typeable (Typeable, showsTypeRep, typeOf) +import Data.Type.Equality (TestEquality (..), (:~:) (Refl)) +import Data.Typeable (Typeable, showsTypeRep, typeOf) -- ---------------------------------------------------------------------------- -- Eras diff --git a/cardano-api/internal/Cardano/Api/Error.hs b/cardano-api/internal/Cardano/Api/Error.hs index c1aa28c110..a88c161e8d 100644 --- a/cardano-api/internal/Cardano/Api/Error.hs +++ b/cardano-api/internal/Cardano/Api/Error.hs @@ -15,14 +15,15 @@ module Cardano.Api.Error ) where -import Cardano.Api.Pretty -import Control.Exception (Exception (..), IOException, throwIO) -import Control.Monad.Except (throwError) -import Control.Monad.IO.Class (MonadIO) -import Control.Monad.Trans.Except (ExceptT) -import Control.Monad.Trans.Except.Extra (handleIOExceptT) -import System.Directory (doesFileExist) -import System.IO (Handle) +import Cardano.Api.Pretty + +import Control.Exception (Exception (..), IOException, throwIO) +import Control.Monad.Except (throwError) +import Control.Monad.IO.Class (MonadIO) +import Control.Monad.Trans.Except (ExceptT) +import Control.Monad.Trans.Except.Extra (handleIOExceptT) +import System.Directory (doesFileExist) +import System.IO (Handle) class Error e where prettyError :: e -> Doc ann diff --git a/cardano-api/internal/Cardano/Api/Feature.hs b/cardano-api/internal/Cardano/Api/Feature.hs index 74e193e073..c40265a92e 100644 --- a/cardano-api/internal/Cardano/Api/Feature.hs +++ b/cardano-api/internal/Cardano/Api/Feature.hs @@ -12,8 +12,8 @@ module Cardano.Api.Feature ) where -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Core +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Core -- | A value only if the eon includes era data Featured eon era a where diff --git a/cardano-api/internal/Cardano/Api/Fees.hs b/cardano-api/internal/Cardano/Api/Fees.hs index a3f687dc3c..6d457602c2 100644 --- a/cardano-api/internal/Cardano/Api/Fees.hs +++ b/cardano-api/internal/Cardano/Api/Fees.hs @@ -48,24 +48,25 @@ module Cardano.Api.Fees ) where -import Cardano.Api.Address -import Cardano.Api.Certificate -import Cardano.Api.Eon.AlonzoEraOnwards -import Cardano.Api.Eon.BabbageEraOnwards -import Cardano.Api.Eon.MaryEraOnwards -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Case -import Cardano.Api.Eras.Core -import Cardano.Api.Error -import Cardano.Api.Feature +import Cardano.Api.Address +import Cardano.Api.Certificate +import Cardano.Api.Eon.AlonzoEraOnwards +import Cardano.Api.Eon.BabbageEraOnwards +import Cardano.Api.Eon.MaryEraOnwards +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Case +import Cardano.Api.Eras.Core +import Cardano.Api.Error +import Cardano.Api.Feature import qualified Cardano.Api.Ledger.Lens as A -import Cardano.Api.Pretty -import Cardano.Api.ProtocolParameters -import Cardano.Api.Query -import Cardano.Api.Script -import Cardano.Api.Tx.Body -import Cardano.Api.Tx.Sign -import Cardano.Api.Value +import Cardano.Api.Pretty +import Cardano.Api.ProtocolParameters +import Cardano.Api.Query +import Cardano.Api.Script +import Cardano.Api.Tx.Body +import Cardano.Api.Tx.Sign +import Cardano.Api.Value + import qualified Cardano.Ledger.Alonzo.Core as Ledger import qualified Cardano.Ledger.Alonzo.Plutus.Context as Plutus import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo @@ -73,28 +74,29 @@ import qualified Cardano.Ledger.Api as L import qualified Cardano.Ledger.Coin as L import qualified Cardano.Ledger.Conway.Governance as L import qualified Cardano.Ledger.Core as L -import Cardano.Ledger.Credential as Ledger (Credential) +import Cardano.Ledger.Credential as Ledger (Credential) import qualified Cardano.Ledger.Crypto as Ledger import qualified Cardano.Ledger.Keys as Ledger import qualified Cardano.Ledger.Plutus.Language as Plutus -import Control.Monad (forM_) -import Data.Bifunctor (bimap, first, second) -import Data.ByteString.Short (ShortByteString) -import Data.Foldable (toList) -import Data.Function ((&)) +import qualified Ouroboros.Consensus.HardFork.History as Consensus +import qualified PlutusLedgerApi.V1 as Plutus + +import Control.Monad (forM_) +import Data.Bifunctor (bimap, first, second) +import Data.ByteString.Short (ShortByteString) +import Data.Foldable (toList) +import Data.Function ((&)) import qualified Data.List as List -import Data.Map.Strict (Map) +import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map -import Data.Maybe (catMaybes, fromMaybe, maybeToList) +import Data.Maybe (catMaybes, fromMaybe, maybeToList) import qualified Data.OSet.Strict as OSet -import Data.Ratio -import Data.Set (Set) +import Data.Ratio +import Data.Set (Set) import qualified Data.Set as Set -import Data.Text (Text) +import Data.Text (Text) import qualified Data.Text as Text -import Lens.Micro ((.~), (^.)) -import qualified Ouroboros.Consensus.HardFork.History as Consensus -import qualified PlutusLedgerApi.V1 as Plutus +import Lens.Micro ((.~), (^.)) {- HLINT ignore "Redundant return" -} @@ -105,7 +107,7 @@ type EvalTxExecutionUnitsLog = [Text] data AutoBalanceError era = AutoBalanceEstimationError (TxFeeEstimationError era) | AutoBalanceCalculationError (TxBodyErrorAutoBalance era) - deriving (Show) + deriving Show instance Error (AutoBalanceError era) where prettyError = \case @@ -173,7 +175,7 @@ data TxFeeEstimationError era | TxFeeEstimationxBodyError TxBodyError | TxFeeEstimationFinalConstructionError TxBodyError | TxFeeEstimationOnlyMaryOnwardsSupportedError - deriving (Show) + deriving Show instance Error (TxFeeEstimationError era) where prettyError = \case @@ -460,7 +462,7 @@ estimateTransactionKeyWitnessCount , txUpdateProposal } = fromIntegral $ - length [() | (_txin, BuildTxWith KeyWitness {}) <- txIns] + length [() | (_txin, BuildTxWith KeyWitness{}) <- txIns] + case txInsCollateral of TxInsCollateral _ txins -> length txins @@ -471,11 +473,11 @@ estimateTransactionKeyWitnessCount _ -> 0 + case txWithdrawals of TxWithdrawals _ withdrawals -> - length [() | (_, _, BuildTxWith KeyWitness {}) <- withdrawals] + length [() | (_, _, BuildTxWith KeyWitness{}) <- withdrawals] _ -> 0 + case txCertificates of TxCertificates _ _ (BuildTxWith witnesses) -> - length [() | KeyWitness {} <- Map.elems witnesses] + length [() | KeyWitness{} <- Map.elems witnesses] _ -> 0 + case txUpdateProposal of TxUpdateProposal _ (UpdateProposal updatePerGenesisKey _) -> @@ -646,7 +648,7 @@ instance Error (TransactionValidityError era) where ] where timeHorizonSlots :: Consensus.PastHorizonException -> Word - timeHorizonSlots Consensus.PastHorizon {Consensus.pastHorizonSummary} + timeHorizonSlots Consensus.PastHorizon{Consensus.pastHorizonSummary} | eraSummaries@(_ : _) <- pastHorizonSummary , Consensus.StandardSafeZone slots <- (Consensus.eraSafeZone . Consensus.eraParams . last) eraSummaries = @@ -863,7 +865,7 @@ data TxBodyErrorAutoBalance era | TxBodyErrorScriptWitnessIndexMissingFromExecUnitsMap ScriptWitnessIndex (Map ScriptWitnessIndex ExecutionUnits) - deriving (Show) + deriving Show instance Error (TxBodyErrorAutoBalance era) where prettyError = \case @@ -942,19 +944,19 @@ data BalancedTxBody era -- ^ Transaction balance (change output) L.Coin -- ^ Estimated transaction fee - deriving (Show) + deriving Show newtype RequiredShelleyKeyWitnesses = RequiredShelleyKeyWitnesses {unRequiredShelleyKeyWitnesses :: Int} - deriving (Show) + deriving Show newtype RequiredByronKeyWitnesses = RequiredByronKeyWitnesses {unRequiredByronKeyWitnesses :: Int} - deriving (Show) + deriving Show newtype TotalReferenceScriptsSize = TotalReferenceScriptsSize {unTotalReferenceScriptsSize :: Int} - deriving (Show) + deriving Show data FeeEstimationMode era = -- | Accurate fee calculation. @@ -1274,8 +1276,8 @@ calcReturnAndTotalCollateral -- ^ Total available collateral in lovelace -> (TxReturnCollateral CtxTx era, TxTotalCollateral era) calcReturnAndTotalCollateral _ _ _ TxInsCollateralNone _ _ _ _ = (TxReturnCollateralNone, TxTotalCollateralNone) -calcReturnAndTotalCollateral _ _ _ _ rc@TxReturnCollateral {} tc@TxTotalCollateral {} _ _ = (rc, tc) -calcReturnAndTotalCollateral retColSup fee pp' TxInsCollateral {} txReturnCollateral txTotalCollateral cAddr totalAvailableAda = +calcReturnAndTotalCollateral _ _ _ _ rc@TxReturnCollateral{} tc@TxTotalCollateral{} _ _ = (rc, tc) +calcReturnAndTotalCollateral retColSup fee pp' TxInsCollateral{} txReturnCollateral txTotalCollateral cAddr totalAvailableAda = do let colPerc = pp' ^. Ledger.ppCollateralPercentageL -- We must first figure out how much lovelace we have committed @@ -1297,12 +1299,12 @@ calcReturnAndTotalCollateral retColSup fee pp' TxInsCollateral {} txReturnCollat #if MIN_VERSION_base(4,16,0) #else -- For ghc-9.2, this pattern match is redundant, but ghc-8.10 will complain if its missing. - (rc@TxReturnCollateral {}, tc@TxTotalCollateral {}) -> + (rc@TxReturnCollateral{}, tc@TxTotalCollateral{}) -> (rc, tc) #endif - (rc@TxReturnCollateral {}, TxTotalCollateralNone) -> + (rc@TxReturnCollateral{}, TxTotalCollateralNone) -> (rc, TxTotalCollateralNone) - (TxReturnCollateralNone, tc@TxTotalCollateral {}) -> + (TxReturnCollateralNone, tc@TxTotalCollateral{}) -> (TxReturnCollateralNone, tc) (TxReturnCollateralNone, TxTotalCollateralNone) -> if totalCollateralLovelace * 100 >= requiredCollateral @@ -1367,10 +1369,10 @@ maybeDummyTotalCollAndCollReturnOutput -> TxBodyContent BuildTx era -> AddressInEra era -> (TxReturnCollateral CtxTx era, TxTotalCollateral era) -maybeDummyTotalCollAndCollReturnOutput sbe TxBodyContent {txInsCollateral, txReturnCollateral, txTotalCollateral} cAddr = +maybeDummyTotalCollAndCollReturnOutput sbe TxBodyContent{txInsCollateral, txReturnCollateral, txTotalCollateral} cAddr = case txInsCollateral of TxInsCollateralNone -> (TxReturnCollateralNone, TxTotalCollateralNone) - TxInsCollateral {} -> + TxInsCollateral{} -> forShelleyBasedEraInEon sbe (TxReturnCollateralNone, TxTotalCollateralNone) @@ -1386,9 +1388,9 @@ maybeDummyTotalCollAndCollReturnOutput sbe TxBodyContent {txInsCollateral, txRet ) dummyTotCol = TxTotalCollateral w (L.Coin (2 ^ (32 :: Integer) - 1)) in case (txReturnCollateral, txTotalCollateral) of - (rc@TxReturnCollateral {}, tc@TxTotalCollateral {}) -> (rc, tc) - (rc@TxReturnCollateral {}, TxTotalCollateralNone) -> (rc, dummyTotCol) - (TxReturnCollateralNone, tc@TxTotalCollateral {}) -> (dummyRetCol, tc) + (rc@TxReturnCollateral{}, tc@TxTotalCollateral{}) -> (rc, tc) + (rc@TxReturnCollateral{}, TxTotalCollateralNone) -> (rc, dummyTotCol) + (TxReturnCollateralNone, tc@TxTotalCollateral{}) -> (dummyRetCol, tc) (TxReturnCollateralNone, TxTotalCollateralNone) -> (dummyRetCol, dummyTotCol) ) @@ -1403,7 +1405,7 @@ substituteExecutionUnits exUnitsMap = :: ScriptWitnessIndex -> ScriptWitness witctx era -> Either (TxBodyErrorAutoBalance era) (ScriptWitness witctx era) - f _ wit@SimpleScriptWitness {} = Right wit + f _ wit@SimpleScriptWitness{} = Right wit f idx (PlutusScriptWitness langInEra version script datum redeemer _) = case Map.lookup idx exUnitsMap of Nothing -> @@ -1461,7 +1463,7 @@ mapTxScriptWitnesses | -- The tx ins are indexed in the map order by txid (ix, (txin, BuildTxWith wit)) <- zip [0 ..] (orderTxIns txins) , let wit' = case wit of - KeyWitness {} -> Right wit + KeyWitness{} -> Right wit ScriptWitness ctx witness -> ScriptWitness ctx <$> witness' where witness' = f (ScriptWitnessIndexTxIn ix) witness diff --git a/cardano-api/internal/Cardano/Api/Genesis.hs b/cardano-api/internal/Cardano/Api/Genesis.hs index 598cf426fb..ec43b049b3 100644 --- a/cardano-api/internal/Cardano/Api/Genesis.hs +++ b/cardano-api/internal/Cardano/Api/Genesis.hs @@ -26,47 +26,44 @@ module Cardano.Api.Genesis ) where -import Cardano.Api.IO -import Cardano.Api.Utils (unsafeBoundedRational) +import Cardano.Api.IO +import Cardano.Api.Utils (unsafeBoundedRational) + import qualified Cardano.Chain.Genesis import qualified Cardano.Crypto.Hash.Blake2b import qualified Cardano.Crypto.Hash.Class -import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis (..)) -import Cardano.Ledger.Alonzo.Scripts (ExUnits (..), Prices (..)) -import Cardano.Ledger.Api (CoinPerWord (..)) -import Cardano.Ledger.BaseTypes as Ledger -import Cardano.Ledger.Coin (Coin (..)) -import Cardano.Ledger.Conway.Genesis (ConwayGenesis (..)) -import Cardano.Ledger.Conway.PParams - ( DRepVotingThresholds (..) - , PoolVotingThresholds (..) - , UpgradeConwayPParams (..) - ) -import Cardano.Ledger.Crypto (StandardCrypto) -import Cardano.Ledger.Plutus (Language (..)) -import Cardano.Ledger.Plutus.CostModels (mkCostModelsLenient) -import Cardano.Ledger.Shelley.Core -import Cardano.Ledger.Shelley.Genesis - ( NominalDiffTimeMicro - , ShelleyGenesis (..) - , emptyGenesisStaking - ) +import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis (..)) +import Cardano.Ledger.Alonzo.Scripts (ExUnits (..), Prices (..)) +import Cardano.Ledger.Api (CoinPerWord (..)) +import Cardano.Ledger.BaseTypes as Ledger +import Cardano.Ledger.Coin (Coin (..)) +import Cardano.Ledger.Conway.Genesis (ConwayGenesis (..)) +import Cardano.Ledger.Conway.PParams (DRepVotingThresholds (..), + PoolVotingThresholds (..), UpgradeConwayPParams (..)) +import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Plutus (Language (..)) +import Cardano.Ledger.Plutus.CostModels (mkCostModelsLenient) +import Cardano.Ledger.Shelley.Core +import Cardano.Ledger.Shelley.Genesis (NominalDiffTimeMicro, ShelleyGenesis (..), + emptyGenesisStaking) import qualified Cardano.Ledger.Shelley.Genesis as Ledger -import Control.Monad.Trans.Fail.String (errorFail) -import Data.ByteString (ByteString) +import qualified Ouroboros.Consensus.Shelley.Eras as Shelley + +import Control.Monad.Trans.Fail.String (errorFail) +import Data.ByteString (ByteString) import qualified Data.Default.Class as DefaultClass -import Data.Functor.Identity (Identity) +import Data.Functor.Identity (Identity) import qualified Data.ListMap as ListMap import qualified Data.Map.Strict as Map -import Data.Ratio -import Data.Text (Text) +import Data.Ratio +import Data.Text (Text) import qualified Data.Time as Time -import Data.Typeable -import GHC.Stack (HasCallStack) -import Lens.Micro -import qualified Ouroboros.Consensus.Shelley.Eras as Shelley -import Test.Cardano.Ledger.Core.Rational ((%!)) -import Test.Cardano.Ledger.Plutus (testingCostModelV3) +import Data.Typeable +import GHC.Stack (HasCallStack) +import Lens.Micro + +import Test.Cardano.Ledger.Core.Rational ((%!)) +import Test.Cardano.Ledger.Plutus (testingCostModelV3) data ShelleyConfig = ShelleyConfig { scConfig :: !(Ledger.ShelleyGenesis Shelley.StandardCrypto) diff --git a/cardano-api/internal/Cardano/Api/GenesisParameters.hs b/cardano-api/internal/Cardano/Api/GenesisParameters.hs index 1eb37477f3..ac92f585e8 100644 --- a/cardano-api/internal/Cardano/Api/GenesisParameters.hs +++ b/cardano-api/internal/Cardano/Api/GenesisParameters.hs @@ -14,14 +14,16 @@ module Cardano.Api.GenesisParameters ) where -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras -import Cardano.Api.NetworkId +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras +import Cardano.Api.NetworkId import qualified Cardano.Api.ReexposeLedger as Ledger + import qualified Cardano.Ledger.Coin as L import qualified Cardano.Ledger.Shelley.Genesis as Shelley -import Cardano.Slotting.Slot (EpochSize (..)) -import Data.Time (NominalDiffTime, UTCTime) +import Cardano.Slotting.Slot (EpochSize (..)) + +import Data.Time (NominalDiffTime, UTCTime) -- ---------------------------------------------------------------------------- -- Genesis parameters diff --git a/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs b/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs index d367154e62..6f4b202ae0 100644 --- a/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs +++ b/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs @@ -12,32 +12,34 @@ module Cardano.Api.Governance.Actions.ProposalProcedure where -import Cardano.Api.Address -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.HasTypeProxy -import Cardano.Api.Keys.Shelley -import Cardano.Api.ProtocolParameters +import Cardano.Api.Address +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.HasTypeProxy +import Cardano.Api.Keys.Shelley +import Cardano.Api.ProtocolParameters import qualified Cardano.Api.ReexposeLedger as Ledger -import Cardano.Api.SerialiseCBOR -import Cardano.Api.SerialiseTextEnvelope -import Cardano.Api.TxIn +import Cardano.Api.SerialiseCBOR +import Cardano.Api.SerialiseTextEnvelope +import Cardano.Api.TxIn + import qualified Cardano.Binary as CBOR import qualified Cardano.Ledger.Address as L -import Cardano.Ledger.BaseTypes +import Cardano.Ledger.BaseTypes import qualified Cardano.Ledger.Coin as L import qualified Cardano.Ledger.Conway as Conway import qualified Cardano.Ledger.Conway.Governance as Gov import qualified Cardano.Ledger.Conway.Governance as Ledger -import Cardano.Ledger.Core (EraCrypto) +import Cardano.Ledger.Core (EraCrypto) import qualified Cardano.Ledger.Core as Shelley import qualified Cardano.Ledger.Credential as L -import Cardano.Ledger.Crypto (StandardCrypto) -import Cardano.Ledger.Keys (KeyRole (ColdCommitteeRole)) -import Data.ByteString (ByteString) -import Data.Map.Strict (Map) -import Data.Maybe (fromMaybe) -import Data.Word -import GHC.Exts (IsList (..)) +import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Keys (KeyRole (ColdCommitteeRole)) + +import Data.ByteString (ByteString) +import Data.Map.Strict (Map) +import Data.Maybe (fromMaybe) +import Data.Word +import GHC.Exts (IsList (..)) data AnyGovernanceAction = forall era. AnyGovernanceAction (Gov.GovAction era) diff --git a/cardano-api/internal/Cardano/Api/Governance/Actions/VotingProcedure.hs b/cardano-api/internal/Cardano/Api/Governance/Actions/VotingProcedure.hs index c8bc00ae93..dba360230a 100644 --- a/cardano-api/internal/Cardano/Api/Governance/Actions/VotingProcedure.hs +++ b/cardano-api/internal/Cardano/Api/Governance/Actions/VotingProcedure.hs @@ -16,24 +16,26 @@ module Cardano.Api.Governance.Actions.VotingProcedure where -import Cardano.Api.Address -import Cardano.Api.Eon.ConwayEraOnwards -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Governance.Actions.ProposalProcedure -import Cardano.Api.HasTypeProxy +import Cardano.Api.Address +import Cardano.Api.Eon.ConwayEraOnwards +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Governance.Actions.ProposalProcedure +import Cardano.Api.HasTypeProxy import qualified Cardano.Api.ReexposeLedger as Ledger -import Cardano.Api.SerialiseCBOR -import Cardano.Api.SerialiseTextEnvelope +import Cardano.Api.SerialiseCBOR +import Cardano.Api.SerialiseTextEnvelope + import qualified Cardano.Binary as CBOR import qualified Cardano.Ledger.Api as L -import Cardano.Ledger.Core (EraCrypto) +import Cardano.Ledger.Core (EraCrypto) import qualified Cardano.Ledger.Core as L -import Control.Monad (foldM) + +import Control.Monad (foldM) import qualified Data.Map as Map import qualified Data.Set as Set -import Data.Text (Text) +import Data.Text (Text) import qualified Data.Text.Encoding as Text -import GHC.Generics +import GHC.Generics newtype GovernanceActionId era = GovernanceActionId { unGovernanceActionId :: Ledger.GovActionId (EraCrypto (ShelleyLedgerEra era)) diff --git a/cardano-api/internal/Cardano/Api/Governance/Poll.hs b/cardano-api/internal/Cardano/Api/Governance/Poll.hs index c49a554b4a..b46ca46ba2 100644 --- a/cardano-api/internal/Cardano/Api/Governance/Poll.hs +++ b/cardano-api/internal/Cardano/Api/Governance/Poll.hs @@ -37,35 +37,37 @@ module Cardano.Api.Governance.Poll ) 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.SerialiseCBOR -import Cardano.Api.SerialiseRaw -import Cardano.Api.SerialiseTextEnvelope -import Cardano.Api.SerialiseUsing -import Cardano.Api.Tx.Body -import Cardano.Api.Tx.Sign -import Cardano.Api.TxMetadata -import Cardano.Api.Utils -import Cardano.Binary (DecoderError (..)) -import Cardano.Crypto.Hash (hashFromBytes, hashToBytes, hashWith) +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.SerialiseCBOR +import Cardano.Api.SerialiseRaw +import Cardano.Api.SerialiseTextEnvelope +import Cardano.Api.SerialiseUsing +import Cardano.Api.Tx.Body +import Cardano.Api.Tx.Sign +import Cardano.Api.TxMetadata +import Cardano.Api.Utils + +import Cardano.Binary (DecoderError (..)) +import Cardano.Crypto.Hash (hashFromBytes, hashToBytes, hashWith) import qualified Cardano.Crypto.Hash as Hash -import Cardano.Ledger.Crypto (HASH, StandardCrypto) -import Control.Arrow (left) -import Control.Monad (foldM, when) -import Data.Either.Combinators (maybeToRight) -import Data.Function ((&)) +import Cardano.Ledger.Crypto (HASH, StandardCrypto) + +import Control.Arrow (left) +import Control.Monad (foldM, when) +import Data.Either.Combinators (maybeToRight) +import Data.Function ((&)) import qualified Data.Map.Strict as Map -import Data.String (IsString (..)) -import Data.Text (Text) +import Data.String (IsString (..)) +import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Lazy as Text.Lazy import qualified Data.Text.Lazy.Builder as Text.Builder -import Data.Word (Word64) -import Formatting (build, sformat) +import Data.Word (Word64) +import Formatting (build, sformat) -- | Associated metadata label as defined in CIP-0094 pollMetadataLabel :: Word64 @@ -120,7 +122,7 @@ instance HasTypeProxy GovernancePoll where proxyToAsType _ = AsGovernancePoll instance AsTxMetadata GovernancePoll where - asTxMetadata GovernancePoll {govPollQuestion, govPollAnswers, govPollNonce} = + asTxMetadata GovernancePoll{govPollQuestion, govPollAnswers, govPollNonce} = makeTransactionMetadata $ Map.fromList [ @@ -216,7 +218,7 @@ instance HasTypeProxy GovernancePollAnswer where proxyToAsType _ = AsGovernancePollAnswer instance AsTxMetadata GovernancePollAnswer where - asTxMetadata GovernancePollAnswer {govAnsPoll, govAnsChoice} = + asTxMetadata GovernancePollAnswer{govAnsPoll, govAnsChoice} = makeTransactionMetadata $ Map.fromList [ @@ -276,19 +278,19 @@ data GovernancePollError | ErrGovernancePollUnauthenticated | ErrGovernancePollMalformedAnswer DecoderError | ErrGovernancePollInvalidAnswer GovernancePollInvalidAnswerError - deriving (Show) + deriving Show data GovernancePollInvalidAnswerError = GovernancePollInvalidAnswerError { invalidAnswerAcceptableAnswers :: [(Word, Text)] , invalidAnswerReceivedAnswer :: Word } - deriving (Show) + deriving Show data GovernancePollMismatchError = GovernancePollMismatchError { specifiedHashInAnswer :: Hash GovernancePoll , calculatedHashFromPoll :: Hash GovernancePoll } - deriving (Show) + deriving Show renderGovernancePollError :: GovernancePollError -> Text renderGovernancePollError err = diff --git a/cardano-api/internal/Cardano/Api/HasTypeProxy.hs b/cardano-api/internal/Cardano/Api/HasTypeProxy.hs index f15a3e07df..65f29242d3 100644 --- a/cardano-api/internal/Cardano/Api/HasTypeProxy.hs +++ b/cardano-api/internal/Cardano/Api/HasTypeProxy.hs @@ -9,9 +9,9 @@ module Cardano.Api.HasTypeProxy ) where -import Data.Kind (Constraint, Type) -import Data.Proxy (Proxy (..)) -import Data.Typeable (Typeable) +import Data.Kind (Constraint, Type) +import Data.Proxy (Proxy (..)) +import Data.Typeable (Typeable) class Typeable t => HasTypeProxy t where -- | A family of singleton types used in this API to indicate which type to diff --git a/cardano-api/internal/Cardano/Api/Hash.hs b/cardano-api/internal/Cardano/Api/Hash.hs index 4e84aca4fa..02a412b8c2 100644 --- a/cardano-api/internal/Cardano/Api/Hash.hs +++ b/cardano-api/internal/Cardano/Api/Hash.hs @@ -9,10 +9,12 @@ module Cardano.Api.Hash ) where -import Cardano.Api.HasTypeProxy +import Cardano.Api.HasTypeProxy + import qualified Cardano.Crypto.Hash as Hash import qualified Cardano.Ledger.SafeHash as Ledger -import Data.Kind (Type) + +import Data.Kind (Type) import qualified Data.Text as Text data family Hash keyrole :: Type diff --git a/cardano-api/internal/Cardano/Api/IO.hs b/cardano-api/internal/Cardano/Api/IO.hs index 4b26d37750..88e38c0fb0 100644 --- a/cardano-api/internal/Cardano/Api/IO.hs +++ b/cardano-api/internal/Cardano/Api/IO.hs @@ -28,18 +28,19 @@ module Cardano.Api.IO ) where -import Cardano.Api.Error (FileError (..), fileIOExceptT) -import Cardano.Api.IO.Base -import Cardano.Api.IO.Compat -import Control.Monad.Except (runExceptT) -import Control.Monad.IO.Class (MonadIO (..)) -import Control.Monad.Trans.Except.Extra (handleIOExceptT) -import Data.ByteString (ByteString) +import Cardano.Api.Error (FileError (..), fileIOExceptT) +import Cardano.Api.IO.Base +import Cardano.Api.IO.Compat + +import Control.Monad.Except (runExceptT) +import Control.Monad.IO.Class (MonadIO (..)) +import Control.Monad.Trans.Except.Extra (handleIOExceptT) +import Data.ByteString (ByteString) import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Char8 as BSC import qualified Data.ByteString.Lazy as LBS import qualified Data.ByteString.Lazy as LBSC -import Data.Text (Text) +import Data.Text (Text) import qualified Data.Text.IO as Text readByteStringFile diff --git a/cardano-api/internal/Cardano/Api/IO/Base.hs b/cardano-api/internal/Cardano/Api/IO/Base.hs index 2a53be3f0d..22d6dc860a 100644 --- a/cardano-api/internal/Cardano/Api/IO/Base.hs +++ b/cardano-api/internal/Cardano/Api/IO/Base.hs @@ -13,8 +13,8 @@ module Cardano.Api.IO.Base ) where -import Data.Aeson (FromJSON, ToJSON) -import Data.String (IsString) +import Data.Aeson (FromJSON, ToJSON) +import Data.String (IsString) data FileDirection = -- | Indicate the file is to be used for reading. @@ -39,4 +39,4 @@ data VRFPrivateKeyFilePermissionError = OtherPermissionsExist FilePath | GroupPermissionsExist FilePath | GenericPermissionsExist FilePath - deriving (Show) + deriving Show diff --git a/cardano-api/internal/Cardano/Api/IO/Compat.hs b/cardano-api/internal/Cardano/Api/IO/Compat.hs index 4e67cb5642..b82126c395 100644 --- a/cardano-api/internal/Cardano/Api/IO/Compat.hs +++ b/cardano-api/internal/Cardano/Api/IO/Compat.hs @@ -8,13 +8,14 @@ module Cardano.Api.IO.Compat ) where -import Cardano.Api.Error -import Cardano.Api.IO.Base -import Cardano.Api.IO.Compat.Posix -import Cardano.Api.IO.Compat.Win32 -import Control.Monad.Except (ExceptT) -import Data.ByteString (ByteString) -import System.IO +import Cardano.Api.Error +import Cardano.Api.IO.Base +import Cardano.Api.IO.Compat.Posix +import Cardano.Api.IO.Compat.Win32 + +import Control.Monad.Except (ExceptT) +import Data.ByteString (ByteString) +import System.IO handleFileForWritingWithOwnerPermission :: FilePath diff --git a/cardano-api/internal/Cardano/Api/IO/Compat/Posix.hs b/cardano-api/internal/Cardano/Api/IO/Compat/Posix.hs index 1806807fff..aafe98b6b5 100644 --- a/cardano-api/internal/Cardano/Api/IO/Compat/Posix.hs +++ b/cardano-api/internal/Cardano/Api/IO/Compat/Posix.hs @@ -18,39 +18,31 @@ where #ifdef UNIX -import Cardano.Api.Error (FileError (..)) -import Cardano.Api.IO.Base -import Control.Exception (IOException, bracket, bracketOnError, try) -import Control.Monad (forM_, when) -import Control.Monad.Except (ExceptT, runExceptT) -import Control.Monad.IO.Class -import Control.Monad.Trans.Except.Extra (handleIOExceptT, left) +import Cardano.Api.Error (FileError (..)) +import Cardano.Api.IO.Base + +import Control.Exception (IOException, bracket, bracketOnError, try) +import Control.Monad (forM_, when) +import Control.Monad.Except (ExceptT, runExceptT) +import Control.Monad.IO.Class +import Control.Monad.Trans.Except.Extra (handleIOExceptT, left) import qualified Data.ByteString as BS -import System.Directory () -import System.FilePath (()) -import System.IO (Handle) +import System.Directory () +import System.FilePath (()) import qualified System.IO as IO -import System.Posix.Files - ( fileMode - , getFileStatus - , groupModes - , intersectFileModes - , nullFileMode - , otherModes - , ownerModes - , ownerReadMode - , setFdOwnerAndGroup - , setFileMode - , stdFileMode - ) -# if MIN_VERSION_unix(2,8,0) -import System.Posix.IO (OpenFileFlags (..), OpenMode (..), closeFd, defaultFileFlags, fdToHandle, openFd) +import System.IO (Handle) +import System.Posix.Files (fileMode, getFileStatus, groupModes, intersectFileModes, + nullFileMode, otherModes, ownerModes, ownerReadMode, setFdOwnerAndGroup, + setFileMode, stdFileMode) +#if MIN_VERSION_unix(2,8,0) +import System.Posix.IO (OpenFileFlags (..), OpenMode (..), closeFd, defaultFileFlags, + fdToHandle, openFd) #else -import System.Posix.IO (OpenMode (..), closeFd, defaultFileFlags, fdToHandle, openFd) +import System.Posix.IO (OpenMode (..), closeFd, defaultFileFlags, fdToHandle, openFd) #endif -import System.Posix.Types (Fd, FileMode) -import System.Posix.User (getRealUserID) -import Text.Printf (printf) +import System.Posix.Types (Fd, FileMode) +import System.Posix.User (getRealUserID) +import Text.Printf (printf) handleFileForWritingWithOwnerPermissionImpl :: FilePath @@ -123,9 +115,9 @@ openFileDescriptor fp openMode = ReadOnly -> defaultFileFlags ReadWrite -> - defaultFileFlags {creat = Just stdFileMode} + defaultFileFlags{creat = Just stdFileMode} WriteOnly -> - defaultFileFlags {creat = Just ownerModes} + defaultFileFlags{creat = Just ownerModes} # else openFileDescriptor fp openMode = diff --git a/cardano-api/internal/Cardano/Api/IO/Compat/Win32.hs b/cardano-api/internal/Cardano/Api/IO/Compat/Win32.hs index b7cef470a7..526cc58f24 100644 --- a/cardano-api/internal/Cardano/Api/IO/Compat/Win32.hs +++ b/cardano-api/internal/Cardano/Api/IO/Compat/Win32.hs @@ -16,23 +16,24 @@ where #ifndef UNIX -import Cardano.Api.Error (FileError (..)) -import Cardano.Api.IO.Base -import Control.Exception (bracketOnError) -import Control.Monad (forM_, when) -import Control.Monad.Except (ExceptT) -import Control.Monad.IO.Class (liftIO) -import Control.Monad.Trans.Except.Extra (left) -import Data.Bits -import Data.ByteString (ByteString) +import Cardano.Api.Error (FileError (..)) +import Cardano.Api.IO.Base + +import Control.Exception (bracketOnError) +import Control.Monad (forM_, when) +import Control.Monad.Except (ExceptT) +import Control.Monad.IO.Class (liftIO) +import Control.Monad.Trans.Except.Extra (left) +import Data.Bits +import Data.ByteString (ByteString) import qualified Data.ByteString as BS -import System.Directory (emptyPermissions, readable, setPermissions) import qualified System.Directory as IO -import System.FilePath (splitFileName, (<.>), ()) -import System.IO (Handle) +import System.Directory (emptyPermissions, readable, setPermissions) +import System.FilePath (splitFileName, (<.>), ()) import qualified System.IO as IO -import System.Win32.File -import Text.Printf (printf) +import System.IO (Handle) +import System.Win32.File +import Text.Printf (printf) handleFileForWritingWithOwnerPermissionImpl :: FilePath @@ -63,7 +64,7 @@ writeSecretsImpl outDir prefix suffix secretOp xs = \(secret, nr) -> do let filename = outDir prefix <> "." <> printf "%03d" nr <> "." <> suffix BS.writeFile filename $ secretOp secret - setPermissions filename (emptyPermissions {readable = True}) + setPermissions filename (emptyPermissions{readable = True}) -- | Make sure the VRF private key file is readable only -- by the current process owner the node is running under. diff --git a/cardano-api/internal/Cardano/Api/IPC.hs b/cardano-api/internal/Cardano/Api/IPC.hs index 862b85e767..4679bb8b91 100644 --- a/cardano-api/internal/Cardano/Api/IPC.hs +++ b/cardano-api/internal/Cardano/Api/IPC.hs @@ -74,37 +74,23 @@ module Cardano.Api.IPC ) where -import Cardano.Api.Block -import Cardano.Api.HasTypeProxy -import Cardano.Api.IO -import Cardano.Api.IPC.Version -import Cardano.Api.InMode -import Cardano.Api.Modes -import Cardano.Api.Monad.Error (ExceptT (..)) -import Cardano.Api.NetworkId -import Cardano.Api.Protocol -import Cardano.Api.Query -import Cardano.Api.Tx.Body -import Cardano.Api.Tx.Sign +import Cardano.Api.Block +import Cardano.Api.HasTypeProxy +import Cardano.Api.InMode +import Cardano.Api.IO +import Cardano.Api.IPC.Version +import Cardano.Api.Modes +import Cardano.Api.Monad.Error (ExceptT (..)) +import Cardano.Api.NetworkId +import Cardano.Api.Protocol +import Cardano.Api.Query +import Cardano.Api.Tx.Body +import Cardano.Api.Tx.Sign + import qualified Cardano.Ledger.Api as L -import Control.Concurrent.STM - ( TMVar - , atomically - , newEmptyTMVarIO - , putTMVar - , takeTMVar - , tryPutTMVar - ) -import Control.Monad (void) -import Control.Monad.IO.Class -import Control.Tracer (nullTracer) -import Data.Aeson (ToJSON, object, toJSON, (.=)) -import qualified Data.ByteString.Lazy as LBS -import qualified Data.Map.Strict as Map -import Data.Void (Void) import qualified Ouroboros.Consensus.Block as Consensus import qualified Ouroboros.Consensus.Cardano.Block as Consensus -import Ouroboros.Consensus.Cardano.CanHardFork +import Ouroboros.Consensus.Cardano.CanHardFork import qualified Ouroboros.Consensus.Ledger.Query as Consensus import qualified Ouroboros.Consensus.Ledger.SupportsMempool as Consensus import qualified Ouroboros.Consensus.Ledger.SupportsProtocol as Consensus @@ -113,33 +99,37 @@ import qualified Ouroboros.Consensus.Node.NetworkProtocolVersion as Consensus import qualified Ouroboros.Consensus.Node.ProtocolInfo as Consensus import qualified Ouroboros.Consensus.Protocol.TPraos as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger.Block as Consensus -import Ouroboros.Consensus.Shelley.Ledger.SupportsProtocol () +import Ouroboros.Consensus.Shelley.Ledger.SupportsProtocol () import qualified Ouroboros.Network.Block as Net import qualified Ouroboros.Network.Mux as Net -import Ouroboros.Network.NodeToClient - ( NodeToClientProtocols (..) - , NodeToClientVersionData (..) - ) +import Ouroboros.Network.NodeToClient (NodeToClientProtocols (..), + NodeToClientVersionData (..)) import qualified Ouroboros.Network.NodeToClient as Net -import Ouroboros.Network.NodeToClient.Version (NodeToClientVersion (..)) -import Ouroboros.Network.Protocol.ChainSync.Client as Net.Sync -import Ouroboros.Network.Protocol.ChainSync.ClientPipelined as Net.SyncP -import Ouroboros.Network.Protocol.LocalStateQuery.Client (LocalStateQueryClient (..)) +import Ouroboros.Network.NodeToClient.Version (NodeToClientVersion (..)) +import Ouroboros.Network.Protocol.ChainSync.Client as Net.Sync +import Ouroboros.Network.Protocol.ChainSync.ClientPipelined as Net.SyncP +import Ouroboros.Network.Protocol.LocalStateQuery.Client (LocalStateQueryClient (..)) import qualified Ouroboros.Network.Protocol.LocalStateQuery.Client as Net.Query -import Ouroboros.Network.Protocol.LocalStateQuery.Type (AcquireFailure (..)) +import Ouroboros.Network.Protocol.LocalStateQuery.Type (AcquireFailure (..)) import qualified Ouroboros.Network.Protocol.LocalStateQuery.Type as Net.Query -import Ouroboros.Network.Protocol.LocalTxMonitor.Client - ( LocalTxMonitorClient (..) - , localTxMonitorClientPeer - ) +import Ouroboros.Network.Protocol.LocalTxMonitor.Client (LocalTxMonitorClient (..), + localTxMonitorClientPeer) import qualified Ouroboros.Network.Protocol.LocalTxMonitor.Client as CTxMon import qualified Ouroboros.Network.Protocol.LocalTxMonitor.Type as Consensus -import Ouroboros.Network.Protocol.LocalTxSubmission.Client - ( LocalTxSubmissionClient (..) - , SubmitResult (..) - ) +import Ouroboros.Network.Protocol.LocalTxSubmission.Client (LocalTxSubmissionClient (..), + SubmitResult (..)) import qualified Ouroboros.Network.Protocol.LocalTxSubmission.Client as Net.Tx +import Control.Concurrent.STM (TMVar, atomically, newEmptyTMVarIO, putTMVar, takeTMVar, + tryPutTMVar) +import Control.Monad (void) +import Control.Monad.IO.Class +import Control.Tracer (nullTracer) +import Data.Aeson (ToJSON, object, toJSON, (.=)) +import qualified Data.ByteString.Lazy as LBS +import qualified Data.Map.Strict as Map +import Data.Void (Void) + -- ---------------------------------------------------------------------------- -- The types for the client side of the node-to-client IPC protocols -- diff --git a/cardano-api/internal/Cardano/Api/IPC/Monad.hs b/cardano-api/internal/Cardano/Api/IPC/Monad.hs index 16925360b3..a115949312 100644 --- a/cardano-api/internal/Cardano/Api/IPC/Monad.hs +++ b/cardano-api/internal/Cardano/Api/IPC/Monad.hs @@ -9,18 +9,20 @@ module Cardano.Api.IPC.Monad ) where -import Cardano.Api.Block -import Cardano.Api.IPC -import Cardano.Api.IPC.Version -import Cardano.Ledger.Shelley.Scripts () -import Control.Concurrent.STM -import Control.Monad -import Control.Monad.IO.Class -import Control.Monad.Reader -import Control.Monad.Trans.Cont +import Cardano.Api.Block +import Cardano.Api.IPC +import Cardano.Api.IPC.Version + +import Cardano.Ledger.Shelley.Scripts () import qualified Ouroboros.Network.Protocol.LocalStateQuery.Client as Net.Query import qualified Ouroboros.Network.Protocol.LocalStateQuery.Type as Net.Query +import Control.Concurrent.STM +import Control.Monad +import Control.Monad.IO.Class +import Control.Monad.Reader +import Control.Monad.Trans.Cont + {- HLINT ignore "Use const" -} {- HLINT ignore "Use let" -} diff --git a/cardano-api/internal/Cardano/Api/IPC/Version.hs b/cardano-api/internal/Cardano/Api/IPC/Version.hs index f2adb0a018..4a68f07ebd 100644 --- a/cardano-api/internal/Cardano/Api/IPC/Version.hs +++ b/cardano-api/internal/Cardano/Api/IPC/Version.hs @@ -7,7 +7,7 @@ module Cardano.Api.IPC.Version ) where -import Ouroboros.Network.NodeToClient.Version (NodeToClientVersion (..)) +import Ouroboros.Network.NodeToClient.Version (NodeToClientVersion (..)) -- | The query 'a' is a versioned query, which means it requires the Node to support a minimum -- Node-to-Client version. diff --git a/cardano-api/internal/Cardano/Api/InMode.hs b/cardano-api/internal/Cardano/Api/InMode.hs index cd6c3276b5..1a7ce916a3 100644 --- a/cardano-api/internal/Cardano/Api/InMode.hs +++ b/cardano-api/internal/Cardano/Api/InMode.hs @@ -27,28 +27,30 @@ module Cardano.Api.InMode ) where -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras -import Cardano.Api.Modes -import Cardano.Api.Orphans () -import Cardano.Api.Tx.Body -import Cardano.Api.Tx.Sign -import Cardano.Api.Utils (textShow) +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras +import Cardano.Api.Modes +import Cardano.Api.Orphans () +import Cardano.Api.Tx.Body +import Cardano.Api.Tx.Sign +import Cardano.Api.Utils (textShow) + import qualified Cardano.Ledger.Api as L -import Data.Aeson (ToJSON (..), (.=)) -import qualified Data.Aeson as Aeson -import Data.SOP.Strict (NS (S, Z)) -import qualified Data.Text as Text -import GHC.Generics import qualified Ouroboros.Consensus.Byron.Ledger as Consensus import qualified Ouroboros.Consensus.Cardano.Block as Consensus import qualified Ouroboros.Consensus.HardFork.Combinator as Consensus -import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (EraMismatch) +import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (EraMismatch) import qualified Ouroboros.Consensus.Ledger.SupportsMempool as Consensus import qualified Ouroboros.Consensus.Shelley.HFEras as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus import qualified Ouroboros.Consensus.TypeFamilyWrappers as Consensus +import Data.Aeson (ToJSON (..), (.=)) +import qualified Data.Aeson as Aeson +import Data.SOP.Strict (NS (S, Z)) +import qualified Data.Text as Text +import GHC.Generics + -- ---------------------------------------------------------------------------- -- Transactions in the context of a consensus mode -- diff --git a/cardano-api/internal/Cardano/Api/Json.hs b/cardano-api/internal/Cardano/Api/Json.hs index dde472de3b..7c08584713 100644 --- a/cardano-api/internal/Cardano/Api/Json.hs +++ b/cardano-api/internal/Cardano/Api/Json.hs @@ -3,8 +3,8 @@ module Cardano.Api.Json ) where -import Data.Aeson -import Data.Scientific +import Data.Aeson +import Data.Scientific -- Rationals and JSON are an awkward mix. We cannot convert rationals -- like @1/3@ to JSON numbers. But _most_ of the numbers we want to use diff --git a/cardano-api/internal/Cardano/Api/Keys/Byron.hs b/cardano-api/internal/Cardano/Api/Keys/Byron.hs index 76bc76cc5b..fa19bfa605 100644 --- a/cardano-api/internal/Cardano/Api/Keys/Byron.hs +++ b/cardano-api/internal/Cardano/Api/Keys/Byron.hs @@ -28,15 +28,16 @@ module Cardano.Api.Keys.Byron ) where -import Cardano.Api.HasTypeProxy -import Cardano.Api.Hash -import Cardano.Api.Keys.Class -import Cardano.Api.Keys.Shelley -import Cardano.Api.SerialiseCBOR -import Cardano.Api.SerialiseRaw -import Cardano.Api.SerialiseTextEnvelope -import Cardano.Api.SerialiseUsing -import Cardano.Binary (cborError, toStrictByteString) +import Cardano.Api.Hash +import Cardano.Api.HasTypeProxy +import Cardano.Api.Keys.Class +import Cardano.Api.Keys.Shelley +import Cardano.Api.SerialiseCBOR +import Cardano.Api.SerialiseRaw +import Cardano.Api.SerialiseTextEnvelope +import Cardano.Api.SerialiseUsing + +import Cardano.Binary (cborError, toStrictByteString) import qualified Cardano.Chain.Common as Crypto import qualified Cardano.Crypto.DSIGN.Class as Crypto import qualified Cardano.Crypto.Hashing as Crypto @@ -44,16 +45,17 @@ import qualified Cardano.Crypto.Seed as Crypto import qualified Cardano.Crypto.Signing as Crypto import qualified Cardano.Crypto.Wallet as Crypto.HD import qualified Cardano.Crypto.Wallet as Wallet + import qualified Codec.CBOR.Decoding as CBOR import qualified Codec.CBOR.Read as CBOR -import Control.Monad -import Data.Bifunctor +import Control.Monad +import Data.Bifunctor import qualified Data.ByteString.Lazy as LB -import Data.Either.Combinators -import Data.String (IsString) -import Data.Text (Text) +import Data.Either.Combinators +import Data.String (IsString) +import Data.Text (Text) import qualified Data.Text as Text -import Formatting (build, formatToString) +import Formatting (build, formatToString) -- | Byron-era payment keys. Used for Byron addresses and witnessing -- transactions that spend from these addresses. @@ -92,16 +94,16 @@ toByronSigningKey bWit = instance Key ByronKey where newtype VerificationKey ByronKey = ByronVerificationKey Crypto.VerificationKey - deriving stock (Eq) + deriving stock Eq deriving (Show, IsString) via UsingRawBytesHex (VerificationKey ByronKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR newtype SigningKey ByronKey = ByronSigningKey Crypto.SigningKey deriving (Show, IsString) via UsingRawBytesHex (SigningKey ByronKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deterministicSigningKey :: AsType ByronKey -> Crypto.Seed -> SigningKey ByronKey deterministicSigningKey AsByronKey seed = @@ -147,7 +149,7 @@ newtype instance Hash ByronKey = ByronKeyHash Crypto.KeyHash deriving (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash ByronKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash ByronKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash ByronKey) where serialiseToRawBytes (ByronKeyHash (Crypto.KeyHash vkh)) = @@ -183,16 +185,16 @@ instance IsByronKey ByronKey where instance Key ByronKeyLegacy where newtype VerificationKey ByronKeyLegacy = ByronVerificationKeyLegacy Crypto.VerificationKey - deriving stock (Eq) + deriving stock Eq deriving (Show, IsString) via UsingRawBytesHex (VerificationKey ByronKeyLegacy) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR newtype SigningKey ByronKeyLegacy = ByronSigningKeyLegacy Crypto.SigningKey deriving (Show, IsString) via UsingRawBytesHex (SigningKey ByronKeyLegacy) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deterministicSigningKey :: AsType ByronKeyLegacy -> Crypto.Seed -> SigningKey ByronKeyLegacy deterministicSigningKey _ _ = error "Please generate a non legacy Byron key instead" @@ -222,7 +224,7 @@ newtype instance Hash ByronKeyLegacy = ByronKeyHashLegacy Crypto.KeyHash deriving (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash ByronKeyLegacy) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash ByronKeyLegacy) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash ByronKeyLegacy) where serialiseToRawBytes (ByronKeyHashLegacy (Crypto.KeyHash vkh)) = diff --git a/cardano-api/internal/Cardano/Api/Keys/Class.hs b/cardano-api/internal/Cardano/Api/Keys/Class.hs index a142a6cdbd..44253514b5 100644 --- a/cardano-api/internal/Cardano/Api/Keys/Class.hs +++ b/cardano-api/internal/Cardano/Api/Keys/Class.hs @@ -13,16 +13,18 @@ module Cardano.Api.Keys.Class ) where -import Cardano.Api.HasTypeProxy -import Cardano.Api.Hash -import Cardano.Api.SerialiseRaw -import Cardano.Api.SerialiseTextEnvelope +import Cardano.Api.Hash +import Cardano.Api.HasTypeProxy +import Cardano.Api.SerialiseRaw +import Cardano.Api.SerialiseTextEnvelope + import qualified Cardano.Crypto.DSIGN.Class as Crypto import qualified Cardano.Crypto.Seed as Crypto -import Control.Monad.IO.Class -import Data.Kind (Type) -import System.Random (StdGen) + +import Control.Monad.IO.Class +import Data.Kind (Type) import qualified System.Random as Random +import System.Random (StdGen) -- | An interface for cryptographic keys used for signatures with a 'SigningKey' -- and a 'VerificationKey' key. diff --git a/cardano-api/internal/Cardano/Api/Keys/Praos.hs b/cardano-api/internal/Cardano/Api/Keys/Praos.hs index 27f6f60cc6..ad83c77b94 100644 --- a/cardano-api/internal/Cardano/Api/Keys/Praos.hs +++ b/cardano-api/internal/Cardano/Api/Keys/Praos.hs @@ -25,24 +25,26 @@ module Cardano.Api.Keys.Praos ) where -import Cardano.Api.HasTypeProxy -import Cardano.Api.Hash -import Cardano.Api.Keys.Class -import Cardano.Api.SerialiseBech32 -import Cardano.Api.SerialiseCBOR -import Cardano.Api.SerialiseRaw -import Cardano.Api.SerialiseTextEnvelope -import Cardano.Api.SerialiseUsing +import Cardano.Api.Hash +import Cardano.Api.HasTypeProxy +import Cardano.Api.Keys.Class +import Cardano.Api.SerialiseBech32 +import Cardano.Api.SerialiseCBOR +import Cardano.Api.SerialiseRaw +import Cardano.Api.SerialiseTextEnvelope +import Cardano.Api.SerialiseUsing + import qualified Cardano.Crypto.DSIGN.Class as Crypto import qualified Cardano.Crypto.Hash.Class as Crypto import qualified Cardano.Crypto.KES.Class as Crypto import qualified Cardano.Crypto.VRF.Class as Crypto -import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Crypto (StandardCrypto) import qualified Cardano.Ledger.Crypto as Shelley (KES, VRF) import qualified Cardano.Ledger.Keys as Shelley -import Data.ByteString (ByteString) -import Data.Either.Combinators (maybeToRight) -import Data.String (IsString (..)) + +import Data.ByteString (ByteString) +import Data.Either.Combinators (maybeToRight) +import Data.String (IsString (..)) -- -- KES keys @@ -57,16 +59,16 @@ instance HasTypeProxy KesKey where instance Key KesKey where newtype VerificationKey KesKey = KesVerificationKey (Shelley.VerKeyKES StandardCrypto) - deriving stock (Eq) + deriving stock Eq deriving (Show, IsString) via UsingRawBytesHex (VerificationKey KesKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR newtype SigningKey KesKey = KesSigningKey (Shelley.SignKeyKES StandardCrypto) deriving (Show, IsString) via UsingRawBytesHex (SigningKey KesKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR -- This loses the mlock safety of the seed, since it starts from a normal in-memory seed. deterministicSigningKey :: AsType KesKey -> Crypto.Seed -> SigningKey KesKey @@ -121,7 +123,7 @@ newtype instance Hash KesKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash KesKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash KesKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash KesKey) where serialiseToRawBytes (KesKeyHash vkh) = @@ -170,16 +172,16 @@ instance HasTypeProxy VrfKey where instance Key VrfKey where newtype VerificationKey VrfKey = VrfVerificationKey (Shelley.VerKeyVRF StandardCrypto) - deriving stock (Eq) + deriving stock Eq deriving (Show, IsString) via UsingRawBytesHex (VerificationKey VrfKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR newtype SigningKey VrfKey = VrfSigningKey (Shelley.SignKeyVRF StandardCrypto) deriving (Show, IsString) via UsingRawBytesHex (SigningKey VrfKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deterministicSigningKey :: AsType VrfKey -> Crypto.Seed -> SigningKey VrfKey deterministicSigningKey AsVrfKey seed = @@ -233,7 +235,7 @@ newtype instance Hash VrfKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash VrfKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash VrfKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash VrfKey) where serialiseToRawBytes (VrfKeyHash vkh) = diff --git a/cardano-api/internal/Cardano/Api/Keys/Read.hs b/cardano-api/internal/Cardano/Api/Keys/Read.hs index 7f2348b327..7d6d5313c8 100644 --- a/cardano-api/internal/Cardano/Api/Keys/Read.hs +++ b/cardano-api/internal/Cardano/Api/Keys/Read.hs @@ -11,16 +11,17 @@ module Cardano.Api.Keys.Read ) where -import Cardano.Api.DeserialiseAnyOf -import Cardano.Api.Error -import Cardano.Api.HasTypeProxy -import Cardano.Api.IO -import Cardano.Api.SerialiseBech32 -import Cardano.Api.SerialiseTextEnvelope -import Cardano.Api.Utils -import Control.Monad.Except (runExceptT) -import Data.Bifunctor -import Data.List.NonEmpty (NonEmpty) +import Cardano.Api.DeserialiseAnyOf +import Cardano.Api.Error +import Cardano.Api.HasTypeProxy +import Cardano.Api.IO +import Cardano.Api.SerialiseBech32 +import Cardano.Api.SerialiseTextEnvelope +import Cardano.Api.Utils + +import Control.Monad.Except (runExceptT) +import Data.Bifunctor +import Data.List.NonEmpty (NonEmpty) -- | Read a cryptographic key from a file. -- diff --git a/cardano-api/internal/Cardano/Api/Keys/Shelley.hs b/cardano-api/internal/Cardano/Api/Keys/Shelley.hs index 5c551bf25a..f9f18de8b5 100644 --- a/cardano-api/internal/Cardano/Api/Keys/Shelley.hs +++ b/cardano-api/internal/Cardano/Api/Keys/Shelley.hs @@ -39,31 +39,33 @@ module Cardano.Api.Keys.Shelley ) where -import Cardano.Api.Error -import Cardano.Api.HasTypeProxy -import Cardano.Api.Hash -import Cardano.Api.Keys.Class -import Cardano.Api.Pretty -import Cardano.Api.SerialiseBech32 -import Cardano.Api.SerialiseCBOR -import Cardano.Api.SerialiseJSON -import Cardano.Api.SerialiseRaw -import Cardano.Api.SerialiseTextEnvelope -import Cardano.Api.SerialiseUsing +import Cardano.Api.Error +import Cardano.Api.Hash +import Cardano.Api.HasTypeProxy +import Cardano.Api.Keys.Class +import Cardano.Api.Pretty +import Cardano.Api.SerialiseBech32 +import Cardano.Api.SerialiseCBOR +import Cardano.Api.SerialiseJSON +import Cardano.Api.SerialiseRaw +import Cardano.Api.SerialiseTextEnvelope +import Cardano.Api.SerialiseUsing + import qualified Cardano.Crypto.DSIGN.Class as Crypto import qualified Cardano.Crypto.Hash.Class as Crypto import qualified Cardano.Crypto.Seed as Crypto import qualified Cardano.Crypto.Wallet as Crypto.HD -import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Crypto (StandardCrypto) import qualified Cardano.Ledger.Crypto as Shelley (DSIGN) import qualified Cardano.Ledger.Keys as Shelley -import Data.Aeson.Types (ToJSONKey (..), toJSONKeyText, withText) -import Data.Bifunctor (first) -import Data.ByteString (ByteString) + +import Data.Aeson.Types (ToJSONKey (..), toJSONKeyText, withText) +import Data.Bifunctor (first) +import Data.ByteString (ByteString) import qualified Data.ByteString as BS -import Data.Either.Combinators (maybeToRight) -import Data.Maybe -import Data.String (IsString (..)) +import Data.Either.Combinators (maybeToRight) +import Data.Maybe +import Data.String (IsString (..)) -- -- Shelley payment keys @@ -82,16 +84,16 @@ instance HasTypeProxy PaymentKey where instance Key PaymentKey where newtype VerificationKey PaymentKey = PaymentVerificationKey (Shelley.VKey Shelley.Payment StandardCrypto) - deriving stock (Eq) + deriving stock Eq deriving (Show, IsString) via UsingRawBytesHex (VerificationKey PaymentKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR newtype SigningKey PaymentKey = PaymentSigningKey (Shelley.SignKeyDSIGN StandardCrypto) deriving (Show, IsString) via UsingRawBytesHex (SigningKey PaymentKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deterministicSigningKey :: AsType PaymentKey -> Crypto.Seed -> SigningKey PaymentKey deterministicSigningKey AsPaymentKey seed = @@ -146,7 +148,7 @@ newtype instance Hash PaymentKey deriving (Show, IsString) via UsingRawBytesHex (Hash PaymentKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash PaymentKey) deriving (ToJSONKey, ToJSON, FromJSON) via UsingRawBytesHex (Hash PaymentKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash PaymentKey) where serialiseToRawBytes (PaymentKeyHash (Shelley.KeyHash vkh)) = @@ -201,13 +203,13 @@ instance HasTypeProxy PaymentExtendedKey where instance Key PaymentExtendedKey where newtype VerificationKey PaymentExtendedKey = PaymentExtendedVerificationKey Crypto.HD.XPub - deriving stock (Eq) - deriving anyclass (SerialiseAsCBOR) + deriving stock Eq + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (VerificationKey PaymentExtendedKey) newtype SigningKey PaymentExtendedKey = PaymentExtendedSigningKey Crypto.HD.XPrv - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (SigningKey PaymentExtendedKey) deterministicSigningKey @@ -296,7 +298,7 @@ newtype instance Hash PaymentExtendedKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash PaymentExtendedKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash PaymentExtendedKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash PaymentExtendedKey) where serialiseToRawBytes (PaymentExtendedKeyHash (Shelley.KeyHash vkh)) = @@ -338,15 +340,15 @@ instance Key StakeKey where newtype VerificationKey StakeKey = StakeVerificationKey { unStakeVerificationKey :: Shelley.VKey Shelley.Staking StandardCrypto } - deriving stock (Eq) + deriving stock Eq deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (VerificationKey StakeKey) newtype SigningKey StakeKey = StakeSigningKey (Shelley.SignKeyDSIGN StandardCrypto) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (SigningKey StakeKey) deterministicSigningKey :: AsType StakeKey -> Crypto.Seed -> SigningKey StakeKey @@ -398,7 +400,7 @@ newtype instance Hash StakeKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash StakeKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash StakeKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash StakeKey) where serialiseToRawBytes (StakeKeyHash (Shelley.KeyHash vkh)) = @@ -452,13 +454,13 @@ instance HasTypeProxy StakeExtendedKey where instance Key StakeExtendedKey where newtype VerificationKey StakeExtendedKey = StakeExtendedVerificationKey Crypto.HD.XPub - deriving stock (Eq) - deriving anyclass (SerialiseAsCBOR) + deriving stock Eq + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (VerificationKey StakeExtendedKey) newtype SigningKey StakeExtendedKey = StakeExtendedSigningKey Crypto.HD.XPrv - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (SigningKey StakeExtendedKey) deterministicSigningKey @@ -546,7 +548,7 @@ newtype instance Hash StakeExtendedKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash StakeExtendedKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash StakeExtendedKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash StakeExtendedKey) where serialiseToRawBytes (StakeExtendedKeyHash (Shelley.KeyHash vkh)) = @@ -587,16 +589,16 @@ instance HasTypeProxy GenesisKey where instance Key GenesisKey where newtype VerificationKey GenesisKey = GenesisVerificationKey (Shelley.VKey Shelley.Genesis StandardCrypto) - deriving stock (Eq) + deriving stock Eq deriving (Show, IsString) via UsingRawBytesHex (VerificationKey GenesisKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR newtype SigningKey GenesisKey = GenesisSigningKey (Shelley.SignKeyDSIGN StandardCrypto) deriving (Show, IsString) via UsingRawBytesHex (SigningKey GenesisKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deterministicSigningKey :: AsType GenesisKey -> Crypto.Seed -> SigningKey GenesisKey deterministicSigningKey AsGenesisKey seed = @@ -640,7 +642,7 @@ newtype instance Hash GenesisKey deriving (Show, IsString) via UsingRawBytesHex (Hash GenesisKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash GenesisKey) deriving (ToJSONKey, ToJSON, FromJSON) via UsingRawBytesHex (Hash GenesisKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash GenesisKey) where serialiseToRawBytes (GenesisKeyHash (Shelley.KeyHash vkh)) = @@ -683,16 +685,16 @@ instance HasTypeProxy CommitteeHotKey where instance Key CommitteeHotKey where newtype VerificationKey CommitteeHotKey = CommitteeHotVerificationKey (Shelley.VKey Shelley.HotCommitteeRole StandardCrypto) - deriving stock (Eq) + deriving stock Eq deriving (Show, IsString) via UsingRawBytesHex (VerificationKey CommitteeHotKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR newtype SigningKey CommitteeHotKey = CommitteeHotSigningKey (Shelley.SignKeyDSIGN StandardCrypto) deriving (Show, IsString) via UsingRawBytesHex (SigningKey CommitteeHotKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deterministicSigningKey :: AsType CommitteeHotKey -> Crypto.Seed -> SigningKey CommitteeHotKey deterministicSigningKey AsCommitteeHotKey seed = @@ -738,7 +740,7 @@ newtype instance Hash CommitteeHotKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash CommitteeHotKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash CommitteeHotKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash CommitteeHotKey) where serialiseToRawBytes (CommitteeHotKeyHash (Shelley.KeyHash vkh)) = @@ -794,16 +796,16 @@ instance HasTypeProxy CommitteeColdKey where instance Key CommitteeColdKey where newtype VerificationKey CommitteeColdKey = CommitteeColdVerificationKey (Shelley.VKey Shelley.ColdCommitteeRole StandardCrypto) - deriving stock (Eq) + deriving stock Eq deriving (Show, IsString) via UsingRawBytesHex (VerificationKey CommitteeColdKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR newtype SigningKey CommitteeColdKey = CommitteeColdSigningKey (Shelley.SignKeyDSIGN StandardCrypto) deriving (Show, IsString) via UsingRawBytesHex (SigningKey CommitteeColdKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deterministicSigningKey :: AsType CommitteeColdKey -> Crypto.Seed -> SigningKey CommitteeColdKey deterministicSigningKey AsCommitteeColdKey seed = @@ -849,7 +851,7 @@ newtype instance Hash CommitteeColdKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash CommitteeColdKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash CommitteeColdKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash CommitteeColdKey) where serialiseToRawBytes (CommitteeColdKeyHash (Shelley.KeyHash vkh)) = @@ -904,13 +906,13 @@ instance HasTypeProxy CommitteeColdExtendedKey where instance Key CommitteeColdExtendedKey where newtype VerificationKey CommitteeColdExtendedKey = CommitteeColdExtendedVerificationKey Crypto.HD.XPub - deriving stock (Eq) - deriving anyclass (SerialiseAsCBOR) + deriving stock Eq + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (VerificationKey PaymentExtendedKey) newtype SigningKey CommitteeColdExtendedKey = CommitteeColdExtendedSigningKey Crypto.HD.XPrv - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (SigningKey PaymentExtendedKey) deterministicSigningKey @@ -949,7 +951,7 @@ newtype instance Hash CommitteeColdExtendedKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash CommitteeColdKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash CommitteeColdKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance ToCBOR (VerificationKey CommitteeColdExtendedKey) where toCBOR (CommitteeColdExtendedVerificationKey xpub) = @@ -1039,13 +1041,13 @@ instance HasTypeProxy CommitteeHotExtendedKey where instance Key CommitteeHotExtendedKey where newtype VerificationKey CommitteeHotExtendedKey = CommitteeHotExtendedVerificationKey Crypto.HD.XPub - deriving stock (Eq) - deriving anyclass (SerialiseAsCBOR) + deriving stock Eq + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (VerificationKey PaymentExtendedKey) newtype SigningKey CommitteeHotExtendedKey = CommitteeHotExtendedSigningKey Crypto.HD.XPrv - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (SigningKey PaymentExtendedKey) deterministicSigningKey @@ -1084,7 +1086,7 @@ newtype instance Hash CommitteeHotExtendedKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash CommitteeHotKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash CommitteeHotKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance ToCBOR (VerificationKey CommitteeHotExtendedKey) where toCBOR (CommitteeHotExtendedVerificationKey xpub) = @@ -1187,13 +1189,13 @@ instance HasTypeProxy GenesisExtendedKey where instance Key GenesisExtendedKey where newtype VerificationKey GenesisExtendedKey = GenesisExtendedVerificationKey Crypto.HD.XPub - deriving stock (Eq) - deriving anyclass (SerialiseAsCBOR) + deriving stock Eq + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (VerificationKey GenesisExtendedKey) newtype SigningKey GenesisExtendedKey = GenesisExtendedSigningKey Crypto.HD.XPrv - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (SigningKey GenesisExtendedKey) deterministicSigningKey @@ -1273,7 +1275,7 @@ newtype instance Hash GenesisExtendedKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash GenesisExtendedKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash GenesisExtendedKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash GenesisExtendedKey) where serialiseToRawBytes (GenesisExtendedKeyHash (Shelley.KeyHash vkh)) = @@ -1314,16 +1316,16 @@ instance HasTypeProxy GenesisDelegateKey where instance Key GenesisDelegateKey where newtype VerificationKey GenesisDelegateKey = GenesisDelegateVerificationKey (Shelley.VKey Shelley.GenesisDelegate StandardCrypto) - deriving stock (Eq) + deriving stock Eq deriving (Show, IsString) via UsingRawBytesHex (VerificationKey GenesisDelegateKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR newtype SigningKey GenesisDelegateKey = GenesisDelegateSigningKey (Shelley.SignKeyDSIGN StandardCrypto) deriving (Show, IsString) via UsingRawBytesHex (SigningKey GenesisDelegateKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deterministicSigningKey :: AsType GenesisDelegateKey -> Crypto.Seed -> SigningKey GenesisDelegateKey deterministicSigningKey AsGenesisDelegateKey seed = @@ -1367,7 +1369,7 @@ newtype instance Hash GenesisDelegateKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash GenesisDelegateKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash GenesisDelegateKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash GenesisDelegateKey) where serialiseToRawBytes (GenesisDelegateKeyHash (Shelley.KeyHash vkh)) = @@ -1430,13 +1432,13 @@ instance HasTypeProxy GenesisDelegateExtendedKey where instance Key GenesisDelegateExtendedKey where newtype VerificationKey GenesisDelegateExtendedKey = GenesisDelegateExtendedVerificationKey Crypto.HD.XPub - deriving stock (Eq) - deriving anyclass (SerialiseAsCBOR) + deriving stock Eq + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (VerificationKey GenesisDelegateExtendedKey) newtype SigningKey GenesisDelegateExtendedKey = GenesisDelegateExtendedSigningKey Crypto.HD.XPrv - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (SigningKey GenesisDelegateExtendedKey) deterministicSigningKey @@ -1522,7 +1524,7 @@ newtype instance Hash GenesisDelegateExtendedKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash GenesisDelegateExtendedKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash GenesisDelegateExtendedKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash GenesisDelegateExtendedKey) where serialiseToRawBytes (GenesisDelegateExtendedKeyHash (Shelley.KeyHash vkh)) = @@ -1563,16 +1565,16 @@ instance HasTypeProxy GenesisUTxOKey where instance Key GenesisUTxOKey where newtype VerificationKey GenesisUTxOKey = GenesisUTxOVerificationKey (Shelley.VKey Shelley.Payment StandardCrypto) - deriving stock (Eq) + deriving stock Eq deriving (Show, IsString) via UsingRawBytesHex (VerificationKey GenesisUTxOKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR newtype SigningKey GenesisUTxOKey = GenesisUTxOSigningKey (Shelley.SignKeyDSIGN StandardCrypto) deriving (Show, IsString) via UsingRawBytesHex (SigningKey GenesisUTxOKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deterministicSigningKey :: AsType GenesisUTxOKey -> Crypto.Seed -> SigningKey GenesisUTxOKey deterministicSigningKey AsGenesisUTxOKey seed = @@ -1614,7 +1616,7 @@ newtype instance Hash GenesisUTxOKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash GenesisUTxOKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash GenesisUTxOKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash GenesisUTxOKey) where serialiseToRawBytes (GenesisUTxOKeyHash (Shelley.KeyHash vkh)) = @@ -1664,16 +1666,16 @@ instance HasTypeProxy StakePoolKey where instance Key StakePoolKey where newtype VerificationKey StakePoolKey = StakePoolVerificationKey (Shelley.VKey Shelley.StakePool StandardCrypto) - deriving stock (Eq) + deriving stock Eq deriving (Show, IsString) via UsingRawBytesHex (VerificationKey StakePoolKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR newtype SigningKey StakePoolKey = StakePoolSigningKey (Shelley.SignKeyDSIGN StandardCrypto) deriving (Show, IsString) via UsingRawBytesHex (SigningKey StakePoolKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deterministicSigningKey :: AsType StakePoolKey -> Crypto.Seed -> SigningKey StakePoolKey deterministicSigningKey AsStakePoolKey seed = @@ -1726,7 +1728,7 @@ newtype instance Hash StakePoolKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash StakePoolKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash StakePoolKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash StakePoolKey) where serialiseToRawBytes (StakePoolKeyHash (Shelley.KeyHash vkh)) = @@ -1788,16 +1790,16 @@ instance HasTypeProxy DRepKey where instance Key DRepKey where newtype VerificationKey DRepKey = DRepVerificationKey (Shelley.VKey Shelley.DRepRole StandardCrypto) - deriving stock (Eq) + deriving stock Eq deriving (Show, IsString) via UsingRawBytesHex (VerificationKey DRepKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR newtype SigningKey DRepKey = DRepSigningKey (Shelley.SignKeyDSIGN StandardCrypto) deriving (Show, IsString) via UsingRawBytesHex (SigningKey DRepKey) deriving newtype (ToCBOR, FromCBOR) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deterministicSigningKey :: AsType DRepKey -> Crypto.Seed -> SigningKey DRepKey deterministicSigningKey AsDRepKey seed = @@ -1850,7 +1852,7 @@ newtype instance Hash DRepKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash DRepKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash DRepKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance SerialiseAsRawBytes (Hash DRepKey) where serialiseToRawBytes (DRepKeyHash (Shelley.KeyHash vkh)) = @@ -1911,13 +1913,13 @@ instance HasTypeProxy DRepExtendedKey where instance Key DRepExtendedKey where newtype VerificationKey DRepExtendedKey = DRepExtendedVerificationKey Crypto.HD.XPub - deriving stock (Eq) - deriving anyclass (SerialiseAsCBOR) + deriving stock Eq + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (VerificationKey PaymentExtendedKey) newtype SigningKey DRepExtendedKey = DRepExtendedSigningKey Crypto.HD.XPrv - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR deriving (Show, IsString) via UsingRawBytesHex (SigningKey PaymentExtendedKey) deterministicSigningKey @@ -1955,7 +1957,7 @@ newtype instance Hash DRepExtendedKey deriving stock (Eq, Ord) deriving (Show, IsString) via UsingRawBytesHex (Hash DRepKey) deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash DRepKey) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance ToCBOR (VerificationKey DRepExtendedKey) where toCBOR (DRepExtendedVerificationKey xpub) = diff --git a/cardano-api/internal/Cardano/Api/Ledger/Lens.hs b/cardano-api/internal/Cardano/Api/Ledger/Lens.hs index dc20111407..28ae78d467 100644 --- a/cardano-api/internal/Cardano/Api/Ledger/Lens.hs +++ b/cardano-api/internal/Cardano/Api/Ledger/Lens.hs @@ -41,31 +41,33 @@ module Cardano.Api.Ledger.Lens ) where -import Cardano.Api.Eon.AllegraEraOnwards -import Cardano.Api.Eon.AlonzoEraOnwards -import Cardano.Api.Eon.BabbageEraOnwards -import Cardano.Api.Eon.ConwayEraOnwards -import Cardano.Api.Eon.MaryEraOnwards -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eon.ShelleyEraOnly -import Cardano.Api.Eon.ShelleyToAllegraEra -import Cardano.Api.Eon.ShelleyToBabbageEra -import Cardano.Api.Eras.Case -import Cardano.Api.Orphans () +import Cardano.Api.Eon.AllegraEraOnwards +import Cardano.Api.Eon.AlonzoEraOnwards +import Cardano.Api.Eon.BabbageEraOnwards +import Cardano.Api.Eon.ConwayEraOnwards +import Cardano.Api.Eon.MaryEraOnwards +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eon.ShelleyEraOnly +import Cardano.Api.Eon.ShelleyToAllegraEra +import Cardano.Api.Eon.ShelleyToBabbageEra +import Cardano.Api.Eras.Case +import Cardano.Api.Orphans () + import qualified Cardano.Ledger.Allegra.Core as L import qualified Cardano.Ledger.Alonzo.Core as L import qualified Cardano.Ledger.Api as L -import Cardano.Ledger.BaseTypes (SlotNo, StrictMaybe (..)) +import Cardano.Ledger.BaseTypes (SlotNo, StrictMaybe (..)) import qualified Cardano.Ledger.Coin as L import qualified Cardano.Ledger.Conway.Core as L import qualified Cardano.Ledger.Keys as L import qualified Cardano.Ledger.Mary.Value as L import qualified Cardano.Ledger.Shelley.PParams as L import qualified Cardano.Ledger.TxIn as L + import qualified Data.OSet.Strict as L import qualified Data.Sequence.Strict as L -import Data.Set (Set) -import Lens.Micro +import Data.Set (Set) +import Lens.Micro newtype TxBody era = TxBody { unTxBody :: L.TxBody (ShelleyLedgerEra era) diff --git a/cardano-api/internal/Cardano/Api/LedgerEvents/ConvertLedgerEvent.hs b/cardano-api/internal/Cardano/Api/LedgerEvents/ConvertLedgerEvent.hs index 8e91891441..b01e22b1b5 100644 --- a/cardano-api/internal/Cardano/Api/LedgerEvents/ConvertLedgerEvent.hs +++ b/cardano-api/internal/Cardano/Api/LedgerEvents/ConvertLedgerEvent.hs @@ -13,47 +13,37 @@ module Cardano.Api.LedgerEvents.ConvertLedgerEvent ) where -import Cardano.Api.LedgerEvents.LedgerEvent -import Cardano.Api.LedgerEvents.Rule.BBODY.DELEGS -import Cardano.Api.LedgerEvents.Rule.BBODY.LEDGER -import Cardano.Api.LedgerEvents.Rule.BBODY.UTXOW -import Cardano.Api.LedgerEvents.Rule.TICK.NEWEPOCH -import Cardano.Api.LedgerEvents.Rule.TICK.RUPD +import Cardano.Api.LedgerEvents.LedgerEvent +import Cardano.Api.LedgerEvents.Rule.BBODY.DELEGS +import Cardano.Api.LedgerEvents.Rule.BBODY.LEDGER +import Cardano.Api.LedgerEvents.Rule.BBODY.UTXOW +import Cardano.Api.LedgerEvents.Rule.TICK.NEWEPOCH +import Cardano.Api.LedgerEvents.Rule.TICK.RUPD + import qualified Cardano.Ledger.Allegra.Rules as Allegra -import Cardano.Ledger.Alonzo.Rules (AlonzoBbodyEvent (..)) -import Cardano.Ledger.Api.Era - ( AllegraEra - , AlonzoEra - , BabbageEra - , ConwayEra - , MaryEra - , ShelleyEra - ) +import Cardano.Ledger.Alonzo.Rules (AlonzoBbodyEvent (..)) +import Cardano.Ledger.Api.Era (AllegraEra, AlonzoEra, BabbageEra, ConwayEra, MaryEra, + ShelleyEra) import qualified Cardano.Ledger.Conway.Rules as Conway -import Cardano.Ledger.Core +import Cardano.Ledger.Core import qualified Cardano.Ledger.Core as Ledger.Core -import Cardano.Ledger.Crypto (StandardCrypto) -import Cardano.Ledger.Shelley.Rules - ( RupdEvent (..) - , ShelleyBbodyEvent (LedgersEvent) - , ShelleyNewEpochEvent (..) - , ShelleyTickEvent (TickNewEpochEvent, TickRupdEvent) - , ShelleyUtxowEvent (..) - ) +import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Shelley.Rules (RupdEvent (..), ShelleyBbodyEvent (LedgersEvent), + ShelleyNewEpochEvent (..), ShelleyTickEvent (TickNewEpochEvent, TickRupdEvent), + ShelleyUtxowEvent (..)) import qualified Cardano.Ledger.Shelley.Rules as Shelley -import Control.State.Transition (Event) -import Data.SOP.Strict -import Ouroboros.Consensus.Byron.Ledger.Block (ByronBlock) -import Ouroboros.Consensus.Cardano.Block (HardForkBlock) +import Ouroboros.Consensus.Byron.Ledger.Block (ByronBlock) +import Ouroboros.Consensus.Cardano.Block (HardForkBlock) import qualified Ouroboros.Consensus.Cardano.Block as Consensus -import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (getOneEraLedgerEvent) +import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (getOneEraLedgerEvent) import qualified Ouroboros.Consensus.Protocol.Praos as Consensus import qualified Ouroboros.Consensus.Protocol.TPraos as Consensus -import Ouroboros.Consensus.Shelley.Ledger - ( ShelleyBlock - , ShelleyLedgerEvent (ShelleyLedgerEventBBODY, ShelleyLedgerEventTICK) - ) -import Ouroboros.Consensus.TypeFamilyWrappers (WrapLedgerEvent (unwrapLedgerEvent)) +import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock, + ShelleyLedgerEvent (ShelleyLedgerEventBBODY, ShelleyLedgerEventTICK)) +import Ouroboros.Consensus.TypeFamilyWrappers (WrapLedgerEvent (unwrapLedgerEvent)) + +import Control.State.Transition (Event) +import Data.SOP.Strict class ConvertLedgerEvent blk where toLedgerEvent :: WrapLedgerEvent blk -> Maybe LedgerEvent @@ -173,8 +163,8 @@ toLedgerEventConway evt = ShelleyLedgerEventBBODY (ShelleyInAlonzoEvent (LedgersEvent (Shelley.LedgerEvent conwayLedgerEvent))) -> case conwayLedgerEvent of - Conway.UtxowEvent {} -> Nothing - Conway.CertsEvent {} -> Nothing + Conway.UtxowEvent{} -> Nothing + Conway.CertsEvent{} -> Nothing Conway.GovEvent govEvent -> case govEvent of Conway.GovNewProposals txid props -> diff --git a/cardano-api/internal/Cardano/Api/LedgerEvents/LedgerEvent.hs b/cardano-api/internal/Cardano/Api/LedgerEvents/LedgerEvent.hs index eebc98a18c..04569fe33a 100644 --- a/cardano-api/internal/Cardano/Api/LedgerEvents/LedgerEvent.hs +++ b/cardano-api/internal/Cardano/Api/LedgerEvents/LedgerEvent.hs @@ -14,23 +14,25 @@ module Cardano.Api.LedgerEvents.LedgerEvent ) where -import Cardano.Api.Address (StakeCredential, fromShelleyStakeCredential) -import Cardano.Api.Block (EpochNo) -import Cardano.Api.Keys.Shelley (Hash (..), StakePoolKey) +import Cardano.Api.Address (StakeCredential, fromShelleyStakeCredential) +import Cardano.Api.Block (EpochNo) +import Cardano.Api.Keys.Shelley (Hash (..), StakePoolKey) + import qualified Cardano.Ledger.Coin as L import qualified Cardano.Ledger.Coin as Ledger import qualified Cardano.Ledger.Conway.Governance as Ledger import qualified Cardano.Ledger.Core as Ledger.Core import qualified Cardano.Ledger.Credential as Ledger -import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Crypto (StandardCrypto) import qualified Cardano.Ledger.Keys as Ledger -import Cardano.Ledger.Plutus.Evaluate (PlutusWithContext) -import Cardano.Ledger.Shelley.Rewards (Reward) +import Cardano.Ledger.Plutus.Evaluate (PlutusWithContext) +import Cardano.Ledger.Shelley.Rewards (Reward) import qualified Cardano.Ledger.TxIn as Ledger -import Data.List.NonEmpty (NonEmpty) -import Data.Map.Strict (Map) + +import Data.List.NonEmpty (NonEmpty) +import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map -import Data.Set (Set) +import Data.Set (Set) data AnyProposals = forall era. Ledger.Core.EraPParams era => AnyProposals (Ledger.Proposals era) @@ -68,7 +70,7 @@ data LedgerEvent | -- | The current state of governance matters at the epoch boundary. -- I.E the current constitution, committee, protocol parameters, etc. EpochBoundaryRatificationState AnyRatificationState - deriving (Show) + deriving Show -------------------------------------------------------------------------------- -- Event details @@ -85,7 +87,7 @@ data MIRDistributionDetails = MIRDistributionDetails , mirddReservesToTreasury :: L.Coin , mirddTreasuryToReserves :: L.Coin } - deriving (Show) + deriving Show data PoolReapDetails = PoolReapDetails { prdEpochNo :: EpochNo @@ -97,7 +99,7 @@ data PoolReapDetails = PoolReapDetails -- actively registered at the time of the pool reaping, and as such the -- funds are returned to the treasury. } - deriving (Show) + deriving Show convertRetiredPoolsMap :: Map diff --git a/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/BBODY/DELEGS.hs b/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/BBODY/DELEGS.hs index 1e01806da4..fcf3f0e335 100644 --- a/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/BBODY/DELEGS.hs +++ b/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/BBODY/DELEGS.hs @@ -6,7 +6,8 @@ module Cardano.Api.LedgerEvents.Rule.BBODY.DELEGS ) where -import Cardano.Api.LedgerEvents.LedgerEvent +import Cardano.Api.LedgerEvents.LedgerEvent + import qualified Cardano.Ledger.Shelley.Rules as Shelley handleShelleyDELEGSEvent :: Shelley.ShelleyDelegsEvent ledgerera -> Maybe LedgerEvent diff --git a/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/BBODY/LEDGER.hs b/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/BBODY/LEDGER.hs index 75d0bdd53c..19b5b97a74 100644 --- a/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/BBODY/LEDGER.hs +++ b/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/BBODY/LEDGER.hs @@ -9,19 +9,18 @@ module Cardano.Api.LedgerEvents.Rule.BBODY.LEDGER ) where -import Cardano.Api.LedgerEvents.LedgerEvent -import Cardano.Api.LedgerEvents.Rule.BBODY.DELEGS -import Cardano.Api.LedgerEvents.Rule.BBODY.UTXOW -import Cardano.Ledger.Alonzo.Rules - ( AlonzoUtxoEvent (..) - , AlonzoUtxosEvent (..) - , AlonzoUtxowEvent (..) - ) +import Cardano.Api.LedgerEvents.LedgerEvent +import Cardano.Api.LedgerEvents.Rule.BBODY.DELEGS +import Cardano.Api.LedgerEvents.Rule.BBODY.UTXOW + +import Cardano.Ledger.Alonzo.Rules (AlonzoUtxoEvent (..), AlonzoUtxosEvent (..), + AlonzoUtxowEvent (..)) import qualified Cardano.Ledger.Alonzo.Rules as Alonzo import qualified Cardano.Ledger.Core as Ledger.Core import qualified Cardano.Ledger.Crypto as Crypto import qualified Cardano.Ledger.Shelley.Rules as Shelley -import Control.State.Transition.Extended + +import Control.State.Transition.Extended type LatestBBodyEventConstraints ledgerera = ( Event (Ledger.Core.EraRule "BBODY" ledgerera) ~ Alonzo.AlonzoBbodyEvent ledgerera diff --git a/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/BBODY/UTXOW.hs b/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/BBODY/UTXOW.hs index 6e69ab70da..042bfa80e4 100644 --- a/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/BBODY/UTXOW.hs +++ b/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/BBODY/UTXOW.hs @@ -9,18 +9,17 @@ module Cardano.Api.LedgerEvents.Rule.BBODY.UTXOW ) where -import Cardano.Api.LedgerEvents.LedgerEvent +import Cardano.Api.LedgerEvents.LedgerEvent + import qualified Cardano.Ledger.Allegra.Rules as Allegra -import Cardano.Ledger.Alonzo.Rules - ( AlonzoUtxoEvent (..) - , AlonzoUtxosEvent (..) - , AlonzoUtxowEvent (..) - ) +import Cardano.Ledger.Alonzo.Rules (AlonzoUtxoEvent (..), AlonzoUtxosEvent (..), + AlonzoUtxowEvent (..)) import qualified Cardano.Ledger.Alonzo.Rules as Alonzo import qualified Cardano.Ledger.Core as Ledger.Core import qualified Cardano.Ledger.Crypto as Crypto import qualified Cardano.Ledger.Shelley.Rules as Shelley -import Control.State.Transition.Extended + +import Control.State.Transition.Extended handleAlonzoOnwardsUTxOWEvent :: Event (Ledger.Core.EraRule "UTXO" ledgerera) ~ AlonzoUtxoEvent ledgerera @@ -29,8 +28,8 @@ handleAlonzoOnwardsUTxOWEvent => AlonzoUtxowEvent ledgerera -> Maybe LedgerEvent handleAlonzoOnwardsUTxOWEvent (WrappedShelleyEraEvent (Shelley.UtxoEvent (UtxosEvent utxoEvent))) = case utxoEvent of - Alonzo.AlonzoPpupToUtxosEvent {} -> Nothing - Alonzo.TotalDeposits {} -> Nothing + Alonzo.AlonzoPpupToUtxosEvent{} -> Nothing + Alonzo.TotalDeposits{} -> Nothing Alonzo.SuccessfulPlutusScriptsEvent e -> Just $ SuccessfulPlutusScript e Alonzo.FailedPlutusScriptsEvent e -> Just $ FailedPlutusScript e Alonzo.TxUTxODiff _ _ -> Nothing @@ -41,7 +40,7 @@ handlePreAlonzoUTxOWEvent => Shelley.ShelleyUtxowEvent ledgerera -> Maybe LedgerEvent handlePreAlonzoUTxOWEvent (Shelley.UtxoEvent e) = case e of - Shelley.TotalDeposits {} -> Nothing + Shelley.TotalDeposits{} -> Nothing Shelley.UpdateEvent (Shelley.PpupNewEpoch _) -> Nothing Shelley.TxUTxODiff _ _ -> Nothing @@ -51,6 +50,6 @@ handleAllegraMaryUTxOWEvent => Shelley.ShelleyUtxowEvent ledgerera -> Maybe LedgerEvent handleAllegraMaryUTxOWEvent (Shelley.UtxoEvent e) = case e of - Allegra.TotalDeposits {} -> Nothing + Allegra.TotalDeposits{} -> Nothing Allegra.UpdateEvent (Shelley.PpupNewEpoch _) -> Nothing Allegra.TxUTxODiff _ _ -> Nothing diff --git a/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/TICK/NEWEPOCH.hs b/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/TICK/NEWEPOCH.hs index 1eaa12096e..a7c2e13806 100644 --- a/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/TICK/NEWEPOCH.hs +++ b/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/TICK/NEWEPOCH.hs @@ -12,15 +12,17 @@ module Cardano.Api.LedgerEvents.Rule.TICK.NEWEPOCH ) where -import Cardano.Api.Address (fromShelleyStakeCredential) -import Cardano.Api.LedgerEvents.LedgerEvent -import Cardano.Api.LedgerEvents.Rule.TICK.RUPD -import Cardano.Api.ReexposeLedger -import Cardano.Ledger.Conway.Rules (ConwayNewEpochEvent) +import Cardano.Api.Address (fromShelleyStakeCredential) +import Cardano.Api.LedgerEvents.LedgerEvent +import Cardano.Api.LedgerEvents.Rule.TICK.RUPD +import Cardano.Api.ReexposeLedger + +import Cardano.Ledger.Conway.Rules (ConwayNewEpochEvent) import qualified Cardano.Ledger.Conway.Rules as Conway import qualified Cardano.Ledger.Core as Core -import Cardano.Ledger.Shelley.Rules +import Cardano.Ledger.Shelley.Rules import qualified Cardano.Ledger.Shelley.Rules as Shelley + import qualified Data.Map.Strict as Map type LatestTickEventConstraints ledgerera = @@ -45,13 +47,13 @@ handleShelleyNEWEPOCHEvents => ShelleyNewEpochEvent ledgerera -> Maybe LedgerEvent handleShelleyNEWEPOCHEvents shelleyNewEpochEvent = case shelleyNewEpochEvent of - Shelley.DeltaRewardEvent {} -> Nothing - Shelley.RestrainedRewards {} -> Nothing + Shelley.DeltaRewardEvent{} -> Nothing + Shelley.RestrainedRewards{} -> Nothing Shelley.TotalRewardEvent epochNo rewardsMap -> Just $ RewardsDistribution epochNo (Map.mapKeys fromShelleyStakeCredential rewardsMap) Shelley.EpochEvent e -> handleEpochEvents e - Shelley.MirEvent {} -> Nothing -- We no longer care about MIR events - Shelley.TotalAdaPotsEvent {} -> Nothing + Shelley.MirEvent{} -> Nothing -- We no longer care about MIR events + Shelley.TotalAdaPotsEvent{} -> Nothing handleEpochEvents :: EraCrypto ledgerera ~ StandardCrypto @@ -59,14 +61,14 @@ handleEpochEvents => ShelleyEpochEvent ledgerera -> Maybe LedgerEvent handleEpochEvents (PoolReapEvent e) = case e of - RetiredPools {refundPools, unclaimedPools, epochNo} -> + RetiredPools{refundPools, unclaimedPools, epochNo} -> Just . PoolReap $ PoolReapDetails epochNo (convertRetiredPoolsMap refundPools) (convertRetiredPoolsMap unclaimedPools) -handleEpochEvents (SnapEvent {}) = Nothing -handleEpochEvents (UpecEvent {}) = Nothing +handleEpochEvents (SnapEvent{}) = Nothing +handleEpochEvents (UpecEvent{}) = Nothing handleConwayNEWEPOCHEvents :: EraCrypto ledgerera ~ StandardCrypto @@ -81,7 +83,7 @@ handleConwayNEWEPOCHEvents conwayNewEpochEvent = case rewardUpdate of RupdEvent epochNum rewards -> Just $ IncrementalRewardsDistribution epochNum (Map.mapKeys fromShelleyStakeCredential rewards) - Conway.RestrainedRewards {} -> Nothing + Conway.RestrainedRewards{} -> Nothing Conway.TotalRewardEvent epochNo rewardsMap -> Just $ RewardsDistribution epochNo (Map.mapKeys fromShelleyStakeCredential rewardsMap) Conway.EpochEvent epochEvent -> @@ -90,12 +92,12 @@ handleConwayNEWEPOCHEvents conwayNewEpochEvent = Just $ EpochBoundaryRatificationState (AnyRatificationState ratifyState) Conway.PoolReapEvent poolReap -> case poolReap of - RetiredPools {refundPools, unclaimedPools, epochNo} -> + RetiredPools{refundPools, unclaimedPools, epochNo} -> Just . PoolReap $ PoolReapDetails epochNo (convertRetiredPoolsMap refundPools) (convertRetiredPoolsMap unclaimedPools) Conway.SnapEvent _ -> Nothing - Conway.GovInfoEvent {} -> Nothing + Conway.GovInfoEvent{} -> Nothing Conway.TotalAdaPotsEvent _ -> Nothing diff --git a/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/TICK/RUPD.hs b/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/TICK/RUPD.hs index 23b2ac02f6..19d2d29906 100644 --- a/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/TICK/RUPD.hs +++ b/cardano-api/internal/Cardano/Api/LedgerEvents/Rule/TICK/RUPD.hs @@ -3,10 +3,12 @@ module Cardano.Api.LedgerEvents.Rule.TICK.RUPD ) where -import Cardano.Api.Address (fromShelleyStakeCredential) -import Cardano.Api.LedgerEvents.LedgerEvent (LedgerEvent (IncrementalRewardsDistribution)) -import Cardano.Ledger.Crypto (StandardCrypto) -import Cardano.Ledger.Shelley.Rules +import Cardano.Api.Address (fromShelleyStakeCredential) +import Cardano.Api.LedgerEvents.LedgerEvent (LedgerEvent (IncrementalRewardsDistribution)) + +import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Shelley.Rules + import qualified Data.Map.Strict as Map handleLedgerRUPDEvents :: RupdEvent StandardCrypto -> Maybe LedgerEvent diff --git a/cardano-api/internal/Cardano/Api/LedgerState.hs b/cardano-api/internal/Cardano/Api/LedgerState.hs index fcfff007aa..f828fb2172 100644 --- a/cardano-api/internal/Cardano/Api/LedgerState.hs +++ b/cardano-api/internal/Cardano/Api/LedgerState.hs @@ -94,121 +94,66 @@ module Cardano.Api.LedgerState ) where -import Cardano.Api.Block -import Cardano.Api.Certificate -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Case -import Cardano.Api.Eras.Core (forEraMaybeEon) -import Cardano.Api.Error as Api -import Cardano.Api.Genesis -import Cardano.Api.IO -import Cardano.Api.IPC - ( ConsensusModeParams (..) - , LocalChainSyncClient (LocalChainSyncClientPipelined) - , LocalNodeClientProtocols (..) - , LocalNodeClientProtocolsInMode - , LocalNodeConnectInfo (..) - , connectToLocalNode - ) -import Cardano.Api.Keys.Praos -import Cardano.Api.LedgerEvents.ConvertLedgerEvent -import Cardano.Api.LedgerEvents.LedgerEvent -import Cardano.Api.Modes (EpochSlots (..)) +import Cardano.Api.Block +import Cardano.Api.Certificate +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Case +import Cardano.Api.Eras.Core (forEraMaybeEon) +import Cardano.Api.Error as Api +import Cardano.Api.Genesis +import Cardano.Api.IO +import Cardano.Api.IPC (ConsensusModeParams (..), + LocalChainSyncClient (LocalChainSyncClientPipelined), + LocalNodeClientProtocols (..), LocalNodeClientProtocolsInMode, + LocalNodeConnectInfo (..), connectToLocalNode) +import Cardano.Api.Keys.Praos +import Cardano.Api.LedgerEvents.ConvertLedgerEvent +import Cardano.Api.LedgerEvents.LedgerEvent +import Cardano.Api.Modes (EpochSlots (..)) import qualified Cardano.Api.Modes as Api -import Cardano.Api.Monad.Error -import Cardano.Api.NetworkId (NetworkId (..), NetworkMagic (NetworkMagic)) -import Cardano.Api.Pretty -import Cardano.Api.Query - ( CurrentEpochState (..) - , PoolDistribution (unPoolDistr) - , ProtocolState - , SerialisedCurrentEpochState (..) - , SerialisedPoolDistribution - , decodeCurrentEpochState - , decodePoolDistribution - , decodeProtocolState - ) +import Cardano.Api.Monad.Error +import Cardano.Api.NetworkId (NetworkId (..), NetworkMagic (NetworkMagic)) +import Cardano.Api.Pretty +import Cardano.Api.Query (CurrentEpochState (..), PoolDistribution (unPoolDistr), + ProtocolState, SerialisedCurrentEpochState (..), SerialisedPoolDistribution, + decodeCurrentEpochState, decodePoolDistribution, decodeProtocolState) import qualified Cardano.Api.ReexposeLedger as Ledger -import Cardano.Api.SpecialByron as Byron -import Cardano.Api.Utils (textShow) +import Cardano.Api.SpecialByron as Byron +import Cardano.Api.Utils (textShow) + import qualified Cardano.Binary as CBOR import qualified Cardano.Chain.Genesis import qualified Cardano.Chain.Update -import Cardano.Crypto (ProtocolMagicId (unProtocolMagicId), RequiresNetworkMagic (..)) +import Cardano.Crypto (ProtocolMagicId (unProtocolMagicId), RequiresNetworkMagic (..)) import qualified Cardano.Crypto.Hash.Blake2b import qualified Cardano.Crypto.Hash.Class import qualified Cardano.Crypto.Hashing import qualified Cardano.Crypto.ProtocolMagic import qualified Cardano.Crypto.VRF as Crypto import qualified Cardano.Crypto.VRF.Class as VRF -import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis (..)) +import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis (..)) import qualified Cardano.Ledger.Api.Era as Ledger import qualified Cardano.Ledger.Api.Transition as Ledger -import qualified Cardano.Ledger.BHeaderView as Ledger -import Cardano.Ledger.BaseTypes (Globals (..), Nonce, ProtVer (..), natVersion, (â­’)) +import Cardano.Ledger.BaseTypes (Globals (..), Nonce, ProtVer (..), natVersion, (â­’)) import qualified Cardano.Ledger.BaseTypes as Ledger -import Cardano.Ledger.Binary (DecoderError) +import qualified Cardano.Ledger.BHeaderView as Ledger +import Cardano.Ledger.Binary (DecoderError) import qualified Cardano.Ledger.Coin as SL -import Cardano.Ledger.Conway.Genesis (ConwayGenesis (..)) +import Cardano.Ledger.Conway.Genesis (ConwayGenesis (..)) import qualified Cardano.Ledger.Keys as SL import qualified Cardano.Ledger.PoolDistr as SL import qualified Cardano.Ledger.Shelley.API as ShelleyAPI import qualified Cardano.Ledger.Shelley.Core as Core import qualified Cardano.Ledger.Shelley.Genesis as Ledger import qualified Cardano.Protocol.TPraos.API as TPraos -import Cardano.Protocol.TPraos.BHeader (checkLeaderNatValue) +import Cardano.Protocol.TPraos.BHeader (checkLeaderNatValue) import qualified Cardano.Protocol.TPraos.BHeader as TPraos -import Cardano.Slotting.EpochInfo (EpochInfo) +import Cardano.Slotting.EpochInfo (EpochInfo) import qualified Cardano.Slotting.EpochInfo.API as Slot -import Cardano.Slotting.Slot (WithOrigin (At, Origin)) +import Cardano.Slotting.Slot (WithOrigin (At, Origin)) import qualified Cardano.Slotting.Slot as Slot -import Control.Concurrent -import Control.DeepSeq -import Control.Error.Util (note) -import Control.Exception.Safe -import Control.Monad -import Control.Monad.State.Strict -import Data.Aeson as Aeson - ( FromJSON (parseJSON) - , Object - , eitherDecodeStrict' - , withObject - , (.:) - , (.:?) - ) -import Data.Aeson.Types (Parser) -import Data.Bifunctor -import Data.ByteArray (ByteArrayAccess) -import qualified Data.ByteArray -import Data.ByteString (ByteString) -import qualified Data.ByteString as BS -import qualified Data.ByteString.Base16 as Base16 -import qualified Data.ByteString.Lazy as LB -import Data.ByteString.Short as BSS -import Data.Foldable -import Data.IORef -import qualified Data.List as List -import Data.Map.Strict (Map) -import qualified Data.Map.Strict as Map -import Data.Maybe -import Data.Proxy (Proxy (Proxy)) -import Data.SOP.Strict.NP -import Data.Sequence (Seq) -import qualified Data.Sequence as Seq -import Data.Set (Set) -import qualified Data.Set as Set -import Data.Text (Text) -import qualified Data.Text as Text -import qualified Data.Text.Encoding as Text -import qualified Data.Text.Lazy as LT -import Data.Text.Lazy.Builder (toLazyText) -import Data.Word -import qualified Data.Yaml as Yaml -import Formatting.Buildable (build) -import Lens.Micro -import Network.TypedProtocol.Pipelined (Nat (..)) import qualified Ouroboros.Consensus.Block.Abstract as Consensus -import Ouroboros.Consensus.Block.Forging (BlockForging) +import Ouroboros.Consensus.Block.Forging (BlockForging) import qualified Ouroboros.Consensus.Byron.Ledger as Byron import qualified Ouroboros.Consensus.Cardano as Consensus import qualified Ouroboros.Consensus.Cardano.Block as Consensus @@ -222,21 +167,61 @@ import qualified Ouroboros.Consensus.Ledger.Abstract as Ledger import qualified Ouroboros.Consensus.Ledger.Extended as Ledger import qualified Ouroboros.Consensus.Mempool.Capacity as TxLimits import qualified Ouroboros.Consensus.Node.ProtocolInfo as Consensus -import Ouroboros.Consensus.Protocol.Abstract (ChainDepState, ConsensusProtocol (..)) +import Ouroboros.Consensus.Protocol.Abstract (ChainDepState, ConsensusProtocol (..)) import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus -import Ouroboros.Consensus.Protocol.Praos.VRF (mkInputVRF, vrfLeaderValue) +import Ouroboros.Consensus.Protocol.Praos.VRF (mkInputVRF, vrfLeaderValue) import qualified Ouroboros.Consensus.Shelley.HFEras as Shelley import qualified Ouroboros.Consensus.Shelley.Ledger.Ledger as Shelley import qualified Ouroboros.Consensus.Shelley.Ledger.Query.Types as Consensus -import Ouroboros.Consensus.Storage.Serialisation -import Ouroboros.Consensus.TypeFamilyWrappers (WrapLedgerEvent (WrapLedgerEvent)) -import Ouroboros.Network.Block (blockNo) +import Ouroboros.Consensus.Storage.Serialisation +import Ouroboros.Consensus.TypeFamilyWrappers (WrapLedgerEvent (WrapLedgerEvent)) +import Ouroboros.Network.Block (blockNo) import qualified Ouroboros.Network.Block -import Ouroboros.Network.Mux (MuxError) +import Ouroboros.Network.Mux (MuxError) import qualified Ouroboros.Network.Protocol.ChainSync.Client as CS import qualified Ouroboros.Network.Protocol.ChainSync.ClientPipelined as CSP -import Ouroboros.Network.Protocol.ChainSync.PipelineDecision -import System.FilePath +import Ouroboros.Network.Protocol.ChainSync.PipelineDecision + +import Control.Concurrent +import Control.DeepSeq +import Control.Error.Util (note) +import Control.Exception.Safe +import Control.Monad +import Control.Monad.State.Strict +import Data.Aeson as Aeson (FromJSON (parseJSON), Object, eitherDecodeStrict', withObject, + (.:), (.:?)) +import Data.Aeson.Types (Parser) +import Data.Bifunctor +import Data.ByteArray (ByteArrayAccess) +import qualified Data.ByteArray +import Data.ByteString (ByteString) +import qualified Data.ByteString as BS +import qualified Data.ByteString.Base16 as Base16 +import qualified Data.ByteString.Lazy as LB +import Data.ByteString.Short as BSS +import Data.Foldable +import Data.IORef +import qualified Data.List as List +import Data.Map.Strict (Map) +import qualified Data.Map.Strict as Map +import Data.Maybe +import Data.Proxy (Proxy (Proxy)) +import Data.Sequence (Seq) +import qualified Data.Sequence as Seq +import Data.Set (Set) +import qualified Data.Set as Set +import Data.SOP.Strict.NP +import Data.Text (Text) +import qualified Data.Text as Text +import qualified Data.Text.Encoding as Text +import qualified Data.Text.Lazy as LT +import Data.Text.Lazy.Builder (toLazyText) +import Data.Word +import qualified Data.Yaml as Yaml +import Formatting.Buildable (build) +import Lens.Micro +import Network.TypedProtocol.Pipelined (Nat (..)) +import System.FilePath data InitialLedgerStateError = -- | Failed to read or parse the network config file. @@ -245,7 +230,7 @@ data InitialLedgerStateError ILSEGenesisFile GenesisConfigError | -- | Failed to derive the Ledger or Consensus config. ILSELedgerConsensusConfig GenesisConfigError - deriving (Show) + deriving Show instance Exception InitialLedgerStateError @@ -281,7 +266,7 @@ data LedgerStateError -- ^ Ledgerstate from an unexpected era | ByronEraUnsupported | DebugError !String - deriving (Show) + deriving Show instance Exception LedgerStateError @@ -390,7 +375,7 @@ data FoldBlocksError | FoldBlocksApplyBlockError !LedgerStateError | FoldBlocksIOException !IOException | FoldBlocksMuxError !MuxError - deriving (Show) + deriving Show instance Error FoldBlocksError where prettyError = \case @@ -1191,7 +1176,7 @@ initLedgerStateVar genesisConfig = newtype LedgerState = LedgerState { clsState :: Consensus.CardanoLedgerState Consensus.StandardCrypto } - deriving (Show) + deriving Show -- | Retrieve new epoch state from the ledger state, or an error on failure getAnyNewEpochState @@ -1281,12 +1266,12 @@ data GenesisConfig newtype LedgerStateDir = LedgerStateDir { unLedgerStateDir :: FilePath } - deriving (Show) + deriving Show newtype NetworkName = NetworkName { unNetworkName :: Text } - deriving (Show) + deriving Show type NodeConfigFile = File NodeConfig @@ -1374,7 +1359,7 @@ data GenesisConfigError | NEAlonzoConfig !FilePath !Text | NEConwayConfig !FilePath !Text | NECardanoConfig !Text - deriving (Show) + deriving Show instance Exception GenesisConfigError @@ -1486,7 +1471,7 @@ data ShelleyGenesisError = ShelleyGenesisReadError !FilePath !Text | ShelleyGenesisHashMismatch !GenesisHashShelley !GenesisHashShelley -- actual, expected | ShelleyGenesisDecodeError !FilePath !Text - deriving (Show) + deriving Show instance Exception ShelleyGenesisError @@ -1539,7 +1524,7 @@ data AlonzoGenesisError = AlonzoGenesisReadError !FilePath !Text | AlonzoGenesisHashMismatch !GenesisHashAlonzo !GenesisHashAlonzo -- actual, expected | AlonzoGenesisDecodeError !FilePath !Text - deriving (Show) + deriving Show instance Exception AlonzoGenesisError @@ -1597,7 +1582,7 @@ data ConwayGenesisError | ConwayGenesisHashMissing !FilePath | ConwayGenesisFileMissing | ConwayGenesisDecodeError !FilePath !Text - deriving (Show) + deriving Show instance Exception ConwayGenesisError @@ -1770,7 +1755,7 @@ data LeadershipError -- ^ Predicted last slot of the epoch | LeaderErrSlotRangeCalculationFailure Text | LeaderErrCandidateNonceStillEvolving - deriving (Show) + deriving Show instance Api.Error LeadershipError where prettyError = \case @@ -1853,7 +1838,7 @@ nextEpochEligibleLeadershipSlots sbe sGen serCurrEpochState ptclState poolid (Vr -- We need the candidate nonce, the previous epoch's last block header hash -- and the extra entropy from the protocol parameters. We then need to combine them -- with the (â­’) operator. - let Consensus.PraosNonces {Consensus.candidateNonce, Consensus.evolvingNonce} = + let Consensus.PraosNonces{Consensus.candidateNonce, Consensus.evolvingNonce} = Consensus.getPraosNonces (Proxy @(Api.ConsensusProtocol era)) chainDepState -- Let's do a nonce check. The candidate nonce and the evolving nonce should not be equal. diff --git a/cardano-api/internal/Cardano/Api/Modes.hs b/cardano-api/internal/Cardano/Api/Modes.hs index ed0fa6c33f..1b87a40b7c 100644 --- a/cardano-api/internal/Cardano/Api/Modes.hs +++ b/cardano-api/internal/Cardano/Api/Modes.hs @@ -27,25 +27,24 @@ module Cardano.Api.Modes ) where -import Cardano.Api.Eras.Core +import Cardano.Api.Eras.Core + import qualified Cardano.Chain.Slotting as Byron (EpochSlots (..)) import qualified Cardano.Ledger.Api as L -import Cardano.Ledger.Crypto (StandardCrypto) -import Data.SOP (K (K)) -import Data.SOP.Strict (NS (S, Z)) +import Cardano.Ledger.Crypto (StandardCrypto) import qualified Ouroboros.Consensus.Byron.Ledger as Consensus import qualified Ouroboros.Consensus.Cardano.Block as Consensus import qualified Ouroboros.Consensus.Cardano.ByronHFC as Consensus -import Ouroboros.Consensus.HardFork.Combinator as Consensus - ( EraIndex (..) - , eraIndexSucc - , eraIndexZero - ) +import Ouroboros.Consensus.HardFork.Combinator as Consensus (EraIndex (..), eraIndexSucc, + eraIndexZero) import qualified Ouroboros.Consensus.Protocol.Praos as Consensus import qualified Ouroboros.Consensus.Protocol.TPraos as Consensus import qualified Ouroboros.Consensus.Shelley.HFEras as Consensus import qualified Ouroboros.Consensus.Shelley.ShelleyHFC as Consensus +import Data.SOP (K (K)) +import Data.SOP.Strict (NS (S, Z)) + -- ---------------------------------------------------------------------------- -- Consensus modes -- diff --git a/cardano-api/internal/Cardano/Api/Monad/Error.hs b/cardano-api/internal/Cardano/Api/Monad/Error.hs index 49a092e2a5..6ec12de71e 100644 --- a/cardano-api/internal/Cardano/Api/Monad/Error.hs +++ b/cardano-api/internal/Cardano/Api/Monad/Error.hs @@ -21,23 +21,14 @@ module Cardano.Api.Monad.Error ) where -import Control.Exception.Safe -import Control.Monad.Except - ( ExceptT (..) - , MonadError (..) - , catchError - , liftEither - , mapExcept - , mapExceptT - , runExcept - , runExceptT - , withExcept - ) -import Control.Monad.IO.Class -import Control.Monad.Trans.Class -import Control.Monad.Trans.Except -import Control.Monad.Trans.Except.Extra -import Data.Bifunctor (first) +import Control.Exception.Safe +import Control.Monad.Except (ExceptT (..), MonadError (..), catchError, liftEither, + mapExcept, mapExceptT, runExcept, runExceptT, withExcept) +import Control.Monad.IO.Class +import Control.Monad.Trans.Class +import Control.Monad.Trans.Except +import Control.Monad.Trans.Except.Extra +import Data.Bifunctor (first) -- | Convenience alias type MonadTransError e t m = (Monad m, MonadTrans t, MonadError e (t m)) diff --git a/cardano-api/internal/Cardano/Api/NetworkId.hs b/cardano-api/internal/Cardano/Api/NetworkId.hs index 99cc43ea69..f52a60b8d2 100644 --- a/cardano-api/internal/Cardano/Api/NetworkId.hs +++ b/cardano-api/internal/Cardano/Api/NetworkId.hs @@ -18,12 +18,10 @@ where import qualified Cardano.Chain.Common as Byron (NetworkMagic (..)) import qualified Cardano.Chain.Genesis as Byron (mainnetProtocolMagicId) -import qualified Cardano.Crypto.ProtocolMagic as Byron - ( ProtocolMagicId (..) - , RequiresNetworkMagic (..) - ) +import qualified Cardano.Crypto.ProtocolMagic as Byron (ProtocolMagicId (..), + RequiresNetworkMagic (..)) import qualified Cardano.Ledger.BaseTypes as Shelley (Network (..)) -import Ouroboros.Network.Magic (NetworkMagic (..)) +import Ouroboros.Network.Magic (NetworkMagic (..)) -- ---------------------------------------------------------------------------- -- NetworkId type @@ -64,7 +62,7 @@ toByronNetworkMagic (Testnet (NetworkMagic nm)) = Byron.NetworkTestnet nm toByronRequiresNetworkMagic :: NetworkId -> Byron.RequiresNetworkMagic toByronRequiresNetworkMagic Mainnet = Byron.RequiresNoMagic -toByronRequiresNetworkMagic Testnet {} = Byron.RequiresMagic +toByronRequiresNetworkMagic Testnet{} = Byron.RequiresMagic -- ---------------------------------------------------------------------------- -- Shelley conversion functions diff --git a/cardano-api/internal/Cardano/Api/OperationalCertificate.hs b/cardano-api/internal/Cardano/Api/OperationalCertificate.hs index 8c066415f4..b5fe0fc15e 100644 --- a/cardano-api/internal/Cardano/Api/OperationalCertificate.hs +++ b/cardano-api/internal/Cardano/Api/OperationalCertificate.hs @@ -18,22 +18,24 @@ module Cardano.Api.OperationalCertificate ) where -import Cardano.Api.Address -import Cardano.Api.Certificate -import Cardano.Api.Error -import Cardano.Api.HasTypeProxy -import Cardano.Api.Keys.Byron -import Cardano.Api.Keys.Class -import Cardano.Api.Keys.Praos -import Cardano.Api.Keys.Shelley -import Cardano.Api.ProtocolParameters -import Cardano.Api.SerialiseCBOR -import Cardano.Api.SerialiseTextEnvelope -import Cardano.Api.Tx.Sign -import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Api.Address +import Cardano.Api.Certificate +import Cardano.Api.Error +import Cardano.Api.HasTypeProxy +import Cardano.Api.Keys.Byron +import Cardano.Api.Keys.Class +import Cardano.Api.Keys.Praos +import Cardano.Api.Keys.Shelley +import Cardano.Api.ProtocolParameters +import Cardano.Api.SerialiseCBOR +import Cardano.Api.SerialiseTextEnvelope +import Cardano.Api.Tx.Sign + +import Cardano.Ledger.Crypto (StandardCrypto) import qualified Cardano.Ledger.Keys as Shelley import qualified Cardano.Protocol.TPraos.OCert as Shelley -import Data.Word + +import Data.Word -- ---------------------------------------------------------------------------- -- Operational certificates @@ -44,7 +46,7 @@ data OperationalCertificate !(Shelley.OCert StandardCrypto) !(VerificationKey StakePoolKey) deriving (Eq, Show) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR data OperationalCertificateIssueCounter = OperationalCertificateIssueCounter @@ -52,7 +54,7 @@ data OperationalCertificateIssueCounter , opCertIssueColdKey :: !(VerificationKey StakePoolKey) -- For consistency checking } deriving (Eq, Show) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance ToCBOR OperationalCertificate where toCBOR (OperationalCertificate ocert vkey) = @@ -95,7 +97,7 @@ data OperationalCertIssueError OperationalCertKeyMismatch (VerificationKey StakePoolKey) (VerificationKey StakePoolKey) - deriving (Show) + deriving Show instance Error OperationalCertIssueError where prettyError (OperationalCertKeyMismatch _counterKey _signingKey) = diff --git a/cardano-api/internal/Cardano/Api/Orphans.hs b/cardano-api/internal/Cardano/Api/Orphans.hs index 2df04691d1..ca6d447c5b 100644 --- a/cardano-api/internal/Cardano/Api/Orphans.hs +++ b/cardano-api/internal/Cardano/Api/Orphans.hs @@ -15,19 +15,20 @@ module Cardano.Api.Orphans () where -import Cardano.Api.Pretty (Pretty (..), prettyException, (<+>)) -import Cardano.Api.Via.ShowOf -import Cardano.Binary (DecoderError (..)) +import Cardano.Api.Pretty (Pretty (..), prettyException, (<+>)) +import Cardano.Api.Via.ShowOf + +import Cardano.Binary (DecoderError (..)) import qualified Cardano.Chain.Byron.API as L import qualified Cardano.Chain.Common as L import qualified Cardano.Chain.Delegation.Validation.Scheduling as L.Scheduling -import qualified Cardano.Chain.UTxO.UTxO as L -import qualified Cardano.Chain.UTxO.Validation as L import qualified Cardano.Chain.Update as L import qualified Cardano.Chain.Update.Validation.Endorsement as L.Endorsement import qualified Cardano.Chain.Update.Validation.Interface as L.Interface import qualified Cardano.Chain.Update.Validation.Registration as L.Registration import qualified Cardano.Chain.Update.Validation.Voting as L.Voting +import qualified Cardano.Chain.UTxO.UTxO as L +import qualified Cardano.Chain.UTxO.Validation as L import qualified Cardano.Ledger.Allegra.Rules as L import qualified Cardano.Ledger.Alonzo.PParams as Ledger import qualified Cardano.Ledger.Alonzo.Rules as L @@ -35,21 +36,21 @@ import qualified Cardano.Ledger.Alonzo.Tx as L import qualified Cardano.Ledger.Api as L import qualified Cardano.Ledger.Babbage.PParams as Ledger import qualified Cardano.Ledger.Babbage.Rules as L -import Cardano.Ledger.BaseTypes (strictMaybeToMaybe) +import Cardano.Ledger.BaseTypes (strictMaybeToMaybe) import qualified Cardano.Ledger.BaseTypes as L import qualified Cardano.Ledger.BaseTypes as Ledger -import Cardano.Ledger.Binary +import Cardano.Ledger.Binary import qualified Cardano.Ledger.Binary.Plain as Plain import qualified Cardano.Ledger.Coin as L import qualified Cardano.Ledger.Conway.PParams as Ledger import qualified Cardano.Ledger.Conway.Rules as L import qualified Cardano.Ledger.Conway.TxCert as L import qualified Cardano.Ledger.Core as L -import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Crypto (StandardCrypto) import qualified Cardano.Ledger.Crypto as CC (Crypto) import qualified Cardano.Ledger.Crypto as Crypto import qualified Cardano.Ledger.Crypto as L -import Cardano.Ledger.HKD (NoUpdate (..)) +import Cardano.Ledger.HKD (NoUpdate (..)) import qualified Cardano.Ledger.Keys as L.Keys import qualified Cardano.Ledger.SafeHash as L import qualified Cardano.Ledger.Shelley.API.Mempool as L @@ -58,37 +59,38 @@ import qualified Cardano.Ledger.Shelley.Rules as L import qualified Cardano.Ledger.Shelley.TxBody as L import qualified Cardano.Ledger.Shelley.TxCert as L import qualified Cardano.Protocol.TPraos.API as Ledger -import Cardano.Protocol.TPraos.BHeader (HashHeader (..)) +import Cardano.Protocol.TPraos.BHeader (HashHeader (..)) import qualified Cardano.Protocol.TPraos.Rules.Prtcl as L import qualified Cardano.Protocol.TPraos.Rules.Prtcl as Ledger import qualified Cardano.Protocol.TPraos.Rules.Tickn as Ledger +import Ouroboros.Consensus.Byron.Ledger.Block (ByronHash (..)) +import Ouroboros.Consensus.HardFork.Combinator (OneEraHash (..)) +import Ouroboros.Consensus.Protocol.Praos (PraosState) +import qualified Ouroboros.Consensus.Protocol.Praos as Consensus +import Ouroboros.Consensus.Protocol.TPraos (TPraosState) +import qualified Ouroboros.Consensus.Protocol.TPraos as Consensus +import qualified Ouroboros.Consensus.Shelley.Eras as Consensus +import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyHash (..)) +import qualified Ouroboros.Consensus.Shelley.Ledger.Query as Consensus +import Ouroboros.Network.Block (HeaderHash, Tip (..)) +import Ouroboros.Network.Mux (MuxError) + import qualified Codec.Binary.Bech32 as Bech32 import qualified Codec.CBOR.Read as CBOR -import Data.Aeson (KeyValue ((.=)), ToJSON (..), ToJSONKey (..), object, pairs) +import Data.Aeson (KeyValue ((.=)), ToJSON (..), ToJSONKey (..), object, pairs) import qualified Data.Aeson as Aeson import qualified Data.ByteString.Base16 as Base16 import qualified Data.ByteString.Short as SBS -import Data.Data (Data) -import Data.Kind (Constraint, Type) -import Data.Maybe.Strict (StrictMaybe (..)) -import Data.Monoid +import Data.Data (Data) +import Data.Kind (Constraint, Type) +import Data.Maybe.Strict (StrictMaybe (..)) +import Data.Monoid import qualified Data.Text.Encoding as Text -import Data.Typeable (Typeable) -import GHC.Generics -import GHC.Stack (HasCallStack) -import GHC.TypeLits -import Lens.Micro -import Ouroboros.Consensus.Byron.Ledger.Block (ByronHash (..)) -import Ouroboros.Consensus.HardFork.Combinator (OneEraHash (..)) -import Ouroboros.Consensus.Protocol.Praos (PraosState) -import qualified Ouroboros.Consensus.Protocol.Praos as Consensus -import Ouroboros.Consensus.Protocol.TPraos (TPraosState) -import qualified Ouroboros.Consensus.Protocol.TPraos as Consensus -import qualified Ouroboros.Consensus.Shelley.Eras as Consensus -import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyHash (..)) -import qualified Ouroboros.Consensus.Shelley.Ledger.Query as Consensus -import Ouroboros.Network.Block (HeaderHash, Tip (..)) -import Ouroboros.Network.Mux (MuxError) +import Data.Typeable (Typeable) +import GHC.Generics +import GHC.Stack (HasCallStack) +import GHC.TypeLits +import Lens.Micro deriving instance Generic (L.ApplyTxError era) diff --git a/cardano-api/internal/Cardano/Api/Pretty.hs b/cardano-api/internal/Cardano/Api/Pretty.hs index fba616db5b..8ad2fd7c9e 100644 --- a/cardano-api/internal/Cardano/Api/Pretty.hs +++ b/cardano-api/internal/Cardano/Api/Pretty.hs @@ -22,12 +22,13 @@ module Cardano.Api.Pretty ) where -import Cardano.Api.Via.ShowOf -import Control.Exception.Safe +import Cardano.Api.Via.ShowOf + +import Control.Exception.Safe import qualified Data.Text as Text import qualified Data.Text.Lazy as TextLazy -import Prettyprinter -import Prettyprinter.Render.Terminal +import Prettyprinter +import Prettyprinter.Render.Terminal -- | 'Ann' is the prettyprinter annotation for cardano-api and cardano-cli to enable the printing -- of colored output. This is a type alias for AnsiStyle. diff --git a/cardano-api/internal/Cardano/Api/Protocol.hs b/cardano-api/internal/Cardano/Api/Protocol.hs index ce4ad6b932..0df6915935 100644 --- a/cardano-api/internal/Cardano/Api/Protocol.hs +++ b/cardano-api/internal/Cardano/Api/Protocol.hs @@ -19,24 +19,27 @@ module Cardano.Api.Protocol ) where -import Cardano.Api.Modes -import Data.Bifunctor (bimap) -import Ouroboros.Consensus.Block.Forging (BlockForging) +import Cardano.Api.Modes + +import Ouroboros.Consensus.Block.Forging (BlockForging) import qualified Ouroboros.Consensus.Byron.Ledger as Byron -import Ouroboros.Consensus.Cardano -import Ouroboros.Consensus.Cardano.Block -import Ouroboros.Consensus.Cardano.ByronHFC (ByronBlockHFC) -import Ouroboros.Consensus.Cardano.Node -import Ouroboros.Consensus.HardFork.Combinator.Embed.Unary +import Ouroboros.Consensus.Cardano +import Ouroboros.Consensus.Cardano.Block +import Ouroboros.Consensus.Cardano.ByronHFC (ByronBlockHFC) +import Ouroboros.Consensus.Cardano.Node +import Ouroboros.Consensus.HardFork.Combinator.Embed.Unary import qualified Ouroboros.Consensus.Ledger.SupportsProtocol as Consensus -import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolClientInfo (..), ProtocolInfo (..)) -import Ouroboros.Consensus.Node.Run (RunNode) +import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolClientInfo (..), ProtocolInfo (..)) +import Ouroboros.Consensus.Node.Run (RunNode) import qualified Ouroboros.Consensus.Protocol.TPraos as Consensus import qualified Ouroboros.Consensus.Shelley.Eras as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger.Block as Consensus -import Ouroboros.Consensus.Shelley.ShelleyHFC (ShelleyBlockHFC) -import Ouroboros.Consensus.Util.IOLike (IOLike) -import Type.Reflection ((:~:) (..)) +import Ouroboros.Consensus.Shelley.ShelleyHFC (ShelleyBlockHFC) +import Ouroboros.Consensus.Util.IOLike (IOLike) + +import Data.Bifunctor (bimap) + +import Type.Reflection ((:~:) (..)) class (RunNode blk, IOLike m) => Protocol m blk where data ProtocolInfoArgs blk diff --git a/cardano-api/internal/Cardano/Api/Protocol/Version.hs b/cardano-api/internal/Cardano/Api/Protocol/Version.hs index 9fc414d99c..21af782d96 100644 --- a/cardano-api/internal/Cardano/Api/Protocol/Version.hs +++ b/cardano-api/internal/Cardano/Api/Protocol/Version.hs @@ -24,9 +24,10 @@ module Cardano.Api.Protocol.Version ) where -import Cardano.Api.Eon.ShelleyBasedEra (ShelleyBasedEra (..)) +import Cardano.Api.Eon.ShelleyBasedEra (ShelleyBasedEra (..)) import qualified Cardano.Api.Eras.Core as Api -import GHC.TypeLits + +import GHC.TypeLits -- | Users typically interact with the latest features on the mainnet or experiment with features -- from the upcoming era. Hence, the protocol versions are limited to the current mainnet era diff --git a/cardano-api/internal/Cardano/Api/ProtocolParameters.hs b/cardano-api/internal/Cardano/Api/ProtocolParameters.hs index 54f0320fd0..6032d4f7f0 100644 --- a/cardano-api/internal/Cardano/Api/ProtocolParameters.hs +++ b/cardano-api/internal/Cardano/Api/ProtocolParameters.hs @@ -95,73 +95,67 @@ module Cardano.Api.ProtocolParameters ) where -import Cardano.Api.Address -import Cardano.Api.Eon.AlonzoEraOnwards -import Cardano.Api.Eon.BabbageEraOnwards -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras -import Cardano.Api.Error -import Cardano.Api.HasTypeProxy -import Cardano.Api.Hash -import Cardano.Api.Json (toRationalJSON) -import Cardano.Api.Keys.Byron -import Cardano.Api.Keys.Shelley -import Cardano.Api.Orphans () -import Cardano.Api.Pretty -import Cardano.Api.Script -import Cardano.Api.SerialiseCBOR -import Cardano.Api.SerialiseRaw -import Cardano.Api.SerialiseTextEnvelope -import Cardano.Api.SerialiseUsing -import Cardano.Api.StakePoolMetadata -import Cardano.Api.TxMetadata -import Cardano.Api.Utils -import Cardano.Api.Value +import Cardano.Api.Address +import Cardano.Api.Eon.AlonzoEraOnwards +import Cardano.Api.Eon.BabbageEraOnwards +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras +import Cardano.Api.Error +import Cardano.Api.Hash +import Cardano.Api.HasTypeProxy +import Cardano.Api.Json (toRationalJSON) +import Cardano.Api.Keys.Byron +import Cardano.Api.Keys.Shelley +import Cardano.Api.Orphans () +import Cardano.Api.Pretty +import Cardano.Api.Script +import Cardano.Api.SerialiseCBOR +import Cardano.Api.SerialiseRaw +import Cardano.Api.SerialiseTextEnvelope +import Cardano.Api.SerialiseUsing +import Cardano.Api.StakePoolMetadata +import Cardano.Api.TxMetadata +import Cardano.Api.Utils +import Cardano.Api.Value + import qualified Cardano.Binary as CBOR import qualified Cardano.Crypto.Hash.Class as Crypto import qualified Cardano.Ledger.Alonzo.PParams as Ledger import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo import qualified Cardano.Ledger.Api.Era as Ledger -import Cardano.Ledger.Api.PParams +import Cardano.Ledger.Api.PParams import qualified Cardano.Ledger.Babbage.Core as Ledger -import Cardano.Ledger.BaseTypes (strictMaybeToMaybe) +import Cardano.Ledger.BaseTypes (strictMaybeToMaybe) import qualified Cardano.Ledger.BaseTypes as Ledger import qualified Cardano.Ledger.Coin as L import qualified Cardano.Ledger.Conway.PParams as Ledger -import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Crypto (StandardCrypto) import qualified Cardano.Ledger.Keys as Ledger import qualified Cardano.Ledger.Plutus.CostModels as Plutus import qualified Cardano.Ledger.Plutus.Language as Plutus import qualified Cardano.Ledger.Shelley.API as Ledger -import Cardano.Slotting.Slot (EpochNo (..)) -import Control.Monad -import Data.Aeson - ( FromJSON (..) - , ToJSON (..) - , object - , withObject - , (.!=) - , (.:) - , (.:?) - , (.=) - ) -import Data.Bifunctor (bimap, first) -import Data.ByteString (ByteString) -import Data.Data (Data) -import Data.Either.Combinators (maybeToRight) -import Data.Int (Int64) -import Data.Map.Strict (Map) +import Cardano.Slotting.Slot (EpochNo (..)) +import PlutusLedgerApi.Common (CostModelApplyError) + +import Control.Monad +import Data.Aeson (FromJSON (..), ToJSON (..), object, withObject, (.!=), (.:), (.:?), + (.=)) +import Data.Bifunctor (bimap, first) +import Data.ByteString (ByteString) +import Data.Data (Data) +import Data.Either.Combinators (maybeToRight) +import Data.Int (Int64) +import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map -import Data.Maybe (isJust) -import Data.Maybe.Strict (StrictMaybe (..)) -import Data.String (IsString) -import Data.Text (Text) -import Data.Word -import GHC.Generics -import Lens.Micro -import Numeric.Natural -import PlutusLedgerApi.Common (CostModelApplyError) -import Text.PrettyBy.Default (display) +import Data.Maybe (isJust) +import Data.Maybe.Strict (StrictMaybe (..)) +import Data.String (IsString) +import Data.Text (Text) +import Data.Word +import GHC.Generics +import Lens.Micro +import Numeric.Natural +import Text.PrettyBy.Default (display) -- ----------------------------------------------------------------------------- -- Era based ledger protocol parameters @@ -258,13 +252,13 @@ data IntroducedInConwayPParams era , icDRepActivity :: StrictMaybe Ledger.EpochInterval , icMinFeeRefScriptCostPerByte :: StrictMaybe Ledger.NonNegativeInterval } - deriving (Show) + deriving Show createIntroducedInConwayPParams :: Ledger.ConwayEraPParams ledgerera => IntroducedInConwayPParams ledgerera -> Ledger.PParamsUpdate ledgerera -createIntroducedInConwayPParams IntroducedInConwayPParams {..} = +createIntroducedInConwayPParams IntroducedInConwayPParams{..} = Ledger.emptyPParamsUpdate & Ledger.ppuPoolVotingThresholdsL .~ icPoolVotingThresholds & Ledger.ppuDRepVotingThresholdsL .~ icDRepVotingThresholds @@ -337,12 +331,12 @@ data CommonProtocolParametersUpdate , cppMonetaryExpansion :: StrictMaybe Ledger.UnitInterval , cppMinPoolCost :: StrictMaybe Ledger.Coin } - deriving (Show) + deriving Show -- | Create a protocol parameters update with parameters common to all eras createCommonPParamsUpdate :: EraPParams ledgerera => CommonProtocolParametersUpdate -> Ledger.PParamsUpdate ledgerera -createCommonPParamsUpdate CommonProtocolParametersUpdate {..} = +createCommonPParamsUpdate CommonProtocolParametersUpdate{..} = emptyPParamsUpdate & Ledger.ppuMinFeeAL .~ cppMinFeeA & Ledger.ppuMinFeeBL .~ cppMinFeeB @@ -373,11 +367,11 @@ createPreConwayProtocolVersionUpdate (DeprecatedAfterBabbagePParams cppProtocolV newtype DeprecatedAfterMaryPParams ledgerera = DeprecatedAfterMaryPParams (StrictMaybe Ledger.Coin) -- Minimum UTxO value - deriving (Show) + deriving Show newtype DeprecatedAfterBabbagePParams ledgerera = DeprecatedAfterBabbagePParams (StrictMaybe Ledger.ProtVer) - deriving (Show) + deriving Show type MaxMaryEra ledgerera = Ledger.ProtVerAtMost ledgerera 4 @@ -394,7 +388,7 @@ data ShelleyToAlonzoPParams ledgerera -- ^ Extra entropy (StrictMaybe Ledger.UnitInterval) -- ^ Decentralization parameter - deriving (Show) + deriving Show type MaxAlonzoEra ledgerera = Ledger.ProtVerAtMost ledgerera 6 @@ -419,14 +413,14 @@ data AlonzoOnwardsPParams ledgerera , alCollateralPercentage :: StrictMaybe Natural , alMaxCollateralInputs :: StrictMaybe Natural } - deriving (Show) + deriving Show createPParamsUpdateIntroducedInAlonzo :: () => AlonzoEraOnwards era -> AlonzoOnwardsPParams era -> Ledger.PParamsUpdate (ShelleyLedgerEra era) -createPParamsUpdateIntroducedInAlonzo w (AlonzoOnwardsPParams {..}) = +createPParamsUpdateIntroducedInAlonzo w (AlonzoOnwardsPParams{..}) = alonzoEraOnwardsConstraints w $ Ledger.emptyPParamsUpdate & Ledger.ppuCostModelsL .~ alCostModels @@ -441,7 +435,7 @@ newtype IntroducedInBabbagePParams era = -- | Coins per UTxO byte IntroducedInBabbagePParams (StrictMaybe CoinPerByte) - deriving (Show) + deriving Show createIntroducedInBabbagePParams :: () @@ -616,7 +610,7 @@ instance FromJSON ProtocolParameters where <*> o .:? "utxoCostPerByte" instance ToJSON ProtocolParameters where - toJSON ProtocolParameters {..} = + toJSON ProtocolParameters{..} = object [ "extraPraosEntropy" .= protocolParamExtraPraosEntropy , "stakePoolTargetNum" .= protocolParamStakePoolTargetNum @@ -842,7 +836,7 @@ instance Monoid ProtocolParametersUpdate where instance ToCBOR ProtocolParametersUpdate where toCBOR :: ProtocolParametersUpdate -> CBOR.Encoding - toCBOR ProtocolParametersUpdate {..} = + toCBOR ProtocolParametersUpdate{..} = CBOR.encodeListLen 26 <> toCBOR protocolUpdateProtocolVersion <> toCBOR protocolUpdateDecentralization @@ -949,7 +943,7 @@ data ExecutionUnitPrices deriving (Eq, Show) instance ToCBOR ExecutionUnitPrices where - toCBOR ExecutionUnitPrices {priceExecutionSteps, priceExecutionMemory} = + toCBOR ExecutionUnitPrices{priceExecutionSteps, priceExecutionMemory} = CBOR.encodeListLen 2 <> toCBOR priceExecutionSteps <> toCBOR priceExecutionMemory @@ -962,7 +956,7 @@ instance FromCBOR ExecutionUnitPrices where <*> fromCBOR instance ToJSON ExecutionUnitPrices where - toJSON ExecutionUnitPrices {priceExecutionSteps, priceExecutionMemory} = + toJSON ExecutionUnitPrices{priceExecutionSteps, priceExecutionMemory} = object [ "priceSteps" .= toRationalJSON priceExecutionSteps , "priceMemory" .= toRationalJSON priceExecutionMemory @@ -990,7 +984,7 @@ toAlonzoPrices } fromAlonzoPrices :: Alonzo.Prices -> ExecutionUnitPrices -fromAlonzoPrices Alonzo.Prices {Alonzo.prSteps, Alonzo.prMem} = +fromAlonzoPrices Alonzo.Prices{Alonzo.prSteps, Alonzo.prMem} = ExecutionUnitPrices { priceExecutionSteps = Ledger.unboundRational prSteps , priceExecutionMemory = Ledger.unboundRational prMem @@ -1065,7 +1059,7 @@ data UpdateProposal !(Map (Hash GenesisKey) ProtocolParametersUpdate) !EpochNo deriving stock (Eq, Show) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance HasTypeProxy UpdateProposal where data AsType UpdateProposal = AsUpdateProposal @@ -1764,7 +1758,7 @@ checkProtocolParameters => ShelleyBasedEra era -> ProtocolParameters -> Either ProtocolParametersError () -checkProtocolParameters sbe ProtocolParameters {..} = +checkProtocolParameters sbe ProtocolParameters{..} = case sbe of ShelleyBasedEraShelley -> checkMinUTxOVal ShelleyBasedEraAllegra -> checkMinUTxOVal @@ -1833,7 +1827,7 @@ checkProtocolParameters sbe ProtocolParameters {..} = data ProtocolParametersError = PParamsErrorMissingMinUTxoValue !AnyCardanoEra | PParamsErrorMissingAlonzoProtocolParameter - deriving (Show) + deriving Show instance Error ProtocolParametersError where prettyError = \case diff --git a/cardano-api/internal/Cardano/Api/Query.hs b/cardano-api/internal/Cardano/Api/Query.hs index 1841d16341..011e10eec9 100644 --- a/cardano-api/internal/Cardano/Api/Query.hs +++ b/cardano-api/internal/Cardano/Api/Query.hs @@ -64,62 +64,44 @@ module Cardano.Api.Query ) where -import Cardano.Api.Address -import Cardano.Api.Block -import Cardano.Api.Certificate -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Case -import Cardano.Api.Eras.Core -import Cardano.Api.GenesisParameters -import Cardano.Api.IPC.Version -import Cardano.Api.Keys.Shelley -import Cardano.Api.Modes -import Cardano.Api.NetworkId -import Cardano.Api.ProtocolParameters -import Cardano.Api.Query.Types +import Cardano.Api.Address +import Cardano.Api.Block +import Cardano.Api.Certificate +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Case +import Cardano.Api.Eras.Core +import Cardano.Api.GenesisParameters +import Cardano.Api.IPC.Version +import Cardano.Api.Keys.Shelley +import Cardano.Api.Modes +import Cardano.Api.NetworkId +import Cardano.Api.ProtocolParameters +import Cardano.Api.Query.Types import qualified Cardano.Api.ReexposeLedger as Ledger -import Cardano.Api.Tx.Body +import Cardano.Api.Tx.Body + import qualified Cardano.Chain.Update.Validation.Interface as Byron.Update import qualified Cardano.Ledger.Api as L import qualified Cardano.Ledger.Api.State.Query as L -import Cardano.Ledger.Binary +import Cardano.Ledger.Binary import qualified Cardano.Ledger.Binary.Plain as Plain import qualified Cardano.Ledger.CertState as L import qualified Cardano.Ledger.Coin as L import qualified Cardano.Ledger.Credential as Shelley -import Cardano.Ledger.Crypto (Crypto) +import Cardano.Ledger.Crypto (Crypto) import qualified Cardano.Ledger.Shelley.API as Shelley import qualified Cardano.Ledger.Shelley.Core as Core import qualified Cardano.Ledger.Shelley.LedgerState as L import qualified Cardano.Ledger.Shelley.LedgerState as Shelley -import Cardano.Slotting.EpochInfo (hoistEpochInfo) -import Cardano.Slotting.Slot (WithOrigin (..)) -import Cardano.Slotting.Time (SystemStart (..)) -import Control.Monad.Trans.Except -import Data.Aeson (FromJSON (..), ToJSON (..), withObject) -import qualified Data.Aeson as Aeson -import qualified Data.Aeson.KeyMap as KeyMap -import Data.Aeson.Types (Parser) -import Data.Bifunctor (bimap, first) -import qualified Data.ByteString.Lazy as LBS -import Data.Either.Combinators (rightToMaybe) -import qualified Data.HashMap.Strict as HMS -import Data.Map.Strict (Map) -import qualified Data.Map.Strict as Map -import Data.Maybe (mapMaybe) -import Data.SOP.Constraint (SListI) -import Data.Set (Set) -import qualified Data.Set as Set -import Data.Text (Text) -import qualified Data.Text as Text -import Data.Word (Word64) -import GHC.Stack -import Ouroboros.Consensus.BlockchainTime.WallClock.Types (RelativeTime, SlotLength) +import Cardano.Slotting.EpochInfo (hoistEpochInfo) +import Cardano.Slotting.Slot (WithOrigin (..)) +import Cardano.Slotting.Time (SystemStart (..)) +import Ouroboros.Consensus.BlockchainTime.WallClock.Types (RelativeTime, SlotLength) import qualified Ouroboros.Consensus.Byron.Ledger as Consensus -import Ouroboros.Consensus.Cardano.Block (LedgerState (..), StandardCrypto) +import Ouroboros.Consensus.Cardano.Block (LedgerState (..), StandardCrypto) import qualified Ouroboros.Consensus.Cardano.Block as Consensus import qualified Ouroboros.Consensus.HardFork.Combinator as Consensus -import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (EraMismatch) +import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (EraMismatch) import qualified Ouroboros.Consensus.HardFork.Combinator.AcrossEras as Consensus import qualified Ouroboros.Consensus.HardFork.History as Consensus import qualified Ouroboros.Consensus.HardFork.History as History @@ -128,9 +110,29 @@ import qualified Ouroboros.Consensus.Ledger.Query as Consensus import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger.Query.Types as Consensus -import Ouroboros.Network.Block (Serialised (..)) -import Ouroboros.Network.NodeToClient.Version (NodeToClientVersion (..)) -import Ouroboros.Network.Protocol.LocalStateQuery.Client (Some (..)) +import Ouroboros.Network.Block (Serialised (..)) +import Ouroboros.Network.NodeToClient.Version (NodeToClientVersion (..)) +import Ouroboros.Network.Protocol.LocalStateQuery.Client (Some (..)) + +import Control.Monad.Trans.Except +import Data.Aeson (FromJSON (..), ToJSON (..), withObject) +import qualified Data.Aeson as Aeson +import qualified Data.Aeson.KeyMap as KeyMap +import Data.Aeson.Types (Parser) +import Data.Bifunctor (bimap, first) +import qualified Data.ByteString.Lazy as LBS +import Data.Either.Combinators (rightToMaybe) +import qualified Data.HashMap.Strict as HMS +import Data.Map.Strict (Map) +import qualified Data.Map.Strict as Map +import Data.Maybe (mapMaybe) +import Data.Set (Set) +import qualified Data.Set as Set +import Data.SOP.Constraint (SListI) +import Data.Text (Text) +import qualified Data.Text as Text +import Data.Word (Word64) +import GHC.Stack -- ---------------------------------------------------------------------------- -- Queries @@ -318,10 +320,10 @@ instance NodeToClientVersionOf (QueryInShelleyBasedEra era result) where nodeToClientVersionOf QueryAccountState = NodeToClientV_16 nodeToClientVersionOf QueryConstitution = NodeToClientV_16 nodeToClientVersionOf QueryGovState = NodeToClientV_16 - nodeToClientVersionOf QueryDRepState {} = NodeToClientV_16 - nodeToClientVersionOf QueryDRepStakeDistr {} = NodeToClientV_16 - nodeToClientVersionOf QueryCommitteeMembersState {} = NodeToClientV_16 - nodeToClientVersionOf QueryStakeVoteDelegatees {} = NodeToClientV_16 + nodeToClientVersionOf QueryDRepState{} = NodeToClientV_16 + nodeToClientVersionOf QueryDRepStakeDistr{} = NodeToClientV_16 + nodeToClientVersionOf QueryCommitteeMembersState{} = NodeToClientV_16 + nodeToClientVersionOf QueryStakeVoteDelegatees{} = NodeToClientV_16 deriving instance Show (QueryInShelleyBasedEra era result) @@ -350,7 +352,7 @@ instance NodeToClientVersionOf QueryUTxOFilter where nodeToClientVersionOf (QueryUTxOByTxIn _) = NodeToClientV_9 newtype ByronUpdateState = ByronUpdateState Byron.Update.State - deriving (Show) + deriving Show newtype UTxO era = UTxO {unUTxO :: Map TxIn (TxOut CtxUTxO era)} deriving (Eq, Show) @@ -874,17 +876,17 @@ fromConsensusQueryResultShelleyBased sbe sbeQuery q' r' = case q' of Consensus.GetUTxOWhole -> fromLedgerUTxO sbe r' _ -> fromConsensusQueryResultMismatch - QueryUTxO QueryUTxOByAddress {} -> + QueryUTxO QueryUTxOByAddress{} -> case q' of - Consensus.GetUTxOByAddress {} -> fromLedgerUTxO sbe r' + Consensus.GetUTxOByAddress{} -> fromLedgerUTxO sbe r' _ -> fromConsensusQueryResultMismatch - QueryUTxO QueryUTxOByTxIn {} -> + QueryUTxO QueryUTxOByTxIn{} -> case q' of - Consensus.GetUTxOByTxIn {} -> fromLedgerUTxO sbe r' + Consensus.GetUTxOByTxIn{} -> fromLedgerUTxO sbe r' _ -> fromConsensusQueryResultMismatch QueryStakeAddresses _ nId -> case q' of - Consensus.GetFilteredDelegationsAndRewardAccounts {} -> + Consensus.GetFilteredDelegationsAndRewardAccounts{} -> let (delegs, rwaccs) = r' in ( Map.mapKeys (makeStakeAddress nId) $ fromShelleyRewardAccounts rwaccs , Map.mapKeys (makeStakeAddress nId) $ fromShelleyDelegations delegs @@ -894,14 +896,14 @@ fromConsensusQueryResultShelleyBased sbe sbeQuery q' r' = case q' of Consensus.GetStakePools -> Set.map StakePoolKeyHash r' _ -> fromConsensusQueryResultMismatch - QueryStakePoolParameters {} -> + QueryStakePoolParameters{} -> case q' of - Consensus.GetStakePoolParams {} -> + Consensus.GetStakePoolParams{} -> Map.map fromShelleyPoolParams . Map.mapKeysMonotonic StakePoolKeyHash $ r' _ -> fromConsensusQueryResultMismatch - QueryDebugLedgerState {} -> + QueryDebugLedgerState{} -> case q' of Consensus.GetCBOR Consensus.DebugNewEpochState -> SerialisedDebugLedgerState r' @@ -916,54 +918,54 @@ fromConsensusQueryResultShelleyBased sbe sbeQuery q' r' = Consensus.GetCBOR Consensus.DebugEpochState -> SerialisedCurrentEpochState r' _ -> fromConsensusQueryResultMismatch - QueryPoolState {} -> + QueryPoolState{} -> case q' of - Consensus.GetCBOR Consensus.GetPoolState {} -> + Consensus.GetCBOR Consensus.GetPoolState{} -> SerialisedPoolState r' _ -> fromConsensusQueryResultMismatch - QueryPoolDistribution {} -> + QueryPoolDistribution{} -> case q' of - Consensus.GetCBOR Consensus.GetPoolDistr {} -> + Consensus.GetCBOR Consensus.GetPoolDistr{} -> SerialisedPoolDistribution r' _ -> fromConsensusQueryResultMismatch - QueryStakeSnapshot {} -> + QueryStakeSnapshot{} -> case q' of - Consensus.GetCBOR Consensus.GetStakeSnapshots {} -> + Consensus.GetCBOR Consensus.GetStakeSnapshots{} -> SerialisedStakeSnapshots r' _ -> fromConsensusQueryResultMismatch - QueryStakeDelegDeposits {} -> + QueryStakeDelegDeposits{} -> case q' of - Consensus.GetStakeDelegDeposits {} -> + Consensus.GetStakeDelegDeposits{} -> Map.mapKeysMonotonic fromShelleyStakeCredential r' _ -> fromConsensusQueryResultMismatch - QueryAccountState {} -> + QueryAccountState{} -> case q' of - Consensus.GetAccountState {} -> + Consensus.GetAccountState{} -> r' _ -> fromConsensusQueryResultMismatch - QueryGovState {} -> + QueryGovState{} -> case q' of - Consensus.GetGovState {} -> + Consensus.GetGovState{} -> r' _ -> fromConsensusQueryResultMismatch - QueryDRepState {} -> + QueryDRepState{} -> case q' of - Consensus.GetDRepState {} -> + Consensus.GetDRepState{} -> r' _ -> fromConsensusQueryResultMismatch - QueryDRepStakeDistr {} -> + QueryDRepStakeDistr{} -> case q' of - Consensus.GetDRepStakeDistr {} -> + Consensus.GetDRepStakeDistr{} -> r' _ -> fromConsensusQueryResultMismatch - QueryCommitteeMembersState {} -> + QueryCommitteeMembersState{} -> case q' of - Consensus.GetCommitteeMembersState {} -> + Consensus.GetCommitteeMembersState{} -> r' _ -> fromConsensusQueryResultMismatch - QueryStakeVoteDelegatees {} -> + QueryStakeVoteDelegatees{} -> case q' of - Consensus.GetFilteredVoteDelegatees {} -> + Consensus.GetFilteredVoteDelegatees{} -> Map.mapKeys fromShelleyStakeCredential r' _ -> fromConsensusQueryResultMismatch diff --git a/cardano-api/internal/Cardano/Api/Query/Expr.hs b/cardano-api/internal/Cardano/Api/Query/Expr.hs index 917668721a..9615951f25 100644 --- a/cardano-api/internal/Cardano/Api/Query/Expr.hs +++ b/cardano-api/internal/Cardano/Api/Query/Expr.hs @@ -36,35 +36,37 @@ module Cardano.Api.Query.Expr ) where -import Cardano.Api.Address -import Cardano.Api.Block -import Cardano.Api.Certificate -import Cardano.Api.Eon.BabbageEraOnwards -import Cardano.Api.Eon.ConwayEraOnwards -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras -import Cardano.Api.GenesisParameters -import Cardano.Api.IPC -import Cardano.Api.IPC.Monad -import Cardano.Api.Keys.Shelley -import Cardano.Api.NetworkId -import Cardano.Api.ProtocolParameters -import Cardano.Api.Query +import Cardano.Api.Address +import Cardano.Api.Block +import Cardano.Api.Certificate +import Cardano.Api.Eon.BabbageEraOnwards +import Cardano.Api.Eon.ConwayEraOnwards +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras +import Cardano.Api.GenesisParameters +import Cardano.Api.IPC +import Cardano.Api.IPC.Monad +import Cardano.Api.Keys.Shelley +import Cardano.Api.NetworkId +import Cardano.Api.ProtocolParameters +import Cardano.Api.Query import qualified Cardano.Api.ReexposeLedger as Ledger + import qualified Cardano.Ledger.Api as L import qualified Cardano.Ledger.Api.State.Query as L import qualified Cardano.Ledger.CertState as L import qualified Cardano.Ledger.Coin as L -import Cardano.Ledger.Core (EraCrypto) +import Cardano.Ledger.Core (EraCrypto) import qualified Cardano.Ledger.Credential as L import qualified Cardano.Ledger.Keys as L -import Cardano.Ledger.SafeHash +import Cardano.Ledger.SafeHash import qualified Cardano.Ledger.Shelley.LedgerState as L -import Cardano.Slotting.Slot -import Data.Map (Map) -import Data.Set (Set) +import Cardano.Slotting.Slot +import Ouroboros.Consensus.HardFork.Combinator.AcrossEras as Consensus + +import Data.Map (Map) +import Data.Set (Set) import qualified Data.Set as S -import Ouroboros.Consensus.HardFork.Combinator.AcrossEras as Consensus queryChainBlockNo :: () diff --git a/cardano-api/internal/Cardano/Api/Query/Types.hs b/cardano-api/internal/Cardano/Api/Query/Types.hs index 91c186ad1b..2d250ab84e 100644 --- a/cardano-api/internal/Cardano/Api/Query/Types.hs +++ b/cardano-api/internal/Cardano/Api/Query/Types.hs @@ -8,12 +8,14 @@ module Cardano.Api.Query.Types ) where -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Orphans () -import Cardano.Binary +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Orphans () + +import Cardano.Binary import qualified Cardano.Ledger.Binary.Plain as Plain import qualified Cardano.Ledger.Shelley.API as Shelley -import Data.Aeson (ToJSON (..), object, (.=)) + +import Data.Aeson (ToJSON (..), object, (.=)) import qualified Data.Aeson as Aeson newtype DebugLedgerState era = DebugLedgerState diff --git a/cardano-api/internal/Cardano/Api/ReexposeLedger.hs b/cardano-api/internal/Cardano/Api/ReexposeLedger.hs index f11a3bc38c..717acd0503 100644 --- a/cardano-api/internal/Cardano/Api/ReexposeLedger.hs +++ b/cardano-api/internal/Cardano/Api/ReexposeLedger.hs @@ -141,131 +141,51 @@ module Cardano.Api.ReexposeLedger where import qualified Cardano.Chain.UTxO as Byron -import Cardano.Crypto.Hash.Class (hashFromBytes, hashToBytes) -import Cardano.Ledger.Alonzo.Core (CoinPerWord (..), PParamsUpdate (..), ppPricesL) -import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis) -import Cardano.Ledger.Alonzo.Scripts (CostModels, Prices (..)) -import Cardano.Ledger.Api.Tx.Cert - ( pattern AuthCommitteeHotKeyTxCert - , pattern DelegStakeTxCert - , pattern DelegTxCert - , pattern GenesisDelegTxCert - , pattern MirTxCert - , pattern RegDRepTxCert - , pattern RegDepositDelegTxCert - , pattern RegDepositTxCert - , pattern RegPoolTxCert - , pattern RegTxCert - , pattern ResignCommitteeColdTxCert - , pattern RetirePoolTxCert - , pattern UnRegDRepTxCert - , pattern UnRegDepositTxCert - , pattern UnRegTxCert - ) -import Cardano.Ledger.Babbage.Core (CoinPerByte (..)) -import Cardano.Ledger.BaseTypes - ( AnchorData (..) - , DnsName - , EpochInterval (..) - , Network (..) - , NonNegativeInterval - , ProtVer (..) - , StrictMaybe (..) - , UnitInterval - , Url - , boundRational - , dnsToText - , hashAnchorData - , maybeToStrictMaybe - , mkVersion - , portToWord16 - , strictMaybeToMaybe - , textToDns - , textToUrl - , unboundRational - , urlToText - ) -import Cardano.Ledger.Binary - ( Annotated (..) - , ByteSpan (..) - , byronProtVer - , fromCBOR - , serialize' - , slice - , toCBOR - , toPlainDecoder - ) -import Cardano.Ledger.Binary.Plain (Decoder) -import Cardano.Ledger.CertState (DRepState (..), csCommitteeCredsL) -import Cardano.Ledger.Coin (Coin (..), addDeltaCoin, toDeltaCoin) -import Cardano.Ledger.Conway.Core - ( DRepVotingThresholds (..) - , PoolVotingThresholds (..) - , dvtPPEconomicGroupL - , dvtPPGovGroupL - , dvtPPNetworkGroupL - , dvtPPTechnicalGroupL - , dvtUpdateToConstitutionL - ) -import Cardano.Ledger.Conway.Genesis (ConwayGenesis (..)) -import Cardano.Ledger.Conway.Governance - ( Anchor (..) - , GovActionId (..) - , GovState - , ProposalProcedure (..) - , Vote (..) - , Voter (..) - , VotingProcedure (..) - , VotingProcedures (..) - ) -import Cardano.Ledger.Conway.PParams (UpgradeConwayPParams (..)) -import Cardano.Ledger.Conway.TxCert - ( ConwayDelegCert (..) - , ConwayEraTxCert (..) - , ConwayGovCert (..) - , ConwayTxCert (..) - , Delegatee (..) - , pattern UpdateDRepTxCert - ) -import Cardano.Ledger.Core - ( Era (..) - , EraPParams (..) - , PParams (..) - , PoolCert (..) - , Value - , fromEraCBOR - , ppMinUTxOValueL - , toEraCBOR - ) -import Cardano.Ledger.Credential (Credential (..), credToText) -import Cardano.Ledger.Crypto (ADDRHASH, Crypto, StandardCrypto) -import Cardano.Ledger.DRep (DRep (..), drepAnchorL, drepDepositL, drepExpiryL) -import Cardano.Ledger.Keys - ( HasKeyRole - , KeyHash (..) - , KeyRole (..) - , VKey (..) - , hashWithSerialiser - ) -import Cardano.Ledger.PoolParams (PoolMetadata (..), PoolParams (..), StakePoolRelay (..)) -import Cardano.Ledger.SafeHash (SafeHash, extractHash, unsafeMakeSafeHash) -import Cardano.Ledger.Shelley.API - ( GenDelegPair (..) - , StakeReference (..) - , WitVKey (..) - , hashKey - , hashVerKeyVRF - ) -import Cardano.Ledger.Shelley.Genesis (secondsToNominalDiffTimeMicro) -import Cardano.Ledger.Shelley.LedgerState (PState (..)) -import Cardano.Ledger.Shelley.TxCert - ( EraTxCert (..) - , GenesisDelegCert (..) - , MIRCert (..) - , MIRPot (..) - , MIRTarget (..) - , ShelleyDelegCert (..) - , ShelleyEraTxCert (..) - , ShelleyTxCert (..) - ) -import Cardano.Slotting.Slot (EpochNo (..)) +import Cardano.Crypto.Hash.Class (hashFromBytes, hashToBytes) +import Cardano.Ledger.Alonzo.Core (CoinPerWord (..), PParamsUpdate (..), ppPricesL) +import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis) +import Cardano.Ledger.Alonzo.Scripts (CostModels, Prices (..)) +import Cardano.Ledger.Api.Tx.Cert (pattern AuthCommitteeHotKeyTxCert, + pattern DelegStakeTxCert, pattern DelegTxCert, pattern GenesisDelegTxCert, + pattern MirTxCert, pattern RegDRepTxCert, pattern RegDepositDelegTxCert, + pattern RegDepositTxCert, pattern RegPoolTxCert, pattern RegTxCert, + pattern ResignCommitteeColdTxCert, pattern RetirePoolTxCert, + pattern UnRegDRepTxCert, pattern UnRegDepositTxCert, pattern UnRegTxCert) +import Cardano.Ledger.Babbage.Core (CoinPerByte (..)) +import Cardano.Ledger.BaseTypes (AnchorData (..), DnsName, EpochInterval (..), + Network (..), NonNegativeInterval, ProtVer (..), StrictMaybe (..), UnitInterval, + Url, boundRational, dnsToText, hashAnchorData, maybeToStrictMaybe, mkVersion, + portToWord16, strictMaybeToMaybe, textToDns, textToUrl, unboundRational, + urlToText) +import Cardano.Ledger.Binary (Annotated (..), ByteSpan (..), byronProtVer, fromCBOR, + serialize', slice, toCBOR, toPlainDecoder) +import Cardano.Ledger.Binary.Plain (Decoder) +import Cardano.Ledger.CertState (DRepState (..), csCommitteeCredsL) +import Cardano.Ledger.Coin (Coin (..), addDeltaCoin, toDeltaCoin) +import Cardano.Ledger.Conway.Core (DRepVotingThresholds (..), PoolVotingThresholds (..), + dvtPPEconomicGroupL, dvtPPGovGroupL, dvtPPNetworkGroupL, dvtPPTechnicalGroupL, + dvtUpdateToConstitutionL) +import Cardano.Ledger.Conway.Genesis (ConwayGenesis (..)) +import Cardano.Ledger.Conway.Governance (Anchor (..), GovActionId (..), GovState, + ProposalProcedure (..), Vote (..), Voter (..), VotingProcedure (..), + VotingProcedures (..)) +import Cardano.Ledger.Conway.PParams (UpgradeConwayPParams (..)) +import Cardano.Ledger.Conway.TxCert (ConwayDelegCert (..), ConwayEraTxCert (..), + ConwayGovCert (..), ConwayTxCert (..), Delegatee (..), pattern UpdateDRepTxCert) +import Cardano.Ledger.Core (Era (..), EraPParams (..), PParams (..), PoolCert (..), Value, + fromEraCBOR, ppMinUTxOValueL, toEraCBOR) +import Cardano.Ledger.Credential (Credential (..), credToText) +import Cardano.Ledger.Crypto (ADDRHASH, Crypto, StandardCrypto) +import Cardano.Ledger.DRep (DRep (..), drepAnchorL, drepDepositL, drepExpiryL) +import Cardano.Ledger.Keys (HasKeyRole, KeyHash (..), KeyRole (..), VKey (..), + hashWithSerialiser) +import Cardano.Ledger.PoolParams (PoolMetadata (..), PoolParams (..), StakePoolRelay (..)) +import Cardano.Ledger.SafeHash (SafeHash, extractHash, unsafeMakeSafeHash) +import Cardano.Ledger.Shelley.API (GenDelegPair (..), StakeReference (..), WitVKey (..), + hashKey, hashVerKeyVRF) +import Cardano.Ledger.Shelley.Genesis (secondsToNominalDiffTimeMicro) +import Cardano.Ledger.Shelley.LedgerState (PState (..)) +import Cardano.Ledger.Shelley.TxCert (EraTxCert (..), GenesisDelegCert (..), MIRCert (..), + MIRPot (..), MIRTarget (..), ShelleyDelegCert (..), ShelleyEraTxCert (..), + ShelleyTxCert (..)) +import Cardano.Slotting.Slot (EpochNo (..)) diff --git a/cardano-api/internal/Cardano/Api/ReexposeNetwork.hs b/cardano-api/internal/Cardano/Api/ReexposeNetwork.hs index 6ef494d742..c957abaf80 100644 --- a/cardano-api/internal/Cardano/Api/ReexposeNetwork.hs +++ b/cardano-api/internal/Cardano/Api/ReexposeNetwork.hs @@ -1,3 +1,3 @@ module Cardano.Api.ReexposeNetwork (Target (..)) where -import Ouroboros.Network.Protocol.LocalStateQuery.Type (Target (..)) +import Ouroboros.Network.Protocol.LocalStateQuery.Type (Target (..)) diff --git a/cardano-api/internal/Cardano/Api/Rewards.hs b/cardano-api/internal/Cardano/Api/Rewards.hs index 9fe2cc4128..13ad57c78c 100644 --- a/cardano-api/internal/Cardano/Api/Rewards.hs +++ b/cardano-api/internal/Cardano/Api/Rewards.hs @@ -4,13 +4,15 @@ module Cardano.Api.Rewards ) where -import Cardano.Api.Address -import Cardano.Api.Certificate +import Cardano.Api.Address +import Cardano.Api.Certificate + import qualified Cardano.Ledger.Coin as L -import Data.Aeson as Aeson + +import Data.Aeson as Aeson import qualified Data.Aeson.Types as Aeson -import Data.List (nub) -import Data.Map.Strict (Map) +import Data.List (nub) +import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map import qualified Data.Vector as Vector diff --git a/cardano-api/internal/Cardano/Api/Script.hs b/cardano-api/internal/Cardano/Api/Script.hs index 93768dbfc4..f909b89ebd 100644 --- a/cardano-api/internal/Cardano/Api/Script.hs +++ b/cardano-api/internal/Cardano/Api/Script.hs @@ -111,61 +111,63 @@ module Cardano.Api.Script ) where -import Cardano.Api.Eon.BabbageEraOnwards -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Case -import Cardano.Api.Eras.Core -import Cardano.Api.Error -import Cardano.Api.HasTypeProxy -import Cardano.Api.Hash -import Cardano.Api.Keys.Shelley -import Cardano.Api.ScriptData -import Cardano.Api.SerialiseCBOR -import Cardano.Api.SerialiseJSON -import Cardano.Api.SerialiseRaw -import Cardano.Api.SerialiseTextEnvelope -import Cardano.Api.SerialiseUsing -import Cardano.Api.TxIn -import Cardano.Api.Utils (failEitherWith) +import Cardano.Api.Eon.BabbageEraOnwards +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Case +import Cardano.Api.Eras.Core +import Cardano.Api.Error +import Cardano.Api.Hash +import Cardano.Api.HasTypeProxy +import Cardano.Api.Keys.Shelley +import Cardano.Api.ScriptData +import Cardano.Api.SerialiseCBOR +import Cardano.Api.SerialiseJSON +import Cardano.Api.SerialiseRaw +import Cardano.Api.SerialiseTextEnvelope +import Cardano.Api.SerialiseUsing +import Cardano.Api.TxIn +import Cardano.Api.Utils (failEitherWith) + import qualified Cardano.Binary as CBOR import qualified Cardano.Crypto.Hash.Class as Crypto import qualified Cardano.Ledger.Allegra.Scripts as Allegra import qualified Cardano.Ledger.Allegra.Scripts as Timelock import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo import qualified Cardano.Ledger.Babbage.Scripts as Babbage -import Cardano.Ledger.BaseTypes (StrictMaybe (..)) +import Cardano.Ledger.BaseTypes (StrictMaybe (..)) import qualified Cardano.Ledger.Binary as Binary (decCBOR, decodeFullAnnotator) import qualified Cardano.Ledger.Conway.Scripts as Conway -import Cardano.Ledger.Core (Era (EraCrypto)) +import Cardano.Ledger.Core (Era (EraCrypto)) import qualified Cardano.Ledger.Core as Ledger import qualified Cardano.Ledger.Keys as Shelley import qualified Cardano.Ledger.Plutus.Language as Plutus import qualified Cardano.Ledger.Shelley.Scripts as Shelley -import Cardano.Slotting.Slot (SlotNo) -import Control.Applicative -import Control.Monad -import Data.Aeson (Value (..), object, (.:), (.=)) +import Cardano.Slotting.Slot (SlotNo) +import Ouroboros.Consensus.Shelley.Eras (StandardCrypto) +import qualified PlutusLedgerApi.Test.Examples as Plutus + +import Control.Applicative +import Control.Monad +import Data.Aeson (Value (..), object, (.:), (.=)) import qualified Data.Aeson as Aeson import qualified Data.Aeson.Types as Aeson import qualified Data.ByteString.Lazy as LBS -import Data.ByteString.Short (ShortByteString) +import Data.ByteString.Short (ShortByteString) import qualified Data.ByteString.Short as SBS -import Data.Either.Combinators (maybeToRight) -import Data.Foldable (toList) -import Data.Functor -import Data.Scientific (toBoundedInteger) +import Data.Either.Combinators (maybeToRight) +import Data.Foldable (toList) +import Data.Functor +import Data.Scientific (toBoundedInteger) import qualified Data.Sequence.Strict as Seq -import Data.String (IsString) -import Data.Text (Text) +import Data.String (IsString) +import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Encoding as Text -import Data.Type.Equality (TestEquality (..), (:~:) (Refl)) -import Data.Typeable (Typeable) -import Data.Vector (Vector) +import Data.Type.Equality (TestEquality (..), (:~:) (Refl)) +import Data.Typeable (Typeable) +import Data.Vector (Vector) import qualified Data.Vector as Vector -import Numeric.Natural (Natural) -import Ouroboros.Consensus.Shelley.Eras (StandardCrypto) -import qualified PlutusLedgerApi.Test.Examples as Plutus +import Numeric.Natural (Natural) -- ---------------------------------------------------------------------------- -- Types for script language and version @@ -859,7 +861,7 @@ data ExecutionUnits deriving (Eq, Show) instance ToCBOR ExecutionUnits where - toCBOR ExecutionUnits {executionSteps, executionMemory} = + toCBOR ExecutionUnits{executionSteps, executionMemory} = CBOR.encodeListLen 2 <> toCBOR executionSteps <> toCBOR executionMemory @@ -872,7 +874,7 @@ instance FromCBOR ExecutionUnits where <*> fromCBOR instance ToJSON ExecutionUnits where - toJSON ExecutionUnits {executionSteps, executionMemory} = + toJSON ExecutionUnits{executionSteps, executionMemory} = object [ "steps" .= executionSteps , "memory" .= executionMemory @@ -886,14 +888,14 @@ instance FromJSON ExecutionUnits where <*> o .: "memory" toAlonzoExUnits :: ExecutionUnits -> Alonzo.ExUnits -toAlonzoExUnits ExecutionUnits {executionSteps, executionMemory} = +toAlonzoExUnits ExecutionUnits{executionSteps, executionMemory} = Alonzo.ExUnits { Alonzo.exUnitsSteps = executionSteps , Alonzo.exUnitsMem = executionMemory } fromAlonzoExUnits :: Alonzo.ExUnits -> ExecutionUnits -fromAlonzoExUnits Alonzo.ExUnits {Alonzo.exUnitsSteps, Alonzo.exUnitsMem} = +fromAlonzoExUnits Alonzo.ExUnits{Alonzo.exUnitsSteps, Alonzo.exUnitsMem} = ExecutionUnits { executionSteps = exUnitsSteps , executionMemory = exUnitsMem @@ -995,11 +997,11 @@ data SimpleScript data PlutusScript lang where PlutusScriptSerialised :: ShortByteString -> PlutusScript lang deriving stock (Eq, Ord) - deriving stock (Show) -- TODO: would be nice to use via UsingRawBytesHex + deriving stock Show -- TODO: would be nice to use via UsingRawBytesHex -- however that adds an awkward HasTypeProxy lang => -- constraint to other Show instances elsewhere deriving (ToCBOR, FromCBOR) via (UsingRawBytes (PlutusScript lang)) - deriving anyclass (SerialiseAsCBOR) + deriving anyclass SerialiseAsCBOR instance HasTypeProxy lang => HasTypeProxy (PlutusScript lang) where data AsType (PlutusScript lang) = AsPlutusScript (AsType lang) @@ -1178,7 +1180,7 @@ fromShelleyBasedScript sbe script = . SimpleScript $ fromAllegraTimelock s -data MultiSigError = MultiSigErrorTimelockNotsupported deriving (Show) +data MultiSigError = MultiSigErrorTimelockNotsupported deriving Show -- | Conversion for the 'Shelley.MultiSig' language used by the Shelley era. toShelleyMultiSig diff --git a/cardano-api/internal/Cardano/Api/ScriptData.hs b/cardano-api/internal/Cardano/Api/ScriptData.hs index 584e0588fb..08844dafaf 100644 --- a/cardano-api/internal/Cardano/Api/ScriptData.hs +++ b/cardano-api/internal/Cardano/Api/ScriptData.hs @@ -44,50 +44,52 @@ module Cardano.Api.ScriptData ) where -import Cardano.Api.Eras -import Cardano.Api.Error -import Cardano.Api.HasTypeProxy -import Cardano.Api.Hash -import Cardano.Api.Keys.Shelley -import Cardano.Api.Pretty -import Cardano.Api.SerialiseCBOR -import Cardano.Api.SerialiseJSON -import Cardano.Api.SerialiseRaw -import Cardano.Api.SerialiseUsing -import Cardano.Api.TxMetadata (pBytes, pSigned, parseAll) +import Cardano.Api.Eras +import Cardano.Api.Error +import Cardano.Api.Hash +import Cardano.Api.HasTypeProxy +import Cardano.Api.Keys.Shelley +import Cardano.Api.Pretty +import Cardano.Api.SerialiseCBOR +import Cardano.Api.SerialiseJSON +import Cardano.Api.SerialiseRaw +import Cardano.Api.SerialiseUsing +import Cardano.Api.TxMetadata (pBytes, pSigned, parseAll) + import qualified Cardano.Binary as CBOR import qualified Cardano.Crypto.Hash.Class as Crypto -import Cardano.Ledger.Core (Era) +import Cardano.Ledger.Core (Era) import qualified Cardano.Ledger.Plutus.Data as Plutus import qualified Cardano.Ledger.SafeHash as Ledger -import Codec.Serialise.Class (Serialise (..)) -import Control.Applicative (Alternative (..)) +import Ouroboros.Consensus.Shelley.Eras (StandardAlonzo, StandardCrypto) +import qualified PlutusLedgerApi.V1 as PlutusAPI + +import Codec.Serialise.Class (Serialise (..)) +import Control.Applicative (Alternative (..)) import qualified Data.Aeson as Aeson import qualified Data.Aeson.Key as Aeson import qualified Data.Aeson.KeyMap as KeyMap import qualified Data.Aeson.Text as Aeson.Text import qualified Data.Attoparsec.ByteString.Char8 as Atto -import Data.Bifunctor (first) +import Data.Bifunctor (first) import qualified Data.ByteString as BS import qualified Data.ByteString.Base16 as Base16 import qualified Data.ByteString.Char8 as BSC import qualified Data.ByteString.Lazy.Char8 as LBS import qualified Data.ByteString.Short as SB import qualified Data.Char as Char -import Data.Data (Data) -import Data.Either.Combinators +import Data.Data (Data) +import Data.Either.Combinators import qualified Data.List as List -import Data.Maybe (fromMaybe) +import Data.Maybe (fromMaybe) import qualified Data.Scientific as Scientific -import Data.String (IsString) -import Data.Text (Text) +import Data.String (IsString) +import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Encoding as Text import qualified Data.Text.Lazy as Text.Lazy import qualified Data.Vector as Vector -import Data.Word -import Ouroboros.Consensus.Shelley.Eras (StandardAlonzo, StandardCrypto) -import qualified PlutusLedgerApi.V1 as PlutusAPI +import Data.Word -- Original script data bytes data HashableScriptData @@ -188,7 +190,7 @@ hashScriptDataBytes = -- Conversion functions -- -newtype ScriptBytesError = ScriptBytesError String deriving (Show) +newtype ScriptBytesError = ScriptBytesError String deriving Show -- There is a subtlety here. We must use the original bytes -- when converting to and from `HashableScriptData`/`Data`. This @@ -439,7 +441,7 @@ scriptDataFromJsonNoSchema = fmap (\sd -> HashableScriptData (serialiseToCBOR sd :: Aeson.Value -> Either ScriptDataJsonSchemaError ScriptData conv Aeson.Null = Left ScriptDataJsonNullNotAllowed - conv Aeson.Bool {} = Left ScriptDataJsonBoolNotAllowed + conv Aeson.Bool{} = Left ScriptDataJsonBoolNotAllowed conv (Aeson.Number d) = case Scientific.floatingOrInteger d :: Either Double Integer of Left n -> Left (ScriptDataJsonNumberNotInteger n) diff --git a/cardano-api/internal/Cardano/Api/SerialiseBech32.hs b/cardano-api/internal/Cardano/Api/SerialiseBech32.hs index 0d2b770888..0c3d460ed7 100644 --- a/cardano-api/internal/Cardano/Api/SerialiseBech32.hs +++ b/cardano-api/internal/Cardano/Api/SerialiseBech32.hs @@ -13,20 +13,21 @@ module Cardano.Api.SerialiseBech32 ) where -import Cardano.Api.Error -import Cardano.Api.HasTypeProxy -import Cardano.Api.Orphans () -import Cardano.Api.Pretty -import Cardano.Api.SerialiseRaw -import Cardano.Api.Utils +import Cardano.Api.Error +import Cardano.Api.HasTypeProxy +import Cardano.Api.Orphans () +import Cardano.Api.Pretty +import Cardano.Api.SerialiseRaw +import Cardano.Api.Utils + import qualified Codec.Binary.Bech32 as Bech32 -import Control.Monad (guard) -import Data.ByteString (ByteString) -import Data.Data (Data) +import Control.Monad (guard) +import Data.ByteString (ByteString) +import Data.Data (Data) import qualified Data.List as List -import Data.Set (Set) +import Data.Set (Set) import qualified Data.Set as Set -import Data.Text (Text) +import Data.Text (Text) class (HasTypeProxy a, SerialiseAsRawBytes a) => SerialiseAsBech32 a where -- | The human readable prefix to use when encoding this value to Bech32. diff --git a/cardano-api/internal/Cardano/Api/SerialiseCBOR.hs b/cardano-api/internal/Cardano/Api/SerialiseCBOR.hs index 654c45e19d..77bba956a4 100644 --- a/cardano-api/internal/Cardano/Api/SerialiseCBOR.hs +++ b/cardano-api/internal/Cardano/Api/SerialiseCBOR.hs @@ -8,10 +8,12 @@ module Cardano.Api.SerialiseCBOR ) where -import Cardano.Api.HasTypeProxy -import Cardano.Binary (FromCBOR, ToCBOR) +import Cardano.Api.HasTypeProxy + +import Cardano.Binary (FromCBOR, ToCBOR) import qualified Cardano.Binary as CBOR -import Data.ByteString (ByteString) + +import Data.ByteString (ByteString) class HasTypeProxy a => SerialiseAsCBOR a where serialiseToCBOR :: a -> ByteString diff --git a/cardano-api/internal/Cardano/Api/SerialiseJSON.hs b/cardano-api/internal/Cardano/Api/SerialiseJSON.hs index 7a95b0afb1..1abba7f2ed 100644 --- a/cardano-api/internal/Cardano/Api/SerialiseJSON.hs +++ b/cardano-api/internal/Cardano/Api/SerialiseJSON.hs @@ -15,18 +15,19 @@ module Cardano.Api.SerialiseJSON ) where -import Cardano.Api.Error -import Cardano.Api.HasTypeProxy -import Cardano.Api.Pretty -import Control.Monad.Trans.Except (runExceptT) -import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT, hoistEither) -import Data.Aeson (FromJSON (..), FromJSONKey, ToJSON (..), ToJSONKey) +import Cardano.Api.Error +import Cardano.Api.HasTypeProxy +import Cardano.Api.Pretty + +import Control.Monad.Trans.Except (runExceptT) +import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT, hoistEither) +import Data.Aeson (FromJSON (..), FromJSONKey, ToJSON (..), ToJSONKey) import qualified Data.Aeson as Aeson -import Data.Aeson.Encode.Pretty (encodePretty) -import Data.ByteString (ByteString) +import Data.Aeson.Encode.Pretty (encodePretty) +import Data.ByteString (ByteString) import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as LBS -import Data.Data (Data) +import Data.Data (Data) newtype JsonDecodeError = JsonDecodeError String deriving (Eq, Show, Data) diff --git a/cardano-api/internal/Cardano/Api/SerialiseLedgerCddl.hs b/cardano-api/internal/Cardano/Api/SerialiseLedgerCddl.hs index b52b93c606..d559e51af4 100644 --- a/cardano-api/internal/Cardano/Api/SerialiseLedgerCddl.hs +++ b/cardano-api/internal/Cardano/Api/SerialiseLedgerCddl.hs @@ -33,41 +33,33 @@ module Cardano.Api.SerialiseLedgerCddl ) where -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Error -import Cardano.Api.HasTypeProxy -import Cardano.Api.IO -import Cardano.Api.Pretty -import Cardano.Api.SerialiseTextEnvelope - ( TextEnvelope (..) - , TextEnvelopeDescr (TextEnvelopeDescr) - , TextEnvelopeError (..) - , TextEnvelopeType (TextEnvelopeType) - , deserialiseFromTextEnvelope - , legacyComparison - , serialiseToTextEnvelope - ) -import Cardano.Api.Tx.Sign -import Cardano.Api.Utils +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Error +import Cardano.Api.HasTypeProxy +import Cardano.Api.IO +import Cardano.Api.Pretty +import Cardano.Api.SerialiseTextEnvelope (TextEnvelope (..), + TextEnvelopeDescr (TextEnvelopeDescr), TextEnvelopeError (..), + TextEnvelopeType (TextEnvelopeType), deserialiseFromTextEnvelope, + legacyComparison, serialiseToTextEnvelope) +import Cardano.Api.Tx.Sign +import Cardano.Api.Utils + import qualified Cardano.Chain.UTxO as Byron -import Cardano.Ledger.Binary (DecoderError) +import Cardano.Ledger.Binary (DecoderError) import qualified Cardano.Ledger.Binary as CBOR -import Control.Monad.Trans.Except.Extra - ( firstExceptT - , handleIOExceptT - , hoistEither - , newExceptT - , runExceptT - ) + +import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT, hoistEither, + newExceptT, runExceptT) import qualified Data.Aeson as Aeson -import Data.Aeson.Encode.Pretty (Config (..), defConfig, encodePretty', keyOrder) -import Data.Bifunctor (first) -import Data.ByteString (ByteString) +import Data.Aeson.Encode.Pretty (Config (..), defConfig, encodePretty', keyOrder) +import Data.Bifunctor (first) +import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as LBS -import Data.Data (Data) -import Data.Either.Combinators (mapLeft) +import Data.Data (Data) +import Data.Either.Combinators (mapLeft) import qualified Data.List as List -import Data.Text (Text) +import Data.Text (Text) import qualified Data.Text as T -- Why have we gone this route? The serialization format of `TxBody era` @@ -202,9 +194,9 @@ serialiseWitnessLedgerCddl sbe kw = serialiseToTextEnvelope (Just (TextEnvelopeDescr $ T.unpack $ genDesc kw)) kw where genDesc :: KeyWitness era -> Text - genDesc ByronKeyWitness {} = case sbe of {} - genDesc ShelleyBootstrapWitness {} = "Key BootstrapWitness ShelleyEra" - genDesc ShelleyKeyWitness {} = "Key Witness ShelleyEra" + genDesc ByronKeyWitness{} = case sbe of {} + genDesc ShelleyBootstrapWitness{} = "Key BootstrapWitness ShelleyEra" + genDesc ShelleyKeyWitness{} = "Key Witness ShelleyEra" deserialiseWitnessLedgerCddl :: forall era @@ -226,7 +218,7 @@ deserialiseWitnessLedgerCddl sbe te = :: TextEnvelope -> Either TextEnvelopeCddlError (KeyWitness era) -> Either TextEnvelopeCddlError (KeyWitness era) - legacyDecoding TextEnvelope {teDescription, teRawCBOR} (Left (TextEnvelopeCddlErrCBORDecodingError _)) = + legacyDecoding TextEnvelope{teDescription, teRawCBOR} (Left (TextEnvelopeCddlErrCBORDecodingError _)) = case teDescription of "Key BootstrapWitness ShelleyEra" -> do w <- @@ -274,7 +266,7 @@ writeTxWitnessFileTextEnvelopeCddl sbe path w = textEnvelopeCddlJSONConfig :: Config textEnvelopeCddlJSONConfig = - defConfig {confCompare = textEnvelopeCddlJSONKeyOrder} + defConfig{confCompare = textEnvelopeCddlJSONKeyOrder} textEnvelopeCddlJSONKeyOrder :: Text -> Text -> Ordering textEnvelopeCddlJSONKeyOrder = keyOrder ["type", "description", "cborHex"] diff --git a/cardano-api/internal/Cardano/Api/SerialiseRaw.hs b/cardano-api/internal/Cardano/Api/SerialiseRaw.hs index f58b39e8db..b00a1df016 100644 --- a/cardano-api/internal/Cardano/Api/SerialiseRaw.hs +++ b/cardano-api/internal/Cardano/Api/SerialiseRaw.hs @@ -13,17 +13,18 @@ module Cardano.Api.SerialiseRaw ) where -import Cardano.Api.Error (Error, prettyError) -import Cardano.Api.HasTypeProxy -import Cardano.Api.Pretty -import Data.Bifunctor (Bifunctor (..)) -import Data.ByteString (ByteString) +import Cardano.Api.Error (Error, prettyError) +import Cardano.Api.HasTypeProxy +import Cardano.Api.Pretty + +import Data.Bifunctor (Bifunctor (..)) +import Data.ByteString (ByteString) import qualified Data.ByteString.Base16 as Base16 -import Data.Data (typeRep) -import Data.Text (Text) +import Data.Data (typeRep) +import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Encoding as Text -import Data.Typeable (TypeRep, Typeable) +import Data.Typeable (TypeRep, Typeable) newtype SerialiseAsRawBytesError = SerialiseAsRawBytesError -- TODO We can do better than use String to carry the error message @@ -56,7 +57,7 @@ data RawBytesHexError -- ^ expected type SerialiseAsRawBytesError -- ^ error message - deriving (Show) + deriving Show instance Error RawBytesHexError where prettyError = \case diff --git a/cardano-api/internal/Cardano/Api/SerialiseTextEnvelope.hs b/cardano-api/internal/Cardano/Api/SerialiseTextEnvelope.hs index 650d6d6146..a7e035ef8d 100644 --- a/cardano-api/internal/Cardano/Api/SerialiseTextEnvelope.hs +++ b/cardano-api/internal/Cardano/Api/SerialiseTextEnvelope.hs @@ -37,30 +37,32 @@ module Cardano.Api.SerialiseTextEnvelope ) where -import Cardano.Api.Eras -import Cardano.Api.Error -import Cardano.Api.HasTypeProxy -import Cardano.Api.IO -import Cardano.Api.Orphans () -import Cardano.Api.Pretty -import Cardano.Api.SerialiseCBOR -import Cardano.Api.Utils (readFileBlocking) -import Cardano.Binary (DecoderError) -import Control.Monad (unless) -import Control.Monad.Trans.Except (ExceptT (..), runExceptT) -import Control.Monad.Trans.Except.Extra (firstExceptT, hoistEither) -import Data.Aeson (FromJSON (..), ToJSON (..), object, withObject, (.:), (.=)) +import Cardano.Api.Eras +import Cardano.Api.Error +import Cardano.Api.HasTypeProxy +import Cardano.Api.IO +import Cardano.Api.Orphans () +import Cardano.Api.Pretty +import Cardano.Api.SerialiseCBOR +import Cardano.Api.Utils (readFileBlocking) + +import Cardano.Binary (DecoderError) + +import Control.Monad (unless) +import Control.Monad.Trans.Except (ExceptT (..), runExceptT) +import Control.Monad.Trans.Except.Extra (firstExceptT, hoistEither) +import Data.Aeson (FromJSON (..), ToJSON (..), object, withObject, (.:), (.=)) import qualified Data.Aeson as Aeson -import Data.Aeson.Encode.Pretty (Config (..), defConfig, encodePretty', keyOrder) -import Data.Bifunctor (first) -import Data.ByteString (ByteString) +import Data.Aeson.Encode.Pretty (Config (..), defConfig, encodePretty', keyOrder) +import Data.Bifunctor (first) +import Data.ByteString (ByteString) import qualified Data.ByteString.Base16 as Base16 import qualified Data.ByteString.Lazy as LBS -import Data.Data (Data) +import Data.Data (Data) import qualified Data.List as List -import Data.Maybe (fromMaybe) -import Data.String (IsString) -import Data.Text (Text) +import Data.Maybe (fromMaybe) +import Data.String (IsString) +import Data.Text (Text) import qualified Data.Text.Encoding as Text -- ---------------------------------------------------------------------------- @@ -96,7 +98,7 @@ instance HasTypeProxy TextEnvelope where proxyToAsType _ = AsTextEnvelope instance ToJSON TextEnvelope where - toJSON TextEnvelope {teType, teDescription, teRawCBOR} = + toJSON TextEnvelope{teType, teDescription, teRawCBOR} = object [ "type" .= teType , "description" .= teDescription @@ -114,7 +116,7 @@ instance FromJSON TextEnvelope where either fail return . Base16.decode . Text.encodeUtf8 =<< parseJSON v textEnvelopeJSONConfig :: Config -textEnvelopeJSONConfig = defConfig {confCompare = textEnvelopeJSONKeyOrder} +textEnvelopeJSONConfig = defConfig{confCompare = textEnvelopeJSONKeyOrder} textEnvelopeJSONKeyOrder :: Text -> Text -> Ordering textEnvelopeJSONKeyOrder = keyOrder ["type", "description", "cborHex"] @@ -154,7 +156,7 @@ instance Error TextEnvelopeError where -- -- For example, one might check that the type is \"TxSignedShelley\". expectTextEnvelopeOfType :: TextEnvelopeType -> TextEnvelope -> Either TextEnvelopeError () -expectTextEnvelopeOfType expectedType TextEnvelope {teType = actualType} = +expectTextEnvelopeOfType expectedType TextEnvelope{teType = actualType} = unless (expectedType `legacyComparison` actualType) $ Left (TextEnvelopeTypeError [expectedType] actualType) diff --git a/cardano-api/internal/Cardano/Api/SerialiseUsing.hs b/cardano-api/internal/Cardano/Api/SerialiseUsing.hs index 1bd3d8f26f..ba5b16520e 100644 --- a/cardano-api/internal/Cardano/Api/SerialiseUsing.hs +++ b/cardano-api/internal/Cardano/Api/SerialiseUsing.hs @@ -8,21 +8,22 @@ module Cardano.Api.SerialiseUsing ) where -import Cardano.Api.Error -import Cardano.Api.HasTypeProxy -import Cardano.Api.Pretty -import Cardano.Api.SerialiseBech32 -import Cardano.Api.SerialiseCBOR -import Cardano.Api.SerialiseJSON -import Cardano.Api.SerialiseRaw +import Cardano.Api.Error +import Cardano.Api.HasTypeProxy +import Cardano.Api.Pretty +import Cardano.Api.SerialiseBech32 +import Cardano.Api.SerialiseCBOR +import Cardano.Api.SerialiseJSON +import Cardano.Api.SerialiseRaw + import qualified Data.Aeson.Types as Aeson -import Data.ByteString (ByteString) +import Data.ByteString (ByteString) import qualified Data.ByteString.Base16 as Base16 import qualified Data.ByteString.Char8 as BSC -import Data.String (IsString (..)) +import Data.String (IsString (..)) import qualified Data.Text as Text import qualified Data.Text.Encoding as Text -import Data.Typeable (tyConName, typeRep, typeRepTyCon) +import Data.Typeable (tyConName, typeRep, typeRepTyCon) -- | For use with @deriving via@, to provide 'ToCBOR' and 'FromCBOR' instances, -- based on the 'SerialiseAsRawBytes' instance. diff --git a/cardano-api/internal/Cardano/Api/SpecialByron.hs b/cardano-api/internal/Cardano/Api/SpecialByron.hs index 8493000d19..c73d9bacbf 100644 --- a/cardano-api/internal/Cardano/Api/SpecialByron.hs +++ b/cardano-api/internal/Cardano/Api/SpecialByron.hs @@ -18,46 +18,31 @@ module Cardano.Api.SpecialByron ) where -import Cardano.Api.HasTypeProxy -import Cardano.Api.Keys.Byron -import Cardano.Api.NetworkId (NetworkId, toByronProtocolMagicId) -import Cardano.Api.SerialiseRaw +import Cardano.Api.HasTypeProxy +import Cardano.Api.Keys.Byron +import Cardano.Api.NetworkId (NetworkId, toByronProtocolMagicId) +import Cardano.Api.SerialiseRaw + import qualified Cardano.Binary as Binary -import Cardano.Chain.Common (LovelacePortion, TxFeePolicy) -import Cardano.Chain.Slotting -import Cardano.Chain.Update - ( AProposal (aBody, annotation) - , InstallerHash - , ProposalBody (ProposalBody) - , ProtocolParametersUpdate (..) - , ProtocolVersion - , SoftforkRule - , SoftwareVersion - , SystemTag - , UpId - , mkVote - , recoverUpId - , recoverVoteId - , signProposal - ) +import Cardano.Chain.Common (LovelacePortion, TxFeePolicy) +import Cardano.Chain.Slotting +import Cardano.Chain.Update (AProposal (aBody, annotation), InstallerHash, + ProposalBody (ProposalBody), ProtocolParametersUpdate (..), ProtocolVersion, + SoftforkRule, SoftwareVersion, SystemTag, UpId, mkVote, recoverUpId, + recoverVoteId, signProposal) import qualified Cardano.Chain.Update as Update import qualified Cardano.Chain.Update.Vote as ByronVote -import Cardano.Crypto (SafeSigner, noPassSafeSigner) -import qualified Cardano.Ledger.Binary as Binary - ( Annotated (..) - , ByteSpan (..) - , annotation - , annotationBytes - , byronProtVer - , reAnnotate - ) -import Data.ByteString (ByteString) +import Cardano.Crypto (SafeSigner, noPassSafeSigner) +import qualified Cardano.Ledger.Binary as Binary (Annotated (..), ByteSpan (..), annotation, + annotationBytes, byronProtVer, reAnnotate) +import Ouroboros.Consensus.Byron.Ledger.Block (ByronBlock) +import qualified Ouroboros.Consensus.Byron.Ledger.Mempool as Mempool + +import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as LB import qualified Data.Map.Strict as M -import Data.Word -import Numeric.Natural -import Ouroboros.Consensus.Byron.Ledger.Block (ByronBlock) -import qualified Ouroboros.Consensus.Byron.Ledger.Mempool as Mempool +import Data.Word +import Numeric.Natural {- HLINT ignore "Use void" -} @@ -155,7 +140,7 @@ data ByronProtocolParametersUpdate -- ^ This has been re-purposed for unlocking the OuroborosBFT logic in the software. -- Relevant: [CDEC-610](https://iohk.myjetbrains.com/youtrack/issue/CDEC-610) } - deriving (Show) + deriving Show makeProtocolParametersUpdate :: ByronProtocolParametersUpdate diff --git a/cardano-api/internal/Cardano/Api/StakePoolMetadata.hs b/cardano-api/internal/Cardano/Api/StakePoolMetadata.hs index a572294f98..57301b4583 100644 --- a/cardano-api/internal/Cardano/Api/StakePoolMetadata.hs +++ b/cardano-api/internal/Cardano/Api/StakePoolMetadata.hs @@ -16,29 +16,31 @@ module Cardano.Api.StakePoolMetadata ) where -import Cardano.Api.Eras -import Cardano.Api.Error -import Cardano.Api.HasTypeProxy -import Cardano.Api.Hash -import Cardano.Api.Keys.Byron -import Cardano.Api.Keys.Praos -import Cardano.Api.Script -import Cardano.Api.SerialiseJSON -import Cardano.Api.SerialiseRaw +import Cardano.Api.Eras +import Cardano.Api.Error +import Cardano.Api.Hash +import Cardano.Api.HasTypeProxy +import Cardano.Api.Keys.Byron +import Cardano.Api.Keys.Praos +import Cardano.Api.Script +import Cardano.Api.SerialiseJSON +import Cardano.Api.SerialiseRaw + import qualified Cardano.Crypto.Hash.Class as Crypto -import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Crypto (StandardCrypto) import qualified Cardano.Ledger.Keys as Shelley -import Data.Aeson ((.:)) + +import Data.Aeson ((.:)) import qualified Data.Aeson as Aeson import qualified Data.Aeson.Types as Aeson -import Data.Bifunctor (first) -import Data.ByteString (ByteString) +import Data.Bifunctor (first) +import Data.ByteString (ByteString) import qualified Data.ByteString as BS -import Data.Data (Data) -import Data.Either.Combinators (maybeToRight) -import Data.Text (Text) +import Data.Data (Data) +import Data.Either.Combinators (maybeToRight) +import Data.Text (Text) import qualified Data.Text as Text -import Prettyprinter +import Prettyprinter -- ---------------------------------------------------------------------------- -- Stake pool metadata diff --git a/cardano-api/internal/Cardano/Api/Tx/Body.hs b/cardano-api/internal/Cardano/Api/Tx/Body.hs index 6278a238da..30bb07d0c0 100644 --- a/cardano-api/internal/Cardano/Api/Tx/Body.hs +++ b/cardano-api/internal/Cardano/Api/Tx/Body.hs @@ -161,38 +161,39 @@ module Cardano.Api.Tx.Body ) where -import Cardano.Api.Address -import Cardano.Api.Certificate -import Cardano.Api.Eon.AllegraEraOnwards -import Cardano.Api.Eon.AlonzoEraOnwards -import Cardano.Api.Eon.BabbageEraOnwards -import Cardano.Api.Eon.ConwayEraOnwards -import Cardano.Api.Eon.MaryEraOnwards -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eon.ShelleyToAllegraEra -import Cardano.Api.Eon.ShelleyToBabbageEra -import Cardano.Api.Eras.Case -import Cardano.Api.Eras.Core -import Cardano.Api.Error (Error (..), displayError) -import Cardano.Api.Feature -import Cardano.Api.Hash -import Cardano.Api.Keys.Byron -import Cardano.Api.Keys.Shelley +import Cardano.Api.Address +import Cardano.Api.Certificate +import Cardano.Api.Eon.AllegraEraOnwards +import Cardano.Api.Eon.AlonzoEraOnwards +import Cardano.Api.Eon.BabbageEraOnwards +import Cardano.Api.Eon.ConwayEraOnwards +import Cardano.Api.Eon.MaryEraOnwards +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eon.ShelleyToAllegraEra +import Cardano.Api.Eon.ShelleyToBabbageEra +import Cardano.Api.Eras.Case +import Cardano.Api.Eras.Core +import Cardano.Api.Error (Error (..), displayError) +import Cardano.Api.Feature +import Cardano.Api.Hash +import Cardano.Api.Keys.Byron +import Cardano.Api.Keys.Shelley import qualified Cardano.Api.Ledger.Lens as A -import Cardano.Api.NetworkId -import Cardano.Api.Pretty -import Cardano.Api.ProtocolParameters +import Cardano.Api.NetworkId +import Cardano.Api.Pretty +import Cardano.Api.ProtocolParameters import qualified Cardano.Api.ReexposeLedger as Ledger -import Cardano.Api.Script -import Cardano.Api.ScriptData -import Cardano.Api.SerialiseJSON -import Cardano.Api.SerialiseRaw -import Cardano.Api.Tx.Sign -import Cardano.Api.TxIn -import Cardano.Api.TxMetadata -import Cardano.Api.Utils -import Cardano.Api.Value -import Cardano.Api.ValueParser +import Cardano.Api.Script +import Cardano.Api.ScriptData +import Cardano.Api.SerialiseJSON +import Cardano.Api.SerialiseRaw +import Cardano.Api.Tx.Sign +import Cardano.Api.TxIn +import Cardano.Api.TxMetadata +import Cardano.Api.Utils +import Cardano.Api.Value +import Cardano.Api.ValueParser + import qualified Cardano.Chain.Common as Byron import qualified Cardano.Chain.UTxO as Byron import qualified Cardano.Crypto.Hash.Class as Crypto @@ -204,18 +205,18 @@ import qualified Cardano.Ledger.Alonzo.Tx as Alonzo (hashScriptIntegrity) import qualified Cardano.Ledger.Alonzo.TxWits as Alonzo import qualified Cardano.Ledger.Api as L import qualified Cardano.Ledger.Babbage.UTxO as L -import Cardano.Ledger.BaseTypes (StrictMaybe (..)) -import Cardano.Ledger.Binary (Annotated (..)) +import Cardano.Ledger.BaseTypes (StrictMaybe (..)) +import Cardano.Ledger.Binary (Annotated (..)) import qualified Cardano.Ledger.Binary as CBOR import qualified Cardano.Ledger.Coin as L import qualified Cardano.Ledger.Conway.Core as L -import Cardano.Ledger.Core () +import Cardano.Ledger.Core () import qualified Cardano.Ledger.Core as Core import qualified Cardano.Ledger.Core as Ledger import qualified Cardano.Ledger.Credential as Shelley -import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Crypto (StandardCrypto) import qualified Cardano.Ledger.Keys as Shelley -import Cardano.Ledger.Mary.Value as L (MaryValue (..), MultiAsset) +import Cardano.Ledger.Mary.Value as L (MaryValue (..), MultiAsset) import qualified Cardano.Ledger.Plutus.Data as Plutus import qualified Cardano.Ledger.Plutus.Language as Plutus import qualified Cardano.Ledger.SafeHash as SafeHash @@ -223,51 +224,46 @@ import qualified Cardano.Ledger.Shelley.API as Ledger import qualified Cardano.Ledger.Shelley.Genesis as Shelley import qualified Cardano.Ledger.Shelley.TxCert as Shelley import qualified Cardano.Ledger.TxIn as L -import Cardano.Ledger.Val as L (isZero) -import Cardano.Slotting.Slot (SlotNo (..)) -import Control.Applicative (some) -import Control.Monad (guard, unless) -import Data.Aeson (object, withObject, (.:), (.:?), (.=)) +import Cardano.Ledger.Val as L (isZero) +import Cardano.Slotting.Slot (SlotNo (..)) +import Ouroboros.Consensus.Shelley.Eras (StandardAllegra, StandardAlonzo, StandardBabbage, + StandardConway, StandardMary, StandardShelley) + +import Control.Applicative (some) +import Control.Monad (guard, unless) +import Data.Aeson (object, withObject, (.:), (.:?), (.=)) import qualified Data.Aeson as Aeson import qualified Data.Aeson.Key as Aeson import qualified Data.Aeson.KeyMap as KeyMap import qualified Data.Aeson.Types as Aeson -import Data.Bifunctor (Bifunctor (..)) -import Data.ByteString (ByteString) +import Data.Bifunctor (Bifunctor (..)) +import Data.ByteString (ByteString) import qualified Data.ByteString.Char8 as BSC -import Data.Foldable (for_, toList) -import Data.Function (on) -import Data.Functor (($>)) -import Data.List (sortBy) +import Data.Foldable (for_, toList) +import Data.Function (on) +import Data.Functor (($>)) +import Data.List (sortBy) import qualified Data.List as List import qualified Data.List.NonEmpty as NonEmpty -import Data.Map.Strict (Map) +import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map -import Data.Maybe -import Data.Monoid -import Data.OSet.Strict (OSet) +import Data.Maybe +import Data.Monoid +import Data.OSet.Strict (OSet) import qualified Data.OSet.Strict as OSet -import Data.Scientific (toBoundedInteger) +import Data.Scientific (toBoundedInteger) import qualified Data.Sequence.Strict as Seq -import Data.Set (Set) +import Data.Set (Set) import qualified Data.Set as Set -import Data.String -import Data.Text (Text) +import Data.String +import Data.Text (Text) import qualified Data.Text as Text -import Data.Type.Equality (TestEquality (..), (:~:) (Refl)) -import Data.Word (Word16, Word32, Word64) -import Lens.Micro hiding (ix) -import Lens.Micro.Extras (view) -import Ouroboros.Consensus.Shelley.Eras - ( StandardAllegra - , StandardAlonzo - , StandardBabbage - , StandardConway - , StandardMary - , StandardShelley - ) -import Text.Parsec (()) +import Data.Type.Equality (TestEquality (..), (:~:) (Refl)) +import Data.Word (Word16, Word32, Word64) +import Lens.Micro hiding (ix) +import Lens.Micro.Extras (view) import qualified Text.Parsec as Parsec +import Text.Parsec (()) import qualified Text.Parsec.String as Parsec -- ---------------------------------------------------------------------------- @@ -380,8 +376,8 @@ txOutToJsonValue era (TxOut addr val dat refScript) = inlineDatumJsonVal d = case d of TxOutDatumNone -> Aeson.Null - TxOutDatumHash {} -> Aeson.Null - TxOutDatumInTx' {} -> Aeson.Null + TxOutDatumHash{} -> Aeson.Null + TxOutDatumInTx'{} -> Aeson.Null TxOutDatumInline _ datum -> scriptDataToJson ScriptDataJsonDetailedSchema datum refScriptJsonVal :: ReferenceScript era -> Aeson.Value @@ -680,7 +676,7 @@ toByronTxOut = \case Byron.TxOut addr <$> toByronLovelace value TxOut (AddressInEra ByronAddressInAnyEra (ByronAddress _)) (TxOutValueShelleyBased w _) _ _ -> case w of {} - TxOut (AddressInEra (ShelleyAddressInEra sbe) ShelleyAddress {}) _ _ _ -> + TxOut (AddressInEra (ShelleyAddressInEra sbe) ShelleyAddress{}) _ _ _ -> case sbe of {} toShelleyTxOut @@ -717,7 +713,7 @@ toAlonzoTxOutDatumHashUTxO :: TxOutDatum CtxUTxO era -> StrictMaybe (Plutus.DataHash StandardCrypto) toAlonzoTxOutDatumHashUTxO TxOutDatumNone = SNothing toAlonzoTxOutDatumHashUTxO (TxOutDatumHash _ (ScriptDataHash dh)) = SJust dh -toAlonzoTxOutDatumHashUTxO (TxOutDatumInline {}) = SNothing +toAlonzoTxOutDatumHashUTxO (TxOutDatumInline{}) = SNothing toBabbageTxOutDatumUTxO :: (L.Era (ShelleyLedgerEra era), Ledger.EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto) @@ -784,7 +780,7 @@ toAlonzoTxOutDatumHash :: TxOutDatum ctx era -> StrictMaybe (Plutus.DataHash StandardCrypto) toAlonzoTxOutDatumHash TxOutDatumNone = SNothing toAlonzoTxOutDatumHash (TxOutDatumHash _ (ScriptDataHash dh)) = SJust dh -toAlonzoTxOutDatumHash (TxOutDatumInline {}) = SNothing +toAlonzoTxOutDatumHash (TxOutDatumInline{}) = SNothing toAlonzoTxOutDatumHash (TxOutDatumInTx' _ (ScriptDataHash dh) _) = SJust dh toBabbageTxOutDatum @@ -1293,11 +1289,11 @@ defaultTxBodyContent era = } setTxIns :: TxIns build era -> TxBodyContent build era -> TxBodyContent build era -setTxIns v txBodyContent = txBodyContent {txIns = v} +setTxIns v txBodyContent = txBodyContent{txIns = v} modTxIns :: (TxIns build era -> TxIns build era) -> TxBodyContent build era -> TxBodyContent build era -modTxIns f txBodyContent = txBodyContent {txIns = f (txIns txBodyContent)} +modTxIns f txBodyContent = txBodyContent{txIns = f (txIns txBodyContent)} addTxIn :: (TxIn, BuildTxWith build (Witness WitCtxTxIn era)) @@ -1306,79 +1302,79 @@ addTxIn addTxIn txIn = modTxIns (txIn :) setTxInsCollateral :: TxInsCollateral era -> TxBodyContent build era -> TxBodyContent build era -setTxInsCollateral v txBodyContent = txBodyContent {txInsCollateral = v} +setTxInsCollateral v txBodyContent = txBodyContent{txInsCollateral = v} setTxInsReference :: TxInsReference build era -> TxBodyContent build era -> TxBodyContent build era -setTxInsReference v txBodyContent = txBodyContent {txInsReference = v} +setTxInsReference v txBodyContent = txBodyContent{txInsReference = v} setTxOuts :: [TxOut CtxTx era] -> TxBodyContent build era -> TxBodyContent build era -setTxOuts v txBodyContent = txBodyContent {txOuts = v} +setTxOuts v txBodyContent = txBodyContent{txOuts = v} modTxOuts :: ([TxOut CtxTx era] -> [TxOut CtxTx era]) -> TxBodyContent build era -> TxBodyContent build era -modTxOuts f txBodyContent = txBodyContent {txOuts = f (txOuts txBodyContent)} +modTxOuts f txBodyContent = txBodyContent{txOuts = f (txOuts txBodyContent)} addTxOut :: TxOut CtxTx era -> TxBodyContent build era -> TxBodyContent build era addTxOut txOut = modTxOuts (txOut :) setTxTotalCollateral :: TxTotalCollateral era -> TxBodyContent build era -> TxBodyContent build era -setTxTotalCollateral v txBodyContent = txBodyContent {txTotalCollateral = v} +setTxTotalCollateral v txBodyContent = txBodyContent{txTotalCollateral = v} setTxReturnCollateral :: TxReturnCollateral CtxTx era -> TxBodyContent build era -> TxBodyContent build era -setTxReturnCollateral v txBodyContent = txBodyContent {txReturnCollateral = v} +setTxReturnCollateral v txBodyContent = txBodyContent{txReturnCollateral = v} setTxFee :: TxFee era -> TxBodyContent build era -> TxBodyContent build era -setTxFee v txBodyContent = txBodyContent {txFee = v} +setTxFee v txBodyContent = txBodyContent{txFee = v} setTxValidityLowerBound :: TxValidityLowerBound era -> TxBodyContent build era -> TxBodyContent build era -setTxValidityLowerBound v txBodyContent = txBodyContent {txValidityLowerBound = v} +setTxValidityLowerBound v txBodyContent = txBodyContent{txValidityLowerBound = v} setTxValidityUpperBound :: TxValidityUpperBound era -> TxBodyContent build era -> TxBodyContent build era -setTxValidityUpperBound v txBodyContent = txBodyContent {txValidityUpperBound = v} +setTxValidityUpperBound v txBodyContent = txBodyContent{txValidityUpperBound = v} setTxMetadata :: TxMetadataInEra era -> TxBodyContent build era -> TxBodyContent build era -setTxMetadata v txBodyContent = txBodyContent {txMetadata = v} +setTxMetadata v txBodyContent = txBodyContent{txMetadata = v} setTxAuxScripts :: TxAuxScripts era -> TxBodyContent build era -> TxBodyContent build era -setTxAuxScripts v txBodyContent = txBodyContent {txAuxScripts = v} +setTxAuxScripts v txBodyContent = txBodyContent{txAuxScripts = v} setTxExtraKeyWits :: TxExtraKeyWitnesses era -> TxBodyContent build era -> TxBodyContent build era -setTxExtraKeyWits v txBodyContent = txBodyContent {txExtraKeyWits = v} +setTxExtraKeyWits v txBodyContent = txBodyContent{txExtraKeyWits = v} setTxProtocolParams :: BuildTxWith build (Maybe (LedgerProtocolParameters era)) -> TxBodyContent build era -> TxBodyContent build era -setTxProtocolParams v txBodyContent = txBodyContent {txProtocolParams = v} +setTxProtocolParams v txBodyContent = txBodyContent{txProtocolParams = v} setTxWithdrawals :: TxWithdrawals build era -> TxBodyContent build era -> TxBodyContent build era -setTxWithdrawals v txBodyContent = txBodyContent {txWithdrawals = v} +setTxWithdrawals v txBodyContent = txBodyContent{txWithdrawals = v} setTxCertificates :: TxCertificates build era -> TxBodyContent build era -> TxBodyContent build era -setTxCertificates v txBodyContent = txBodyContent {txCertificates = v} +setTxCertificates v txBodyContent = txBodyContent{txCertificates = v} setTxUpdateProposal :: TxUpdateProposal era -> TxBodyContent build era -> TxBodyContent build era -setTxUpdateProposal v txBodyContent = txBodyContent {txUpdateProposal = v} +setTxUpdateProposal v txBodyContent = txBodyContent{txUpdateProposal = v} setTxMintValue :: TxMintValue build era -> TxBodyContent build era -> TxBodyContent build era -setTxMintValue v txBodyContent = txBodyContent {txMintValue = v} +setTxMintValue v txBodyContent = txBodyContent{txMintValue = v} setTxScriptValidity :: TxScriptValidity era -> TxBodyContent build era -> TxBodyContent build era -setTxScriptValidity v txBodyContent = txBodyContent {txScriptValidity = v} +setTxScriptValidity v txBodyContent = txBodyContent{txScriptValidity = v} setTxCurrentTreasuryValue :: Maybe (Featured ConwayEraOnwards era L.Coin) -> TxBodyContent build era -> TxBodyContent build era -setTxCurrentTreasuryValue v txBodyContent = txBodyContent {txCurrentTreasuryValue = v} +setTxCurrentTreasuryValue v txBodyContent = txBodyContent{txCurrentTreasuryValue = v} setTxTreasuryDonation :: Maybe (Featured ConwayEraOnwards era L.Coin) -> TxBodyContent build era -> TxBodyContent build era -setTxTreasuryDonation v txBodyContent = txBodyContent {txTreasuryDonation = v} +setTxTreasuryDonation v txBodyContent = txBodyContent{txTreasuryDonation = v} getTxIdByron :: Byron.ATxAux ByteString -> TxId -getTxIdByron (Byron.ATxAux {Byron.aTaTx = txbody}) = +getTxIdByron (Byron.ATxAux{Byron.aTaTx = txbody}) = TxId . fromMaybe impossible . Crypto.hashFromBytesShort @@ -2154,11 +2150,11 @@ makeByronTransactionBody txIns txOuts = do classifyRangeError :: TxOut CtxTx ByronEra -> TxBodyError classifyRangeError txout = case txout of - TxOut (AddressInEra ByronAddressInAnyEra ByronAddress {}) (TxOutValueByron value) _ _ + TxOut (AddressInEra ByronAddressInAnyEra ByronAddress{}) (TxOutValueByron value) _ _ | value < 0 -> TxBodyOutputNegative (lovelaceToQuantity value) (txOutInAnyEra ByronEra txout) | otherwise -> TxBodyOutputOverflow (lovelaceToQuantity value) (txOutInAnyEra ByronEra txout) TxOut (AddressInEra ByronAddressInAnyEra (ByronAddress _)) (TxOutValueShelleyBased w _) _ _ -> case w of {} - TxOut (AddressInEra (ShelleyAddressInEra sbe) ShelleyAddress {}) _ _ _ -> case sbe of {} + TxOut (AddressInEra (ShelleyAddressInEra sbe) ShelleyAddress{}) _ _ _ -> case sbe of {} convTxIns :: TxIns BuildTx era -> Set (L.TxIn StandardCrypto) convTxIns txIns = Set.fromList (map (toShelleyTxIn . fst) txIns) @@ -2760,7 +2756,7 @@ makeShelleyTransactionBody getScriptLanguage :: ScriptWitness witctx era -> Maybe Plutus.Language getScriptLanguage (PlutusScriptWitness _ v _ _ _ _) = Just $ toAlonzoLanguage (AnyPlutusScriptVersion v) - getScriptLanguage SimpleScriptWitness {} = Nothing + getScriptLanguage SimpleScriptWitness{} = Nothing txAuxData :: Maybe (L.TxAuxData StandardBabbage) txAuxData = toAuxiliaryData sbe txMetadata txAuxScripts @@ -2898,7 +2894,7 @@ makeShelleyTransactionBody getScriptLanguage :: ScriptWitness witctx era -> Maybe Plutus.Language getScriptLanguage (PlutusScriptWitness _ v _ _ _ _) = Just $ toAlonzoLanguage (AnyPlutusScriptVersion v) - getScriptLanguage SimpleScriptWitness {} = Nothing + getScriptLanguage SimpleScriptWitness{} = Nothing txAuxData :: Maybe (L.TxAuxData StandardConway) txAuxData = toAuxiliaryData sbe txMetadata txAuxScripts diff --git a/cardano-api/internal/Cardano/Api/Tx/Sign.hs b/cardano-api/internal/Cardano/Api/Tx/Sign.hs index c1c5a09367..5a2767fa3f 100644 --- a/cardano-api/internal/Cardano/Api/Tx/Sign.hs +++ b/cardano-api/internal/Cardano/Api/Tx/Sign.hs @@ -76,18 +76,19 @@ module Cardano.Api.Tx.Sign ) where -import Cardano.Api.Address -import Cardano.Api.Certificate -import Cardano.Api.Eon.AlonzoEraOnwards -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras -import Cardano.Api.HasTypeProxy -import Cardano.Api.Keys.Byron -import Cardano.Api.Keys.Class -import Cardano.Api.Keys.Shelley -import Cardano.Api.NetworkId -import Cardano.Api.SerialiseCBOR -import Cardano.Api.SerialiseTextEnvelope +import Cardano.Api.Address +import Cardano.Api.Certificate +import Cardano.Api.Eon.AlonzoEraOnwards +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras +import Cardano.Api.HasTypeProxy +import Cardano.Api.Keys.Byron +import Cardano.Api.Keys.Class +import Cardano.Api.Keys.Shelley +import Cardano.Api.NetworkId +import Cardano.Api.SerialiseCBOR +import Cardano.Api.SerialiseTextEnvelope + import qualified Cardano.Chain.Common as Byron import qualified Cardano.Chain.UTxO as Byron import qualified Cardano.Crypto.DSIGN.Class as Crypto @@ -99,23 +100,24 @@ import qualified Cardano.Crypto.Wallet as Crypto.HD import qualified Cardano.Ledger.Alonzo.Core as L import qualified Cardano.Ledger.Alonzo.TxWits as Alonzo import qualified Cardano.Ledger.Api as L -import Cardano.Ledger.BaseTypes (maybeToStrictMaybe, strictMaybeToMaybe) -import Cardano.Ledger.Binary (Annotated (..)) +import Cardano.Ledger.BaseTypes (maybeToStrictMaybe, strictMaybeToMaybe) +import Cardano.Ledger.Binary (Annotated (..)) import qualified Cardano.Ledger.Binary as CBOR import qualified Cardano.Ledger.Binary.Plain as Plain import qualified Cardano.Ledger.Core as Ledger -import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Crypto (StandardCrypto) import qualified Cardano.Ledger.Keys as Shelley import qualified Cardano.Ledger.SafeHash as Ledger -import Data.ByteString (ByteString) + +import Data.ByteString (ByteString) import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as LBS import qualified Data.Map.Strict as Map -import Data.Maybe +import Data.Maybe import qualified Data.Set as Set -import Data.Type.Equality (TestEquality (..), (:~:) (Refl)) +import Data.Type.Equality (TestEquality (..), (:~:) (Refl)) import qualified Data.Vector as Vector -import Lens.Micro +import Lens.Micro -- ---------------------------------------------------------------------------- -- Signed transactions @@ -852,10 +854,10 @@ signShelleyTransaction sbe txbody sks = witnesses = map (makeShelleyKeyWitness sbe txbody) sks getByronTxBody :: Byron.ATxAux ByteString -> Annotated Byron.Tx ByteString -getByronTxBody (Byron.ATxAux {Byron.aTaTx = txbody}) = txbody +getByronTxBody (Byron.ATxAux{Byron.aTaTx = txbody}) = txbody getTxWitnessesByron :: Byron.ATxAux ByteString -> [KeyWitness ByronEra] -getTxWitnessesByron (Byron.ATxAux {Byron.aTaWitness = witnesses}) = +getTxWitnessesByron (Byron.ATxAux{Byron.aTaWitness = witnesses}) = map ByronKeyWitness . Vector.toList . unAnnotated diff --git a/cardano-api/internal/Cardano/Api/TxIn.hs b/cardano-api/internal/Cardano/Api/TxIn.hs index 90f4939ecf..54643a8d84 100644 --- a/cardano-api/internal/Cardano/Api/TxIn.hs +++ b/cardano-api/internal/Cardano/Api/TxIn.hs @@ -35,32 +35,34 @@ module Cardano.Api.TxIn ) where -import Cardano.Api.Error -import Cardano.Api.HasTypeProxy -import Cardano.Api.Pretty -import Cardano.Api.SerialiseJSON -import Cardano.Api.SerialiseRaw -import Cardano.Api.SerialiseUsing -import Cardano.Api.Utils +import Cardano.Api.Error +import Cardano.Api.HasTypeProxy +import Cardano.Api.Pretty +import Cardano.Api.SerialiseJSON +import Cardano.Api.SerialiseRaw +import Cardano.Api.SerialiseUsing +import Cardano.Api.Utils + import qualified Cardano.Chain.UTxO as Byron import qualified Cardano.Crypto.Hash.Class as Crypto import qualified Cardano.Crypto.Hashing as Byron import qualified Cardano.Ledger.BaseTypes as Ledger -import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Crypto (StandardCrypto) import qualified Cardano.Ledger.Keys as Shelley import qualified Cardano.Ledger.SafeHash as SafeHash import qualified Cardano.Ledger.Shelley.TxBody as Shelley import qualified Cardano.Ledger.TxIn as Ledger -import Control.Applicative (some) -import Data.Aeson (withText) + +import Control.Applicative (some) +import Data.Aeson (withText) import qualified Data.Aeson as Aeson -import Data.Aeson.Types (ToJSONKey (..), toJSONKeyText) +import Data.Aeson.Types (ToJSONKey (..), toJSONKeyText) import qualified Data.ByteString.Char8 as BSC -import Data.String -import Data.Text (Text) +import Data.String +import Data.Text (Text) import qualified Data.Text as Text -import Text.Parsec (()) import qualified Text.Parsec as Parsec +import Text.Parsec (()) import qualified Text.Parsec.Language as Parsec import qualified Text.Parsec.String as Parsec import qualified Text.Parsec.Token as Parsec @@ -136,7 +138,7 @@ parseTxIx :: Parsec.Parser TxIx parseTxIx = TxIx . fromIntegral <$> decimal decimal :: Parsec.Parser Integer -Parsec.TokenParser {Parsec.decimal = decimal} = Parsec.haskell +Parsec.TokenParser{Parsec.decimal = decimal} = Parsec.haskell renderTxIn :: TxIn -> Text renderTxIn (TxIn txId (TxIx ix)) = @@ -144,7 +146,7 @@ renderTxIn (TxIn txId (TxIx ix)) = newtype TxIx = TxIx Word deriving stock (Eq, Ord, Show) - deriving newtype (Enum) + deriving newtype Enum deriving newtype (ToJSON, FromJSON) fromByronTxIn :: Byron.TxIn -> TxIn diff --git a/cardano-api/internal/Cardano/Api/TxMetadata.hs b/cardano-api/internal/Cardano/Api/TxMetadata.hs index 4534456f29..933e8aa44d 100644 --- a/cardano-api/internal/Cardano/Api/TxMetadata.hs +++ b/cardano-api/internal/Cardano/Api/TxMetadata.hs @@ -47,41 +47,43 @@ module Cardano.Api.TxMetadata ) where -import Cardano.Api.Eras -import Cardano.Api.Error -import Cardano.Api.HasTypeProxy -import Cardano.Api.Pretty -import Cardano.Api.SerialiseCBOR (SerialiseAsCBOR (..)) +import Cardano.Api.Eras +import Cardano.Api.Error +import Cardano.Api.HasTypeProxy +import Cardano.Api.Pretty +import Cardano.Api.SerialiseCBOR (SerialiseAsCBOR (..)) + import qualified Cardano.Ledger.Binary as CBOR import qualified Cardano.Ledger.Shelley.TxAuxData as Shelley + import qualified Codec.CBOR.Magic as CBOR -import Control.Applicative (Alternative (..)) -import Control.Monad (guard, when) +import Control.Applicative (Alternative (..)) +import Control.Monad (guard, when) import qualified Data.Aeson as Aeson import qualified Data.Aeson.Key as Aeson import qualified Data.Aeson.KeyMap as KeyMap import qualified Data.Aeson.Text as Aeson.Text import qualified Data.Attoparsec.ByteString.Char8 as Atto -import Data.Bifunctor (bimap, first) -import Data.ByteString (ByteString) +import Data.Bifunctor (bimap, first) +import Data.ByteString (ByteString) import qualified Data.ByteString as BS import qualified Data.ByteString.Base16 as Base16 import qualified Data.ByteString.Char8 as BSC import qualified Data.ByteString.Lazy.Char8 as LBS -import Data.Data (Data) +import Data.Data (Data) import qualified Data.List as List import qualified Data.Map.Lazy as Map.Lazy -import Data.Map.Strict (Map) +import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map -import Data.Maybe (fromMaybe) +import Data.Maybe (fromMaybe) import qualified Data.Scientific as Scientific -import Data.Text (Text) +import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Encoding as Text import qualified Data.Text.Lazy as Text.Lazy import qualified Data.Text.Lazy.Builder as Text.Builder import qualified Data.Vector as Vector -import Data.Word +import Data.Word -- ---------------------------------------------------------------------------- -- TxMetadata types @@ -551,7 +553,7 @@ metadataValueFromJsonNoSchema = conv :: Aeson.Value -> Either TxMetadataJsonSchemaError TxMetadataValue conv Aeson.Null = Left TxMetadataJsonNullNotAllowed - conv Aeson.Bool {} = Left TxMetadataJsonBoolNotAllowed + conv Aeson.Bool{} = Left TxMetadataJsonBoolNotAllowed conv (Aeson.Number d) = case Scientific.floatingOrInteger d :: Either Double Integer of Left n -> Left (TxMetadataJsonNumberNotInteger n) diff --git a/cardano-api/internal/Cardano/Api/Value.hs b/cardano-api/internal/Cardano/Api/Value.hs index 74389e7e41..034536af01 100644 --- a/cardano-api/internal/Cardano/Api/Value.hs +++ b/cardano-api/internal/Cardano/Api/Value.hs @@ -57,44 +57,46 @@ module Cardano.Api.Value ) where -import Cardano.Api.Eon.MaryEraOnwards -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras.Case -import Cardano.Api.Error (displayError) -import Cardano.Api.HasTypeProxy +import Cardano.Api.Eon.MaryEraOnwards +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eras.Case +import Cardano.Api.Error (displayError) +import Cardano.Api.HasTypeProxy import qualified Cardano.Api.Ledger.Lens as A -import Cardano.Api.Script -import Cardano.Api.SerialiseRaw -import Cardano.Api.SerialiseUsing -import Cardano.Api.Utils (failEitherWith) +import Cardano.Api.Script +import Cardano.Api.SerialiseRaw +import Cardano.Api.SerialiseUsing +import Cardano.Api.Utils (failEitherWith) + import qualified Cardano.Chain.Common as Byron import qualified Cardano.Ledger.Allegra.Core as L import qualified Cardano.Ledger.Coin as L -import Cardano.Ledger.Crypto (StandardCrypto) -import Cardano.Ledger.Mary.TxOut as Mary (scaledMinDeposit) -import Cardano.Ledger.Mary.Value (MaryValue (..)) +import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Mary.TxOut as Mary (scaledMinDeposit) +import Cardano.Ledger.Mary.Value (MaryValue (..)) import qualified Cardano.Ledger.Mary.Value as Mary -import Data.Aeson (FromJSON, FromJSONKey, ToJSON, object, parseJSON, toJSON, withObject) + +import Data.Aeson (FromJSON, FromJSONKey, ToJSON, object, parseJSON, toJSON, withObject) import qualified Data.Aeson as Aeson import qualified Data.Aeson.Key as Aeson import qualified Data.Aeson.KeyMap as KeyMap -import Data.Aeson.Types (Parser, ToJSONKey) -import Data.ByteString (ByteString) +import Data.Aeson.Types (Parser, ToJSONKey) +import Data.ByteString (ByteString) import qualified Data.ByteString as BS import qualified Data.ByteString.Char8 as BSC import qualified Data.ByteString.Short as Short -import Data.Data (Data) -import Data.Function ((&)) -import Data.Group (invert) +import Data.Data (Data) +import Data.Function ((&)) +import Data.Group (invert) import qualified Data.List as List import qualified Data.Map.Merge.Strict as Map -import Data.Map.Strict (Map) +import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map -import Data.String (IsString (..)) -import Data.Text (Text) +import Data.String (IsString (..)) +import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Encoding as Text -import Lens.Micro ((%~)) +import Lens.Micro ((%~)) toByronLovelace :: L.Coin -> Maybe Byron.Lovelace toByronLovelace (L.Coin x) = @@ -113,7 +115,7 @@ fromShelleyDeltaLovelace (L.DeltaCoin d) = L.Coin d -- newtype Quantity = Quantity Integer - deriving stock (Data) + deriving stock Data deriving newtype (Eq, Ord, Num, Show, ToJSON, FromJSON) instance Semigroup Quantity where @@ -146,7 +148,7 @@ scriptPolicyId = PolicyId . hashScript newtype AssetName = AssetName ByteString deriving stock (Eq, Ord) - deriving newtype (Show) + deriving newtype Show deriving (ToJSON, FromJSON, ToJSONKey, FromJSONKey) via UsingRawBytesHex AssetName @@ -178,7 +180,7 @@ data AssetId deriving (Eq, Ord, Show) newtype Value = Value (Map AssetId Quantity) - deriving (Eq) + deriving Eq instance Show Value where showsPrec d v = diff --git a/cardano-api/internal/Cardano/Api/ValueParser.hs b/cardano-api/internal/Cardano/Api/ValueParser.hs index de26cec18c..44526e3db8 100644 --- a/cardano-api/internal/Cardano/Api/ValueParser.hs +++ b/cardano-api/internal/Cardano/Api/ValueParser.hs @@ -5,23 +5,24 @@ module Cardano.Api.ValueParser ) where -import Cardano.Api.Error (displayError) -import Cardano.Api.SerialiseRaw -import Cardano.Api.Utils (failEitherWith) -import Cardano.Api.Value -import Control.Applicative (many, some, (<|>)) +import Cardano.Api.Error (displayError) +import Cardano.Api.SerialiseRaw +import Cardano.Api.Utils (failEitherWith) +import Cardano.Api.Value + +import Control.Applicative (many, some, (<|>)) import qualified Data.ByteString.Char8 as BSC import qualified Data.Char as Char -import Data.Functor (void, ($>)) -import Data.List (foldl') +import Data.Functor (void, ($>)) +import Data.List (foldl') import qualified Data.Text as Text import qualified Data.Text.Encoding as Text -import Data.Word (Word64) -import Text.Parsec as Parsec (notFollowedBy, try, ()) -import Text.Parsec.Char (alphaNum, char, digit, hexDigit, space, spaces, string) -import Text.Parsec.Expr (Assoc (..), Operator (..), buildExpressionParser) -import Text.Parsec.String (Parser) -import Text.ParserCombinators.Parsec.Combinator (many1) +import Data.Word (Word64) +import Text.Parsec as Parsec (notFollowedBy, try, ()) +import Text.Parsec.Char (alphaNum, char, digit, hexDigit, space, spaces, string) +import Text.Parsec.Expr (Assoc (..), Operator (..), buildExpressionParser) +import Text.Parsec.String (Parser) +import Text.ParserCombinators.Parsec.Combinator (many1) -- | Parse a 'Value' from its string representation. parseValue :: Parser Value diff --git a/cardano-api/internal/Cardano/Api/Via/ShowOf.hs b/cardano-api/internal/Cardano/Api/Via/ShowOf.hs index b534d7ab1b..2ea04a531a 100644 --- a/cardano-api/internal/Cardano/Api/Via/ShowOf.hs +++ b/cardano-api/internal/Cardano/Api/Via/ShowOf.hs @@ -3,11 +3,11 @@ module Cardano.Api.Via.ShowOf ) where -import Data.Aeson +import Data.Aeson import qualified Data.Aeson.Key as Key -import Data.Aeson.Types +import Data.Aeson.Types import qualified Data.Text as Text -import Prettyprinter +import Prettyprinter newtype ShowOf a = ShowOf a diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index 996af3c6ed..0a7b772ada 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -998,69 +998,69 @@ module Cardano.Api ) where -import Cardano.Api.Address -import Cardano.Api.Anchor -import Cardano.Api.Block -import Cardano.Api.Certificate -import Cardano.Api.Convenience.Construction -import Cardano.Api.Convenience.Query -import Cardano.Api.DRepMetadata -import Cardano.Api.DeserialiseAnyOf -import Cardano.Api.Eon.AllegraEraOnwards -import Cardano.Api.Eon.AlonzoEraOnwards -import Cardano.Api.Eon.BabbageEraOnwards -import Cardano.Api.Eon.ByronToAlonzoEra -import Cardano.Api.Eon.ConwayEraOnwards -import Cardano.Api.Eon.MaryEraOnwards -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eon.ShelleyEraOnly -import Cardano.Api.Eon.ShelleyToAllegraEra -import Cardano.Api.Eon.ShelleyToAlonzoEra -import Cardano.Api.Eon.ShelleyToBabbageEra -import Cardano.Api.Eon.ShelleyToMaryEra -import Cardano.Api.Eras -import Cardano.Api.Eras.Case -import Cardano.Api.Error -import Cardano.Api.Feature -import Cardano.Api.Fees -import Cardano.Api.Genesis -import Cardano.Api.GenesisParameters -import Cardano.Api.Governance.Actions.ProposalProcedure -import Cardano.Api.HasTypeProxy -import Cardano.Api.Hash -import Cardano.Api.IO -import Cardano.Api.IPC -import Cardano.Api.IPC.Monad -import Cardano.Api.InMode -import Cardano.Api.Keys.Byron -import Cardano.Api.Keys.Class -import Cardano.Api.Keys.Read -import Cardano.Api.Keys.Shelley -import Cardano.Api.LedgerState -import Cardano.Api.Modes -import Cardano.Api.Monad.Error -import Cardano.Api.NetworkId -import Cardano.Api.OperationalCertificate -import Cardano.Api.Orphans () -import Cardano.Api.Pretty -import Cardano.Api.Protocol -import Cardano.Api.ProtocolParameters -import Cardano.Api.Query hiding (LedgerState (..)) -import Cardano.Api.Query.Expr -import Cardano.Api.Rewards -import Cardano.Api.Script -import Cardano.Api.ScriptData -import Cardano.Api.SerialiseBech32 -import Cardano.Api.SerialiseCBOR -import Cardano.Api.SerialiseJSON -import Cardano.Api.SerialiseLedgerCddl -import Cardano.Api.SerialiseRaw -import Cardano.Api.SerialiseTextEnvelope -import Cardano.Api.SerialiseUsing -import Cardano.Api.StakePoolMetadata -import Cardano.Api.Tx.Body -import Cardano.Api.Tx.Sign -import Cardano.Api.TxMetadata -import Cardano.Api.Utils -import Cardano.Api.Value -import Cardano.Api.ValueParser +import Cardano.Api.Address +import Cardano.Api.Anchor +import Cardano.Api.Block +import Cardano.Api.Certificate +import Cardano.Api.Convenience.Construction +import Cardano.Api.Convenience.Query +import Cardano.Api.DeserialiseAnyOf +import Cardano.Api.DRepMetadata +import Cardano.Api.Eon.AllegraEraOnwards +import Cardano.Api.Eon.AlonzoEraOnwards +import Cardano.Api.Eon.BabbageEraOnwards +import Cardano.Api.Eon.ByronToAlonzoEra +import Cardano.Api.Eon.ConwayEraOnwards +import Cardano.Api.Eon.MaryEraOnwards +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Eon.ShelleyEraOnly +import Cardano.Api.Eon.ShelleyToAllegraEra +import Cardano.Api.Eon.ShelleyToAlonzoEra +import Cardano.Api.Eon.ShelleyToBabbageEra +import Cardano.Api.Eon.ShelleyToMaryEra +import Cardano.Api.Eras +import Cardano.Api.Eras.Case +import Cardano.Api.Error +import Cardano.Api.Feature +import Cardano.Api.Fees +import Cardano.Api.Genesis +import Cardano.Api.GenesisParameters +import Cardano.Api.Governance.Actions.ProposalProcedure +import Cardano.Api.Hash +import Cardano.Api.HasTypeProxy +import Cardano.Api.InMode +import Cardano.Api.IO +import Cardano.Api.IPC +import Cardano.Api.IPC.Monad +import Cardano.Api.Keys.Byron +import Cardano.Api.Keys.Class +import Cardano.Api.Keys.Read +import Cardano.Api.Keys.Shelley +import Cardano.Api.LedgerState +import Cardano.Api.Modes +import Cardano.Api.Monad.Error +import Cardano.Api.NetworkId +import Cardano.Api.OperationalCertificate +import Cardano.Api.Orphans () +import Cardano.Api.Pretty +import Cardano.Api.Protocol +import Cardano.Api.ProtocolParameters +import Cardano.Api.Query hiding (LedgerState (..)) +import Cardano.Api.Query.Expr +import Cardano.Api.Rewards +import Cardano.Api.Script +import Cardano.Api.ScriptData +import Cardano.Api.SerialiseBech32 +import Cardano.Api.SerialiseCBOR +import Cardano.Api.SerialiseJSON +import Cardano.Api.SerialiseLedgerCddl +import Cardano.Api.SerialiseRaw +import Cardano.Api.SerialiseTextEnvelope +import Cardano.Api.SerialiseUsing +import Cardano.Api.StakePoolMetadata +import Cardano.Api.Tx.Body +import Cardano.Api.Tx.Sign +import Cardano.Api.TxMetadata +import Cardano.Api.Utils +import Cardano.Api.Value +import Cardano.Api.ValueParser diff --git a/cardano-api/src/Cardano/Api/Byron.hs b/cardano-api/src/Cardano/Api/Byron.hs index 620dc5a583..616dea34ab 100644 --- a/cardano-api/src/Cardano/Api/Byron.hs +++ b/cardano-api/src/Cardano/Api/Byron.hs @@ -90,12 +90,12 @@ module Cardano.Api.Byron ) where -import Cardano.Api -import Cardano.Api.Address -import Cardano.Api.Keys.Byron -import Cardano.Api.NetworkId -import Cardano.Api.SerialiseLedgerCddl -import Cardano.Api.SpecialByron -import Cardano.Api.Tx.Body -import Cardano.Api.Tx.Sign -import Cardano.Api.Value +import Cardano.Api +import Cardano.Api.Address +import Cardano.Api.Keys.Byron +import Cardano.Api.NetworkId +import Cardano.Api.SerialiseLedgerCddl +import Cardano.Api.SpecialByron +import Cardano.Api.Tx.Body +import Cardano.Api.Tx.Sign +import Cardano.Api.Value diff --git a/cardano-api/src/Cardano/Api/ChainSync/Client.hs b/cardano-api/src/Cardano/Api/ChainSync/Client.hs index a24da8a7f5..39c5c56da4 100644 --- a/cardano-api/src/Cardano/Api/ChainSync/Client.hs +++ b/cardano-api/src/Cardano/Api/ChainSync/Client.hs @@ -15,4 +15,4 @@ module Cardano.Api.ChainSync.Client ) where -import Ouroboros.Network.Protocol.ChainSync.Client +import Ouroboros.Network.Protocol.ChainSync.Client diff --git a/cardano-api/src/Cardano/Api/ChainSync/ClientPipelined.hs b/cardano-api/src/Cardano/Api/ChainSync/ClientPipelined.hs index d9a3da779d..0ff1ba8e89 100644 --- a/cardano-api/src/Cardano/Api/ChainSync/ClientPipelined.hs +++ b/cardano-api/src/Cardano/Api/ChainSync/ClientPipelined.hs @@ -31,6 +31,7 @@ module Cardano.Api.ChainSync.ClientPipelined ) where -import Network.TypedProtocol.Pipelined (N (..), Nat (..), natToInt) -import Ouroboros.Network.Protocol.ChainSync.ClientPipelined -import Ouroboros.Network.Protocol.ChainSync.PipelineDecision +import Ouroboros.Network.Protocol.ChainSync.ClientPipelined +import Ouroboros.Network.Protocol.ChainSync.PipelineDecision + +import Network.TypedProtocol.Pipelined (N (..), Nat (..), natToInt) diff --git a/cardano-api/src/Cardano/Api/Crypto/Ed25519Bip32.hs b/cardano-api/src/Cardano/Api/Crypto/Ed25519Bip32.hs index 2debb745d1..e7e2fb6555 100644 --- a/cardano-api/src/Cardano/Api/Crypto/Ed25519Bip32.hs +++ b/cardano-api/src/Cardano/Api/Crypto/Ed25519Bip32.hs @@ -18,19 +18,21 @@ module Cardano.Api.Crypto.Ed25519Bip32 ) where -import Cardano.Binary (FromCBOR (..), ToCBOR (..)) -import Cardano.Crypto.DSIGN.Class -import Cardano.Crypto.Seed -import Cardano.Crypto.Util (SignableRepresentation (..)) +import Cardano.Binary (FromCBOR (..), ToCBOR (..)) +import Cardano.Crypto.DSIGN.Class +import Cardano.Crypto.Seed +import Cardano.Crypto.Util (SignableRepresentation (..)) import qualified Cardano.Crypto.Wallet as CC -import Control.DeepSeq (NFData) -import qualified Crypto.ECC.Edwards25519 as Ed25519 -import Crypto.Error (eitherCryptoError) -import Data.ByteArray as BA (ByteArrayAccess, ScrubbedBytes, convert) -import Data.ByteString (ByteString) + +import Control.DeepSeq (NFData) +import Data.ByteArray as BA (ByteArrayAccess, ScrubbedBytes, convert) +import Data.ByteString (ByteString) import qualified Data.ByteString as BS -import GHC.Generics (Generic) -import NoThunks.Class (InspectHeap (..), NoThunks) +import GHC.Generics (Generic) + +import qualified Crypto.ECC.Edwards25519 as Ed25519 +import Crypto.Error (eitherCryptoError) +import NoThunks.Class (InspectHeap (..), NoThunks) data Ed25519Bip32DSIGN @@ -52,17 +54,17 @@ instance DSIGNAlgorithm Ed25519Bip32DSIGN where newtype VerKeyDSIGN Ed25519Bip32DSIGN = VerKeyEd25519Bip32DSIGN CC.XPub deriving (Show, Eq, Generic) - deriving newtype (NFData) - deriving (NoThunks) via InspectHeap CC.XPub + deriving newtype NFData + deriving NoThunks via InspectHeap CC.XPub newtype SignKeyDSIGN Ed25519Bip32DSIGN = SignKeyEd25519Bip32DSIGN CC.XPrv deriving (Generic, ByteArrayAccess) - deriving newtype (NFData) - deriving (NoThunks) via InspectHeap CC.XPrv + deriving newtype NFData + deriving NoThunks via InspectHeap CC.XPrv newtype SigDSIGN Ed25519Bip32DSIGN = SigEd25519Bip32DSIGN CC.XSignature deriving (Show, Eq, Generic, ByteArrayAccess) - deriving (NoThunks) via InspectHeap CC.XSignature + deriving NoThunks via InspectHeap CC.XSignature -- -- Metadata and basic key operations diff --git a/cardano-api/src/Cardano/Api/Experimental.hs b/cardano-api/src/Cardano/Api/Experimental.hs index a670fe599e..9a7d4d3989 100644 --- a/cardano-api/src/Cardano/Api/Experimental.hs +++ b/cardano-api/src/Cardano/Api/Experimental.hs @@ -14,4 +14,4 @@ module Cardano.Api.Experimental ) where -import Cardano.Api.Protocol.Version +import Cardano.Api.Protocol.Version diff --git a/cardano-api/src/Cardano/Api/Ledger.hs b/cardano-api/src/Cardano/Api/Ledger.hs index 1619105aef..4bd87d935c 100644 --- a/cardano-api/src/Cardano/Api/Ledger.hs +++ b/cardano-api/src/Cardano/Api/Ledger.hs @@ -3,4 +3,4 @@ module Cardano.Api.Ledger ) where -import Cardano.Api.ReexposeLedger +import Cardano.Api.ReexposeLedger diff --git a/cardano-api/src/Cardano/Api/Network.hs b/cardano-api/src/Cardano/Api/Network.hs index 047f7b099f..1748c27701 100644 --- a/cardano-api/src/Cardano/Api/Network.hs +++ b/cardano-api/src/Cardano/Api/Network.hs @@ -3,4 +3,4 @@ module Cardano.Api.Network ) where -import Cardano.Api.ReexposeNetwork +import Cardano.Api.ReexposeNetwork diff --git a/cardano-api/src/Cardano/Api/Shelley.hs b/cardano-api/src/Cardano/Api/Shelley.hs index f1f475b79e..9e40f4aeef 100644 --- a/cardano-api/src/Cardano/Api/Shelley.hs +++ b/cardano-api/src/Cardano/Api/Shelley.hs @@ -286,31 +286,31 @@ module Cardano.Api.Shelley ) where -import Cardano.Api -import Cardano.Api.Address -import Cardano.Api.Block -import Cardano.Api.Certificate -import Cardano.Api.DRepMetadata -import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Genesis -import Cardano.Api.Governance.Actions.ProposalProcedure -import Cardano.Api.Governance.Actions.VotingProcedure -import Cardano.Api.Governance.Poll -import Cardano.Api.IPC -import Cardano.Api.InMode -import Cardano.Api.Keys.Praos -import Cardano.Api.Keys.Shelley -import Cardano.Api.LedgerEvents.ConvertLedgerEvent -import Cardano.Api.LedgerEvents.LedgerEvent -import Cardano.Api.LedgerState -import Cardano.Api.NetworkId -import Cardano.Api.OperationalCertificate -import Cardano.Api.ProtocolParameters -import Cardano.Api.Query -import Cardano.Api.Script -import Cardano.Api.ScriptData -import Cardano.Api.StakePoolMetadata -import Cardano.Api.Tx.Body -import Cardano.Api.Tx.Sign -import Cardano.Api.TxMetadata -import Cardano.Api.Value +import Cardano.Api +import Cardano.Api.Address +import Cardano.Api.Block +import Cardano.Api.Certificate +import Cardano.Api.DRepMetadata +import Cardano.Api.Eon.ShelleyBasedEra +import Cardano.Api.Genesis +import Cardano.Api.Governance.Actions.ProposalProcedure +import Cardano.Api.Governance.Actions.VotingProcedure +import Cardano.Api.Governance.Poll +import Cardano.Api.InMode +import Cardano.Api.IPC +import Cardano.Api.Keys.Praos +import Cardano.Api.Keys.Shelley +import Cardano.Api.LedgerEvents.ConvertLedgerEvent +import Cardano.Api.LedgerEvents.LedgerEvent +import Cardano.Api.LedgerState +import Cardano.Api.NetworkId +import Cardano.Api.OperationalCertificate +import Cardano.Api.ProtocolParameters +import Cardano.Api.Query +import Cardano.Api.Script +import Cardano.Api.ScriptData +import Cardano.Api.StakePoolMetadata +import Cardano.Api.Tx.Body +import Cardano.Api.Tx.Sign +import Cardano.Api.TxMetadata +import Cardano.Api.Value diff --git a/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Genesis.hs b/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Genesis.hs index 9fdb63e4cb..9bc890a26d 100644 --- a/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Genesis.hs +++ b/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Genesis.hs @@ -7,32 +7,26 @@ module Test.Golden.Cardano.Api.Genesis ) where -import Cardano.Api.Shelley (ShelleyGenesis (..)) -import Cardano.Ledger.Address (Addr (..)) -import Cardano.Ledger.BaseTypes (Network (..)) -import Cardano.Ledger.Coin (Coin (..)) -import Cardano.Ledger.Core -import Cardano.Ledger.Credential - ( Credential (..) - , PaymentCredential - , StakeCredential - , StakeReference (..) - ) -import Cardano.Ledger.Crypto (StandardCrypto) -import Cardano.Ledger.Keys - ( GenDelegPair (..) - , Hash - , KeyHash (..) - , KeyRole (..) - , VerKeyVRF - ) -import Cardano.Ledger.Shelley.Genesis (emptyGenesisStaking) -import Cardano.Slotting.Slot (EpochSize (..)) -import Data.ListMap (ListMap (ListMap)) +import Cardano.Api.Shelley (ShelleyGenesis (..)) + +import Cardano.Ledger.Address (Addr (..)) +import Cardano.Ledger.BaseTypes (Network (..)) +import Cardano.Ledger.Coin (Coin (..)) +import Cardano.Ledger.Core +import Cardano.Ledger.Credential (Credential (..), PaymentCredential, StakeCredential, + StakeReference (..)) +import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Keys (GenDelegPair (..), Hash, KeyHash (..), KeyRole (..), + VerKeyVRF) +import Cardano.Ledger.Shelley.Genesis (emptyGenesisStaking) +import Cardano.Slotting.Slot (EpochSize (..)) + +import Data.ListMap (ListMap (ListMap)) import qualified Data.Map.Strict as Map -import Data.Time.Clock.POSIX (posixSecondsToUTCTime) -import Lens.Micro -import Test.Cardano.Ledger.Shelley.Utils (unsafeBoundRational) +import Data.Time.Clock.POSIX (posixSecondsToUTCTime) +import Lens.Micro + +import Test.Cardano.Ledger.Shelley.Utils (unsafeBoundRational) exampleShelleyGenesis :: ShelleyGenesis StandardCrypto exampleShelleyGenesis = diff --git a/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Ledger.hs b/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Ledger.hs index 2fef2dae0b..5930fa3069 100644 --- a/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Ledger.hs +++ b/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Ledger.hs @@ -3,11 +3,12 @@ module Test.Golden.Cardano.Api.Ledger ) where +import Test.Cardano.Ledger.Core.Arbitrary () + import qualified Hedgehog.Extras.Aeson as H -import Test.Cardano.Ledger.Core.Arbitrary () -import Test.Golden.Cardano.Api.Genesis (exampleShelleyGenesis) -import Test.Tasty (TestTree) -import Test.Tasty.Hedgehog (testProperty) +import Test.Golden.Cardano.Api.Genesis (exampleShelleyGenesis) +import Test.Tasty (TestTree) +import Test.Tasty.Hedgehog (testProperty) test_golden_ShelleyGenesis :: TestTree test_golden_ShelleyGenesis = diff --git a/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/ProtocolParameters.hs b/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/ProtocolParameters.hs index c59f90be89..2ea66993e4 100644 --- a/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/ProtocolParameters.hs +++ b/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/ProtocolParameters.hs @@ -11,35 +11,33 @@ module Test.Golden.Cardano.Api.ProtocolParameters ) where -import Cardano.Api - ( AnyPlutusScriptVersion (AnyPlutusScriptVersion) - , CostModel (..) - , ExecutionUnits (..) - , PlutusScriptVersion (..) - , makePraosNonce - ) -import Cardano.Api.Ledger (Coin (..), EpochInterval (EpochInterval), StandardCrypto) -import Cardano.Api.ProtocolParameters (ExecutionUnitPrices (..), ProtocolParameters (..)) -import Cardano.Ledger.Alonzo (AlonzoEra) -import Cardano.Ledger.Alonzo.PParams (AlonzoPParams (..)) -import Cardano.Ledger.Babbage (BabbageEra) -import Cardano.Ledger.Babbage.PParams (BabbagePParams (..)) -import Cardano.Ledger.Plutus.CostModels (costModelParamsCount) -import Cardano.Ledger.Plutus.Language (Language (..)) -import Cardano.Ledger.Shelley (ShelleyEra) -import Cardano.Ledger.Shelley.PParams (ShelleyPParams (..)) -import Data.Aeson (FromJSON, eitherDecode, encode) -import Data.ByteString.Lazy (ByteString) -import Data.Functor.Identity (Identity) -import Data.Int (Int64) -import Data.Map (Map) +import Cardano.Api (AnyPlutusScriptVersion (AnyPlutusScriptVersion), CostModel (..), + ExecutionUnits (..), PlutusScriptVersion (..), makePraosNonce) +import Cardano.Api.Ledger (Coin (..), EpochInterval (EpochInterval), StandardCrypto) +import Cardano.Api.ProtocolParameters (ExecutionUnitPrices (..), ProtocolParameters (..)) + +import Cardano.Ledger.Alonzo (AlonzoEra) +import Cardano.Ledger.Alonzo.PParams (AlonzoPParams (..)) +import Cardano.Ledger.Babbage (BabbageEra) +import Cardano.Ledger.Babbage.PParams (BabbagePParams (..)) +import Cardano.Ledger.Plutus.CostModels (costModelParamsCount) +import Cardano.Ledger.Plutus.Language (Language (..)) +import Cardano.Ledger.Shelley (ShelleyEra) +import Cardano.Ledger.Shelley.PParams (ShelleyPParams (..)) + +import Data.Aeson (FromJSON, eitherDecode, encode) +import Data.ByteString.Lazy (ByteString) +import Data.Functor.Identity (Identity) +import Data.Int (Int64) +import Data.Map (Map) import qualified Data.Map as M -import Data.Proxy (Proxy (..)) -import Hedgehog (Property, property, success) +import Data.Proxy (Proxy (..)) + +import Hedgehog (Property, property, success) import qualified Hedgehog.Extras.Aeson as H -import Hedgehog.Internal.Property (failWith) -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) +import Hedgehog.Internal.Property (failWith) +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) test_golden_ProtocolParameters :: TestTree test_golden_ProtocolParameters = testProperty "golden ProtocolParameters" $ do diff --git a/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Typed/Script.hs b/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Typed/Script.hs index 4889b8dbcd..ff433ac31c 100644 --- a/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Typed/Script.hs +++ b/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Typed/Script.hs @@ -13,17 +13,21 @@ module Test.Golden.Cardano.Api.Typed.Script ) where -import Cardano.Api -import Cardano.Api.Shelley +import Cardano.Api +import Cardano.Api.Shelley + import qualified Cardano.Ledger.Api.Era as L -import Data.Aeson -import Hedgehog ((===)) + +import Data.Aeson +import System.FilePath (()) + +import Test.Gen.Cardano.Api.Typed + +import Hedgehog ((===)) import qualified Hedgehog as H -import Hedgehog.Extras.Aeson -import System.FilePath (()) -import Test.Gen.Cardano.Api.Typed -import Test.Tasty (TestTree) -import Test.Tasty.Hedgehog (testProperty) +import Hedgehog.Extras.Aeson +import Test.Tasty (TestTree) +import Test.Tasty.Hedgehog (testProperty) {- HLINT ignore "Use camelCase" -} diff --git a/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Value.hs b/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Value.hs index 643ef9d5f4..3342921e17 100644 --- a/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Value.hs +++ b/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/Value.hs @@ -1,28 +1,23 @@ module Test.Golden.Cardano.Api.Value where -import Cardano.Api - ( MaryEraOnwards (..) - , ShelleyBasedEra (..) - , ValueNestedBundle (..) - , ValueNestedRep (..) - , fromLedgerValue - , parseValue - , renderValue - , renderValuePretty - , valueFromNestedRep - , valueToNestedRep - ) +import Cardano.Api (MaryEraOnwards (..), ShelleyBasedEra (..), ValueNestedBundle (..), + ValueNestedRep (..), fromLedgerValue, parseValue, renderValue, renderValuePretty, + valueFromNestedRep, valueToNestedRep) import qualified Cardano.Api as Api -import Data.Aeson (eitherDecode, encode) -import Data.List (groupBy, sort) + +import Prelude + +import Data.Aeson (eitherDecode, encode) +import Data.List (groupBy, sort) import qualified Data.Map.Strict as Map import qualified Data.Text as Text -import Hedgehog (Property, forAll, property, tripping, (===)) +import qualified Text.Parsec as Parsec (parse) + +import Test.Gen.Cardano.Api.Typed (genAssetName, genValueDefault, genValueNestedRep) + +import Hedgehog (Property, forAll, property, tripping, (===)) import qualified Hedgehog.Extras as H import qualified Hedgehog.Extras.Test.Golden as H -import Test.Gen.Cardano.Api.Typed (genAssetName, genValueDefault, genValueNestedRep) -import qualified Text.Parsec as Parsec (parse) -import Prelude {- HLINT ignore "Use let" -} @@ -96,8 +91,8 @@ canonicalise = . (\(ValueNestedRep bundles) -> bundles) where samePolicyId - ValueNestedBundleAda {} - ValueNestedBundleAda {} = True + ValueNestedBundleAda{} + ValueNestedBundleAda{} = True samePolicyId (ValueNestedBundle pid _) (ValueNestedBundle pid' _) = pid == pid' @@ -115,7 +110,7 @@ canonicalise = ValueNestedBundle pid (Map.unionWith (<>) as as') mergeBundle _ _ = error "canonicalise.mergeBundle: impossible" - filterZeros b@ValueNestedBundleAda {} = b + filterZeros b@ValueNestedBundleAda{} = b filterZeros (ValueNestedBundle pid as) = ValueNestedBundle pid (Map.filter (/= 0) as) diff --git a/cardano-api/test/cardano-api-golden/Test/Golden/ErrorsSpec.hs b/cardano-api/test/cardano-api-golden/Test/Golden/ErrorsSpec.hs index 90ead48a3d..7799e30452 100644 --- a/cardano-api/test/cardano-api-golden/Test/Golden/ErrorsSpec.hs +++ b/cardano-api/test/cardano-api-golden/Test/Golden/ErrorsSpec.hs @@ -29,30 +29,33 @@ module Test.Golden.ErrorsSpec ) where -import Cardano.Api -import Cardano.Api.Shelley -import Cardano.Binary as CBOR +import Cardano.Api +import Cardano.Api.Shelley + +import Cardano.Binary as CBOR import qualified Cardano.Crypto.Seed as Crypto import qualified Cardano.Ledger.Alonzo.Plutus.TxInfo as Ledger import qualified Cardano.Ledger.Api.Era as Ledger import qualified Cardano.Ledger.Coin as L -import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Ledger.Crypto (StandardCrypto) import qualified Cardano.Ledger.Plutus.Language as Plutus +import qualified PlutusCore.Evaluation.Machine.CostModelInterface as Plutus +import qualified PlutusLedgerApi.Common as Plutus hiding (PlutusV2) + import qualified Codec.Binary.Bech32 as Bech32 -import Control.Error.Util (hush) +import Control.Error.Util (hush) import qualified Data.Aeson as Aeson -import Data.ByteString (ByteString) +import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as LBS -import Data.Data +import Data.Data import qualified Data.Map as Map -import Data.Maybe (fromJust) +import Data.Maybe (fromJust) import qualified Data.Set as Set -import Data.Text (Text) -import GHC.Stack (HasCallStack) -import qualified PlutusCore.Evaluation.Machine.CostModelInterface as Plutus -import qualified PlutusLedgerApi.Common as Plutus hiding (PlutusV2) +import Data.Text (Text) +import GHC.Stack (HasCallStack) + import qualified Test.Hedgehog.Golden.ErrorMessage as ErrorMessage -import Test.Tasty +import Test.Tasty seed1 :: ByteString seed1 = diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Crypto.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Crypto.hs index 80a886d743..2fa46796f4 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Crypto.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Crypto.hs @@ -12,15 +12,18 @@ module Test.Cardano.Api.Crypto ) where -import Cardano.Api.Crypto.Ed25519Bip32 (Ed25519Bip32DSIGN, SignKeyDSIGN (..)) -import Cardano.Crypto.DSIGN -import Cardano.Crypto.Util (SignableRepresentation (..)) +import Cardano.Api.Crypto.Ed25519Bip32 (Ed25519Bip32DSIGN, SignKeyDSIGN (..)) + +import Cardano.Crypto.DSIGN +import Cardano.Crypto.Util (SignableRepresentation (..)) import qualified Cardano.Crypto.Wallet as CC -import Data.Proxy (Proxy (..)) -import Test.Crypto.Util -import Test.QuickCheck (Arbitrary (..), Gen, Property, (=/=), (===), (==>)) -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.QuickCheck (testProperty) + +import Data.Proxy (Proxy (..)) + +import Test.Crypto.Util +import Test.QuickCheck (Arbitrary (..), Gen, Property, (=/=), (===), (==>)) +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.QuickCheck (testProperty) -- -- The list of all tests diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/EpochLeadership.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/EpochLeadership.hs index ba01346cbb..a7ff8197a6 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/EpochLeadership.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/EpochLeadership.hs @@ -8,47 +8,43 @@ module Test.Cardano.Api.EpochLeadership ) where -import Cardano.Api - ( Key (verificationKeyHash) - , deterministicSigningKey - , getVerificationKey - ) -import Cardano.Api.Block (EpochNo (..), Hash (StakePoolKeyHash), SlotNo (..)) -import Cardano.Api.Eon.ShelleyBasedEra (ShelleyBasedEra (..)) -import Cardano.Api.Genesis (shelleyGenesisDefaults) -import Cardano.Api.GenesisParameters (EpochSize (..)) -import Cardano.Api.Ledger (KeyHash (..), StandardCrypto, toCBOR) -import Cardano.Api.LedgerState (currentEpochEligibleLeadershipSlots) -import Cardano.Api.Modes (ConsensusProtocol) -import Cardano.Api.Query - ( ProtocolState (..) - , SerialisedPoolDistribution (SerialisedPoolDistribution) - ) -import Cardano.Api.Shelley (Hash (VrfKeyHash), VrfKey, proxyToAsType, unStakePoolKeyHash) -import Cardano.Binary (ToCBOR, serialize) -import Cardano.Crypto.Seed (mkSeedFromBytes) -import Cardano.Ledger.Api.PParams (emptyPParams) -import Cardano.Ledger.BaseTypes (Nonce (..), WithOrigin (..)) -import Cardano.Ledger.Binary.Encoding (toByronCBOR) +import Cardano.Api (Key (verificationKeyHash), deterministicSigningKey, + getVerificationKey) +import Cardano.Api.Block (EpochNo (..), Hash (StakePoolKeyHash), SlotNo (..)) +import Cardano.Api.Eon.ShelleyBasedEra (ShelleyBasedEra (..)) +import Cardano.Api.Genesis (shelleyGenesisDefaults) +import Cardano.Api.GenesisParameters (EpochSize (..)) +import Cardano.Api.Ledger (KeyHash (..), StandardCrypto, toCBOR) +import Cardano.Api.LedgerState (currentEpochEligibleLeadershipSlots) +import Cardano.Api.Modes (ConsensusProtocol) +import Cardano.Api.Query (ProtocolState (..), + SerialisedPoolDistribution (SerialisedPoolDistribution)) +import Cardano.Api.Shelley (Hash (VrfKeyHash), VrfKey, proxyToAsType, unStakePoolKeyHash) + +import Cardano.Binary (ToCBOR, serialize) +import Cardano.Crypto.Seed (mkSeedFromBytes) +import Cardano.Ledger.Api.PParams (emptyPParams) +import Cardano.Ledger.BaseTypes (Nonce (..), WithOrigin (..)) +import Cardano.Ledger.Binary.Encoding (toByronCBOR) import qualified Cardano.Protocol.TPraos.API as API -import Cardano.Slotting.EpochInfo (EpochInfo (..)) -import Cardano.Slotting.Time (RelativeTime (..), mkSlotLength) +import Cardano.Slotting.EpochInfo (EpochInfo (..)) +import Cardano.Slotting.Time (RelativeTime (..), mkSlotLength) +import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus +import Ouroboros.Consensus.Protocol.TPraos (TPraosState (..)) +import Ouroboros.Consensus.Shelley.Ledger.Query.Types (IndividualPoolStake (..), + PoolDistr (..)) +import Ouroboros.Network.Block (Serialised (..)) + import qualified Data.Map as Map -import Data.Proxy (Proxy (..)) -import Data.Ratio ((%)) +import Data.Proxy (Proxy (..)) +import Data.Ratio ((%)) import qualified Data.Set as Set -import Data.Time.Clock (secondsToNominalDiffTime) +import Data.Time.Clock (secondsToNominalDiffTime) + import qualified Hedgehog as H import qualified Hedgehog.Extras as H -import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus -import Ouroboros.Consensus.Protocol.TPraos (TPraosState (..)) -import Ouroboros.Consensus.Shelley.Ledger.Query.Types - ( IndividualPoolStake (..) - , PoolDistr (..) - ) -import Ouroboros.Network.Block (Serialised (..)) -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) -- -- The list of all tests diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Eras.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Eras.hs index ecd05f9bd6..54a2927ced 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Eras.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Eras.hs @@ -5,14 +5,16 @@ module Test.Cardano.Api.Eras ) where -import Cardano.Api -import Cardano.Api.Orphans () -import Data.Aeson (ToJSON (..), decode, encode) -import Hedgehog (Property, forAll, property, (===)) +import Cardano.Api +import Cardano.Api.Orphans () + +import Data.Aeson (ToJSON (..), decode, encode) + +import Hedgehog (Property, forAll, property, (===)) import qualified Hedgehog as H import qualified Hedgehog.Gen as Gen -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) -------------------------------------------------------------------------------- -- Bounded instances diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/IO.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/IO.hs index dd49814c4e..b5339788e5 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/IO.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/IO.hs @@ -5,14 +5,16 @@ module Test.Cardano.Api.IO ) where -import Cardano.Api -import Cardano.Api.IO -import Hedgehog +import Cardano.Api +import Cardano.Api.IO + +import System.Directory (removeFile) + +import Hedgehog import qualified Hedgehog.Extras as H -import Hedgehog.Internal.Property -import System.Directory (removeFile) -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog +import Hedgehog.Internal.Property +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog prop_createVrfFileWithOwnerPermissions :: Property prop_createVrfFileWithOwnerPermissions = diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Json.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Json.hs index 11a7408f9e..50175923b8 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Json.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Json.hs @@ -6,15 +6,18 @@ module Test.Cardano.Api.Json ) where -import Cardano.Api.Orphans () -import Cardano.Api.Shelley -import Data.Aeson (eitherDecode, encode) -import Hedgehog (Property, forAll, tripping) +import Cardano.Api.Orphans () +import Cardano.Api.Shelley + +import Data.Aeson (eitherDecode, encode) + +import Test.Gen.Cardano.Api (genAlonzoGenesis) +import Test.Gen.Cardano.Api.Typed + +import Hedgehog (Property, forAll, tripping) import qualified Hedgehog as H -import Test.Gen.Cardano.Api (genAlonzoGenesis) -import Test.Gen.Cardano.Api.Typed -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) {- HLINT ignore "Use camelCase" -} diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/KeysByron.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/KeysByron.hs index 50f93526ea..28b0fc4571 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/KeysByron.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/KeysByron.hs @@ -5,14 +5,16 @@ module Test.Cardano.Api.KeysByron ) where -import Cardano.Api (AsType (AsByronKey, AsSigningKey), Key (deterministicSigningKey)) -import Hedgehog (Property) -import qualified Hedgehog as H -import Test.Cardano.Api.Typed.Orphans () +import Cardano.Api (AsType (AsByronKey, AsSigningKey), Key (deterministicSigningKey)) + +import Test.Cardano.Api.Typed.Orphans () import qualified Test.Gen.Cardano.Crypto.Seed as Gen -import Test.Hedgehog.Roundtrip.CBOR (trippingCbor) -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) + +import Hedgehog (Property) +import qualified Hedgehog as H +import Test.Hedgehog.Roundtrip.CBOR (trippingCbor) +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) {- HLINT ignore "Use camelCase" -} diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Ledger.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Ledger.hs index b2ceb9ce49..d6d50e0849 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Ledger.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Ledger.hs @@ -6,20 +6,25 @@ module Test.Cardano.Api.Ledger ) where -import Cardano.Api -import Cardano.Api.Shelley +import Cardano.Api +import Cardano.Api.Shelley + import qualified Cardano.Ledger.Api as L -import Cardano.Ledger.Api.Tx.Address -import Cardano.Ledger.Crypto -import Cardano.Ledger.SafeHash -import Control.Monad.Identity +import Cardano.Ledger.Api.Tx.Address +import Cardano.Ledger.Crypto +import Cardano.Ledger.SafeHash + +import Control.Monad.Identity + +import Test.Gen.Cardano.Api.Typed + +import Test.Cardano.Ledger.Core.Arbitrary () + import qualified Hedgehog as H -import Hedgehog.Gen.QuickCheck (arbitrary) -import Hedgehog.Internal.Property -import Test.Cardano.Ledger.Core.Arbitrary () -import Test.Gen.Cardano.Api.Typed -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) +import Hedgehog.Gen.QuickCheck (arbitrary) +import Hedgehog.Internal.Property +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) -- Keep this here to make sure serialiseAddr/deserialiseAddr are working. -- They are defined in the Shelley executable spec and have been wrong at diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Metadata.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Metadata.hs index 6c695fc794..2eda7fcf1f 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Metadata.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Metadata.hs @@ -9,22 +9,25 @@ module Test.Cardano.Api.Metadata ) where -import Cardano.Api +import Cardano.Api + import qualified Data.Aeson as Aeson -import Data.ByteString (ByteString) +import Data.ByteString (ByteString) import qualified Data.Map.Strict as Map -import Data.Maybe (mapMaybe) -import Data.Word (Word64) -import GHC.Stack -import Hedgehog (Gen, Property, (===)) +import Data.Maybe (mapMaybe) +import Data.Word (Word64) +import GHC.Stack +import Text.InterpolatedString.Perl6 + +import Test.Gen.Cardano.Api.Metadata + +import Hedgehog (Gen, Property, (===)) import qualified Hedgehog as H import qualified Hedgehog.Extras as H import qualified Hedgehog.Gen as Gen import qualified Hedgehog.Range as Range -import Test.Gen.Cardano.Api.Metadata -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) -import Text.InterpolatedString.Perl6 +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) -- ---------------------------------------------------------------------------- -- Golden / unit tests diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/ProtocolParameters.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/ProtocolParameters.hs index d459464f65..ef492838dd 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/ProtocolParameters.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/ProtocolParameters.hs @@ -10,30 +10,26 @@ module Test.Cardano.Api.ProtocolParameters ) where -import Cardano.Api - ( CardanoEra (..) - , ProtocolParametersConversionError - , inEonForEra - , prettyPrintJSON - ) -import Cardano.Api.Eon.ShelleyBasedEra (ShelleyBasedEra (..), ShelleyLedgerEra) -import Cardano.Api.Ledger (PParams (..)) -import Cardano.Api.ProtocolParameters - ( LedgerProtocolParameters (..) - , convertToLedgerProtocolParameters - , fromLedgerPParams - ) -import Control.Monad (void) -import Data.Aeson (FromJSON, Object, ToJSON, eitherDecode) +import Cardano.Api (CardanoEra (..), ProtocolParametersConversionError, inEonForEra, + prettyPrintJSON) +import Cardano.Api.Eon.ShelleyBasedEra (ShelleyBasedEra (..), ShelleyLedgerEra) +import Cardano.Api.Ledger (PParams (..)) +import Cardano.Api.ProtocolParameters (LedgerProtocolParameters (..), + convertToLedgerProtocolParameters, fromLedgerPParams) + +import Control.Monad (void) +import Data.Aeson (FromJSON, Object, ToJSON, eitherDecode) import qualified Data.Aeson.Key as Aeson import qualified Data.Aeson.KeyMap as Aeson import qualified Data.ByteString.Lazy as LBS -import Data.Foldable (foldl') -import Hedgehog (Gen, MonadTest, Property, forAll, property, success, (===)) -import Hedgehog.Extras (leftFail) -import Test.Gen.Cardano.Api.Typed (genProtocolParameters) -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) +import Data.Foldable (foldl') + +import Test.Gen.Cardano.Api.Typed (genProtocolParameters) + +import Hedgehog (Gen, MonadTest, Property, forAll, property, success, (===)) +import Hedgehog.Extras (leftFail) +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) -- Originally, cardano-api used a different type than cardano-ledger to represent -- protocol parameters. From conway on, we aim to unify those types and use PParams. @@ -133,7 +129,7 @@ data ValidatedSerializedPair era = ValidatedSerializedPair , serializedPParams :: LBS.ByteString -- ^ Serialized cardano-ledger's `PParams` as a ByteString. } - deriving (Show) + deriving Show -- | Produces a pair of a valid cardano-api's legacy ProtocolParameters and corresponding cardano-ledger's PParams by doing a round trip genValidSerializedPair diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Address.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Address.hs index 3aeed8b2d9..0f2ebe33aa 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Address.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Address.hs @@ -5,14 +5,18 @@ module Test.Cardano.Api.Typed.Address ) where -import Cardano.Api +import Cardano.Api + import qualified Data.Aeson as Aeson -import Hedgehog (Property) + +import Test.Gen.Cardano.Api.Typed (genAddressByron, genAddressShelley) + +import Test.Cardano.Api.Typed.Orphans () + +import Hedgehog (Property) import qualified Hedgehog as H -import Test.Cardano.Api.Typed.Orphans () -import Test.Gen.Cardano.Api.Typed (genAddressByron, genAddressShelley) -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) {- HLINT ignore "Use camelCase" -} diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Bech32.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Bech32.hs index 67c52739bb..5a3179fd69 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Bech32.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Bech32.hs @@ -3,12 +3,14 @@ module Test.Cardano.Api.Typed.Bech32 ) where -import Cardano.Api (AsType (AsShelleyAddress, AsStakeAddress)) -import Hedgehog (Property) -import Test.Gen.Cardano.Api.Typed (genAddressShelley, genStakeAddress) -import Test.Hedgehog.Roundtrip.Bech32 (roundtrip_Bech32) -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) +import Cardano.Api (AsType (AsShelleyAddress, AsStakeAddress)) + +import Test.Gen.Cardano.Api.Typed (genAddressShelley, genStakeAddress) + +import Hedgehog (Property) +import Test.Hedgehog.Roundtrip.Bech32 (roundtrip_Bech32) +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) prop_roundtrip_Address_Shelley :: Property prop_roundtrip_Address_Shelley = roundtrip_Bech32 AsShelleyAddress genAddressShelley diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/CBOR.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/CBOR.hs index 8f22768565..b11b54ff31 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/CBOR.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/CBOR.hs @@ -9,18 +9,22 @@ module Test.Cardano.Api.Typed.CBOR ) where -import Cardano.Api -import Cardano.Api.Shelley (AsType (..)) -import Data.Proxy (Proxy (..)) -import Hedgehog (Property, forAll, property, tripping) +import Cardano.Api +import Cardano.Api.Shelley (AsType (..)) + +import Data.Proxy (Proxy (..)) + +import Test.Gen.Cardano.Api.Typed + +import Test.Cardano.Api.Typed.Orphans () + +import Hedgehog (Property, forAll, property, tripping) import qualified Hedgehog as H import qualified Hedgehog.Gen as Gen -import Test.Cardano.Api.Typed.Orphans () -import Test.Gen.Cardano.Api.Typed -import Test.Hedgehog.Roundtrip.CBOR import qualified Test.Hedgehog.Roundtrip.CBOR as H -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) +import Test.Hedgehog.Roundtrip.CBOR +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) {- HLINT ignore "Use camelCase" -} diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Envelope.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Envelope.hs index 127244d8df..d006e51700 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Envelope.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Envelope.hs @@ -6,13 +6,16 @@ module Test.Cardano.Api.Typed.Envelope ) where -import Cardano.Api -import Hedgehog (Property) +import Cardano.Api + +import Test.Gen.Cardano.Api.Typed + +import Test.Cardano.Api.Typed.Orphans () + +import Hedgehog (Property) import qualified Hedgehog as H -import Test.Cardano.Api.Typed.Orphans () -import Test.Gen.Cardano.Api.Typed -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) {- HLINT ignore "Use camelCase" -} diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/JSON.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/JSON.hs index 548c9b9462..c1d9ab26ae 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/JSON.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/JSON.hs @@ -8,15 +8,19 @@ module Test.Cardano.Api.Typed.JSON ) where -import Cardano.Api -import Data.Aeson (eitherDecode, encode) -import Hedgehog (Property, forAll, tripping) +import Cardano.Api + +import Data.Aeson (eitherDecode, encode) + +import Test.Gen.Cardano.Api.Typed (genMaybePraosNonce, genProtocolParameters) + +import Test.Cardano.Api.Typed.Orphans () + +import Hedgehog (Property, forAll, tripping) import qualified Hedgehog as H import qualified Hedgehog.Gen as Gen -import Test.Cardano.Api.Typed.Orphans () -import Test.Gen.Cardano.Api.Typed (genMaybePraosNonce, genProtocolParameters) -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) {- HLINT ignore "Use camelCase" -} diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Ord.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Ord.hs index 43f6dc0332..a5c65ff096 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Ord.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Ord.hs @@ -3,14 +3,17 @@ module Test.Cardano.Api.Typed.Ord ) where -import Cardano.Api -import Cardano.Api.Shelley -import Hedgehog (Property, (===)) +import Cardano.Api +import Cardano.Api.Shelley + +import Test.Gen.Cardano.Api.Typed + +import Test.Cardano.Api.Metadata (genTxMetadataValue) + +import Hedgehog (Property, (===)) import qualified Hedgehog as H -import Test.Cardano.Api.Metadata (genTxMetadataValue) -import Test.Gen.Cardano.Api.Typed -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) {- HLINT ignore "Use camelCase" -} diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Orphans.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Orphans.hs index 3761894a19..f5b2cdf7d4 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Orphans.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Orphans.hs @@ -7,11 +7,13 @@ module Test.Cardano.Api.Typed.Orphans () where -import Cardano.Api.Shelley -import Cardano.Crypto.Hash hiding (Hash) -import Cardano.Crypto.KES -import Cardano.Crypto.Libsodium (SodiumHashAlgorithm) -import Test.Cardano.Crypto.Orphans () +import Cardano.Api.Shelley + +import Cardano.Crypto.Hash hiding (Hash) +import Cardano.Crypto.KES +import Cardano.Crypto.Libsodium (SodiumHashAlgorithm) + +import Test.Cardano.Crypto.Orphans () -- Signing Key instances diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/RawBytes.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/RawBytes.hs index 3d472869b1..b90f1c410d 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/RawBytes.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/RawBytes.hs @@ -6,13 +6,16 @@ module Test.Cardano.Api.Typed.RawBytes ) where -import Cardano.Api -import Hedgehog (Property) +import Cardano.Api + +import Test.Gen.Cardano.Api.Typed + +import Test.Cardano.Api.Typed.Orphans () + +import Hedgehog (Property) import qualified Hedgehog as H -import Test.Cardano.Api.Typed.Orphans () -import Test.Gen.Cardano.Api.Typed -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) {- HLINT ignore "Use camelCase" -} diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/TxBody.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/TxBody.hs index 734cb73d53..df5d28a139 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/TxBody.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/TxBody.hs @@ -5,16 +5,20 @@ module Test.Cardano.Api.Typed.TxBody ) where -import Cardano.Api -import Cardano.Api.Shelley (ReferenceScript (..), refScriptToShelleyScript) -import Data.Maybe (isJust) -import Data.Type.Equality (TestEquality (testEquality)) -import Hedgehog (MonadTest, Property, annotateShow, failure, (===)) +import Cardano.Api +import Cardano.Api.Shelley (ReferenceScript (..), refScriptToShelleyScript) + +import Data.Maybe (isJust) +import Data.Type.Equality (TestEquality (testEquality)) + +import Test.Gen.Cardano.Api.Typed (genTxBodyContent) + +import Test.Cardano.Api.Typed.Orphans () + +import Hedgehog (MonadTest, Property, annotateShow, failure, (===)) import qualified Hedgehog as H -import Test.Cardano.Api.Typed.Orphans () -import Test.Gen.Cardano.Api.Typed (genTxBodyContent) -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) {- HLINT ignore "Use camelCase" -} diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Value.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Value.hs index 2b51d8968e..1e85200b5f 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Value.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Typed/Value.hs @@ -3,23 +3,20 @@ module Test.Cardano.Api.Typed.Value ) where -import Cardano.Api - ( MaryEraOnwards (..) - , ShelleyBasedEra (..) - , ValueNestedBundle (..) - , ValueNestedRep (..) - , fromLedgerValue - , valueFromNestedRep - , valueToNestedRep - ) -import Data.Aeson (eitherDecode, encode) -import Data.List (groupBy, sort) +import Cardano.Api (MaryEraOnwards (..), ShelleyBasedEra (..), ValueNestedBundle (..), + ValueNestedRep (..), fromLedgerValue, valueFromNestedRep, valueToNestedRep) + +import Prelude + +import Data.Aeson (eitherDecode, encode) +import Data.List (groupBy, sort) import qualified Data.Map.Strict as Map -import Hedgehog (Property, forAll, property, tripping, (===)) -import Test.Gen.Cardano.Api.Typed (genAssetName, genValueDefault, genValueNestedRep) -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.Hedgehog (testProperty) -import Prelude + +import Test.Gen.Cardano.Api.Typed (genAssetName, genValueDefault, genValueNestedRep) + +import Hedgehog (Property, forAll, property, tripping, (===)) +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.Hedgehog (testProperty) prop_roundtrip_Value_JSON :: Property prop_roundtrip_Value_JSON = @@ -49,8 +46,8 @@ canonicalise = . (\(ValueNestedRep bundles) -> bundles) where samePolicyId - ValueNestedBundleAda {} - ValueNestedBundleAda {} = True + ValueNestedBundleAda{} + ValueNestedBundleAda{} = True samePolicyId (ValueNestedBundle pid _) (ValueNestedBundle pid' _) = pid == pid' @@ -68,7 +65,7 @@ canonicalise = ValueNestedBundle pid (Map.unionWith (<>) as as') mergeBundle _ _ = error "canonicalise.mergeBundle: impossible" - filterZeros b@ValueNestedBundleAda {} = b + filterZeros b@ValueNestedBundleAda{} = b filterZeros (ValueNestedBundle pid as) = ValueNestedBundle pid (Map.filter (/= 0) as) diff --git a/cardano-api/test/cardano-api-test/cardano-api-test.hs b/cardano-api/test/cardano-api-test/cardano-api-test.hs index 40511e5448..e31f26fe0c 100644 --- a/cardano-api/test/cardano-api-test/cardano-api-test.hs +++ b/cardano-api/test/cardano-api-test/cardano-api-test.hs @@ -1,7 +1,11 @@ module Main where -import Cardano.Crypto.Libsodium (sodiumInit) -import System.IO (BufferMode (LineBuffering), hSetBuffering, hSetEncoding, stdout, utf8) +import Cardano.Crypto.Libsodium (sodiumInit) + +import System.IO (BufferMode (LineBuffering), hSetBuffering, hSetEncoding, stdout, utf8) + +import qualified Test.Gen.Cardano.Api.Byron + import qualified Test.Cardano.Api.Crypto import qualified Test.Cardano.Api.EpochLeadership import qualified Test.Cardano.Api.Eras @@ -20,8 +24,8 @@ import qualified Test.Cardano.Api.Typed.Ord import qualified Test.Cardano.Api.Typed.RawBytes import qualified Test.Cardano.Api.Typed.TxBody import qualified Test.Cardano.Api.Typed.Value -import qualified Test.Gen.Cardano.Api.Byron -import Test.Tasty (TestTree, defaultMain, testGroup) + +import Test.Tasty (TestTree, defaultMain, testGroup) main :: IO () main = do