Skip to content

Commit

Permalink
Update to cardano-api 8.22.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Sep 27, 2023
1 parent d93346e commit c491c8d
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 61 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository cardano-haskell-packages
-- you need to run if you change them
index-state:
, hackage.haskell.org 2023-08-08T19:56:09Z
, cardano-haskell-packages 2023-09-26T01:42:03Z
, cardano-haskell-packages 2023-09-27T09:51:59Z

packages:
cardano-cli
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ library
, binary
, bytestring
, canonical-json
, cardano-api ^>= 8.21
, cardano-api ^>= 8.22
, cardano-binary
, cardano-crypto
, cardano-crypto-class ^>= 2.1.2
Expand Down
6 changes: 0 additions & 6 deletions cardano-cli/src/Cardano/CLI/Byron/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ import Cardano.CLI.Helpers
import Cardano.CLI.Types.Common
import qualified Cardano.Crypto.Hashing as Crypto
import qualified Cardano.Crypto.Signing as Crypto
import Ouroboros.Consensus.Byron.Ledger (ByronBlock)
import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr)

import Control.Monad.IO.Class (MonadIO (liftIO))
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, hoistEither, left)
import Data.Bifunctor (Bifunctor (..))
import qualified Data.ByteString.Char8 as BS
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.IO as Text
import qualified Data.Text.Lazy.Builder as Builder
import qualified Data.Text.Lazy.IO as TL
Expand All @@ -46,7 +43,6 @@ data ByronClientCmdError
| ByronCmdHelpersError !HelpersError
| ByronCmdKeyFailure !ByronKeyFailure
| ByronCmdTxError !ByronTxError
| ByronCmdTxSubmitError !(ApplyTxErr ByronBlock)
| ByronCmdUpdateProposalError !ByronUpdateProposalError
| ByronCmdVoteError !ByronVoteError
deriving Show
Expand All @@ -59,8 +55,6 @@ renderByronClientCmdError err =
ByronCmdHelpersError e -> renderHelpersError e
ByronCmdKeyFailure e -> renderByronKeyFailure e
ByronCmdTxError e -> renderByronTxError e
ByronCmdTxSubmitError e ->
"Error while submitting Byron tx: " <> Text.pack (show e)
ByronCmdUpdateProposalError e -> renderByronUpdateProposalError e
ByronCmdVoteError e -> renderByronVoteError e

Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ runTxBuildRawCmd
txMetadata mLedgerPParams mProp

let noWitTx = makeSignedTransaction [] txBody
lift (getIsCardanoEraConstraint era $ writeTxFileTextEnvelopeCddl out noWitTx)
lift (cardanoEraConstraints era $ writeTxFileTextEnvelopeCddl out noWitTx)
& onLeft (left . TxCmdWriteFileError)


Expand Down Expand Up @@ -466,7 +466,7 @@ runTxBuildRaw era
}

first TxCmdTxBodyError $
getIsCardanoEraConstraint era $ createAndValidateTransactionBody txBodyContent
cardanoEraConstraints era $ createAndValidateTransactionBody txBodyContent

runTxBuild :: ()
=> CardanoEra era
Expand Down
21 changes: 7 additions & 14 deletions cardano-cli/src/Cardano/CLI/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,11 @@ readTxMetadata :: CardanoEra era
-> [MetadataFile]
-> IO (Either MetadataError (TxMetadataInEra era))
readTxMetadata _ _ [] = return $ Right TxMetadataNone
readTxMetadata era schema files =
case txMetadataSupportedInEra era of
Nothing ->
return . Left
. MetadataErrorNotAvailableInEra
$ getIsCardanoEraConstraint era $ AnyCardanoEra era
Just supported -> do
let exceptAllTxMetadata = mapM (readFileTxMetadata schema) files
eAllTxMetaData <- runExceptT exceptAllTxMetadata
return $ do
metaData <- eAllTxMetaData
Right $ TxMetadataInEra supported $ mconcat metaData
readTxMetadata era schema files = cardanoEraConstraints era $ runExceptT $ do
supported <- maybeEonInEra era
& hoistMaybe (MetadataErrorNotAvailableInEra $ AnyCardanoEra era)
metadata <- mapM (readFileTxMetadata schema) files
pure $ TxMetadataInEra supported $ mconcat metadata

readFileTxMetadata
:: TxMetadataJsonSchema
Expand Down Expand Up @@ -318,7 +311,7 @@ readScriptWitness era (PlutusReferenceScriptWitnessFiles refTxIn
caseByronToAlonzoOrBabbageEraOnwards
( const $ left
$ ScriptWitnessErrorReferenceScriptsNotSupportedInEra
$ getIsCardanoEraConstraint era (AnyCardanoEra era)
$ cardanoEraConstraints era (AnyCardanoEra era)
)
( const $
case scriptLanguageSupportedInEra era anyScriptLanguage of
Expand Down Expand Up @@ -347,7 +340,7 @@ readScriptWitness era (SimpleReferenceScriptWitnessFiles refTxIn
caseByronToAlonzoOrBabbageEraOnwards
( const $ left
$ ScriptWitnessErrorReferenceScriptsNotSupportedInEra
$ getIsCardanoEraConstraint era (AnyCardanoEra era)
$ cardanoEraConstraints era (AnyCardanoEra era)
)
( const $
case scriptLanguageSupportedInEra era anyScriptLanguage of
Expand Down
61 changes: 27 additions & 34 deletions cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import Cardano.Api.Shelley
import Prelude

import Data.Bifunctor (first)
import Data.Function
import qualified Data.Map.Strict as Map
import Data.Maybe
import qualified Data.Text as Text
Expand Down Expand Up @@ -83,11 +84,11 @@ validateTxFee era = \case
Nothing ->
caseByronOrShelleyBasedEra
(pure . TxFeeImplicit)
(const $ Left . TxFeatureImplicitFeesE $ getIsCardanoEraConstraint era $ AnyCardanoEra era)
(const $ Left . TxFeatureImplicitFeesE $ cardanoEraConstraints era $ AnyCardanoEra era)
era
Just fee ->
caseByronOrShelleyBasedEra
(const $ Left . TxFeatureExplicitFeesE $ getIsCardanoEraConstraint era $ AnyCardanoEra era)
(const $ Left . TxFeatureExplicitFeesE $ cardanoEraConstraints era $ AnyCardanoEra era)
(\w -> pure (TxFeeExplicit w fee))
era

Expand All @@ -107,7 +108,7 @@ validateTxTotalCollateral era (Just coll) =
case totalAndReturnCollateralSupportedInEra era of
Just supp -> return $ TxTotalCollateral supp coll
Nothing -> Left $ TxTotalCollateralNotSupported
$ getIsCardanoEraConstraint era
$ cardanoEraConstraints era
$ AnyCardanoEra era

newtype TxReturnCollateralValidationError
Expand All @@ -126,7 +127,7 @@ validateTxReturnCollateral era (Just retColTxOut) = do
case totalAndReturnCollateralSupportedInEra era of
Just supp -> return $ TxReturnCollateral supp retColTxOut
Nothing -> Left $ TxReturnCollateralNotSupported
$ getIsCardanoEraConstraint era
$ cardanoEraConstraints era
$ AnyCardanoEra era

newtype TxValidityLowerBoundValidationError
Expand All @@ -145,7 +146,7 @@ validateTxValidityLowerBound _ Nothing = return TxValidityNoLowerBound
validateTxValidityLowerBound era (Just slot) =
case validityLowerBoundSupportedInEra era of
Nothing -> Left $ TxValidityLowerBoundNotSupported
$ getIsCardanoEraConstraint era
$ cardanoEraConstraints era
$ AnyCardanoEra era
Just supported -> return (TxValidityLowerBound supported slot)

Expand All @@ -164,13 +165,13 @@ validateTxValidityUpperBound
validateTxValidityUpperBound era Nothing =
case validityNoUpperBoundSupportedInEra era of
Nothing -> Left $ TxValidityUpperBoundNotSupported
$ getIsCardanoEraConstraint era
$ cardanoEraConstraints era
$ AnyCardanoEra era
Just supported -> return (TxValidityNoUpperBound supported)
validateTxValidityUpperBound era (Just slot) =
case validityUpperBoundSupportedInEra era of
Nothing -> Left $ TxValidityUpperBoundNotSupported
$ getIsCardanoEraConstraint era
$ cardanoEraConstraints era
$ AnyCardanoEra era
Just supported -> return (TxValidityUpperBound supported slot)

Expand All @@ -193,7 +194,7 @@ validateTxAuxScripts _ [] = return TxAuxScriptsNone
validateTxAuxScripts era scripts =
case auxScriptsSupportedInEra era of
Nothing -> Left $ TxAuxScriptsNotSupportedInEra
$ getIsCardanoEraConstraint era
$ cardanoEraConstraints era
$ AnyCardanoEra era
Just supported -> do
scriptsInEra <- mapM (first TxAuxScriptsLanguageError . validateScriptSupportedInEra era) scripts
Expand All @@ -215,7 +216,7 @@ validateRequiredSigners _ [] = return TxExtraKeyWitnessesNone
validateRequiredSigners era reqSigs =
case extraKeyWitnessesSupportedInEra era of
Nothing -> Left $ TxRequiredSignersValidationError
$ getIsCardanoEraConstraint era
$ cardanoEraConstraints era
$ AnyCardanoEra era
Just supported -> return $ TxExtraKeyWitnesses supported reqSigs

Expand All @@ -233,14 +234,11 @@ validateTxWithdrawals
-> [(StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))]
-> Either TxWithdrawalsValidationError (TxWithdrawals BuildTx era)
validateTxWithdrawals _ [] = return TxWithdrawalsNone
validateTxWithdrawals era withdrawals =
case withdrawalsSupportedInEra era of
Nothing -> Left $ TxWithdrawalsNotSupported
$ getIsCardanoEraConstraint era
$ AnyCardanoEra era
Just supported -> do
let convWithdrawals = map convert withdrawals
return (TxWithdrawals supported convWithdrawals)
validateTxWithdrawals era withdrawals = do
supported <- maybeEonInEra era
& maybe (cardanoEraConstraints era $ Left . TxWithdrawalsNotSupported $ AnyCardanoEra era) Right
let convWithdrawals = map convert withdrawals
pure $ TxWithdrawals supported convWithdrawals
where
convert
:: (StakeAddress, Lovelace, Maybe (ScriptWitness WitCtxStake era))
Expand All @@ -265,15 +263,12 @@ validateTxCertificates
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> Either TxCertificatesValidationError (TxCertificates BuildTx era)
validateTxCertificates _ [] = return TxCertificatesNone
validateTxCertificates era certsAndScriptWitnesses =
case certificatesSupportedInEra era of
Nothing -> Left $ TxCertificatesValidationNotSupported
$ getIsCardanoEraConstraint era
$ AnyCardanoEra era
Just supported -> do
let certs = map fst certsAndScriptWitnesses
reqWits = Map.fromList $ mapMaybe convert certsAndScriptWitnesses
return $ TxCertificates supported certs $ BuildTxWith reqWits
validateTxCertificates era certsAndScriptWitnesses = cardanoEraConstraints era $ do
supported <- maybeEonInEra era
& maybe (Left . TxCertificatesValidationNotSupported $ AnyCardanoEra era) Right
let certs = map fst certsAndScriptWitnesses
reqWits = Map.fromList $ mapMaybe convert certsAndScriptWitnesses
pure $ TxCertificates supported certs $ BuildTxWith reqWits
where
-- We get the stake credential witness for a certificate that requires it.
-- NB: Only stake address deregistration and delegation requires
Expand Down Expand Up @@ -316,7 +311,7 @@ validateProtocolParameters _ Nothing = return (BuildTxWith Nothing)
validateProtocolParameters era (Just pparams) =
case cardanoEraStyle era of
LegacyByronEra -> Left $ ProtocolParametersNotSupported
$ getIsCardanoEraConstraint era
$ cardanoEraConstraints era
$ AnyCardanoEra era
ShelleyBasedEra _ -> return . BuildTxWith $ Just pparams

Expand All @@ -333,12 +328,10 @@ validateTxUpdateProposal
-> Maybe UpdateProposal
-> Either TxUpdateProposalValidationError (TxUpdateProposal era)
validateTxUpdateProposal _ Nothing = return TxUpdateProposalNone
validateTxUpdateProposal era (Just prop) =
case updateProposalSupportedInEra era of
Nothing -> Left $ TxUpdateProposalNotSupported
$ getIsCardanoEraConstraint era
$ AnyCardanoEra era
Just supported -> return $ TxUpdateProposal supported prop
validateTxUpdateProposal era (Just prop) = do
supported <- maybeEonInEra era
& maybe (cardanoEraConstraints era $ Left . TxUpdateProposalNotSupported $ AnyCardanoEra era) Right
pure $ TxUpdateProposal supported prop

newtype TxScriptValidityValidationError
= ScriptValidityNotSupported AnyCardanoEra
Expand All @@ -356,6 +349,6 @@ validateTxScriptValidity _ Nothing = pure TxScriptValidityNone
validateTxScriptValidity era (Just scriptValidity) =
case txScriptValiditySupportedInCardanoEra era of
Nothing -> Left $ ScriptValidityNotSupported
$ getIsCardanoEraConstraint era
$ cardanoEraConstraints era
$ AnyCardanoEra era
Just supported -> pure $ TxScriptValidity supported scriptValidity
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c491c8d

Please sign in to comment.