diff --git a/cabal.project b/cabal.project index 6bc4498438..ae9faf56b0 100644 --- a/cabal.project +++ b/cabal.project @@ -20,6 +20,38 @@ active-repositories: , :rest , cardano-haskell-packages:override +-- BEGIN SRP STANZAS MANAGED BY STANZAMAN -- + +source-repository-package + type: git + location: https://github.com/IntersectMBO/ouroboros-network.git + tag: 65da1ad619473f9467d3336a6d6e9a2a8714913d + subdir: ouroboros-network + --sha256: 1r5y5px0kj4nhb65s9i7pr0sikxghfqwfkzmsgiql2maic4nglwi + +source-repository-package + type: git + location: https://github.com/IntersectMBO/ouroboros-consensus.git + tag: bca18fd361d8342bdbfb8a08366e86479677ce30 + subdir: . + --sha256: 11znnl9zk59bxr6dn76zrni6i0q32bqnlxqf4wprvxikg4r666pa + +source-repository-package + type: git + location: https://github.com/IntersectMBO/ouroboros-network.git + tag: 65da1ad619473f9467d3336a6d6e9a2a8714913d + subdir: cardano-diffusion + --sha256: 1r5y5px0kj4nhb65s9i7pr0sikxghfqwfkzmsgiql2maic4nglwi + +source-repository-package + type: git + location: https://github.com/IntersectMBO/ouroboros-network.git + tag: 65da1ad619473f9467d3336a6d6e9a2a8714913d + subdir: network-mux + --sha256: 1r5y5px0kj4nhb65s9i7pr0sikxghfqwfkzmsgiql2maic4nglwi + +-- END SRP STANZAS MANAGED BY STANZAMAN -- + packages: cardano-api cardano-api-gen diff --git a/cardano-api/cardano-api.cabal b/cardano-api/cardano-api.cabal index a2357b7cf5..99f6d2b80b 100644 --- a/cardano-api/cardano-api.cabal +++ b/cardano-api/cardano-api.cabal @@ -243,6 +243,7 @@ library Cardano.Api.Experimental.Tx.Internal.Fee Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements Cardano.Api.Experimental.Tx.Internal.Type + Cardano.Api.Experimental.Tx.Internal.Validate Cardano.Api.Genesis.Internal Cardano.Api.Genesis.Internal.Parameters Cardano.Api.Governance.Internal.Action.ProposalProcedure diff --git a/cardano-api/src/Cardano/Api/Experimental.hs b/cardano-api/src/Cardano/Api/Experimental.hs index ae67b6203b..51c9f7a627 100644 --- a/cardano-api/src/Cardano/Api/Experimental.hs +++ b/cardano-api/src/Cardano/Api/Experimental.hs @@ -40,6 +40,7 @@ module Cardano.Api.Experimental , Era (..) , IsEra (..) , Some (..) + , InAnyEra (..) , LedgerEra , DeprecatedEra (..) , eraToSbe @@ -95,6 +96,11 @@ module Cardano.Api.Experimental , makeDrepUpdateCertificate , makeStakeAddressAndDRepDelegationCertificate + -- ** Validation + , TxValidationResult (..) + , QueryValidateTxError (..) + , validateTx + -- * Data family instances , AsType (..) diff --git a/cardano-api/src/Cardano/Api/Experimental/Era.hs b/cardano-api/src/Cardano/Api/Experimental/Era.hs index 47e42cb644..f363b96761 100644 --- a/cardano-api/src/Cardano/Api/Experimental/Era.hs +++ b/cardano-api/src/Cardano/Api/Experimental/Era.hs @@ -20,6 +20,7 @@ module Cardano.Api.Experimental.Era , Era (..) , IsEra (..) , Some (..) + , InAnyEra (..) , Inject (..) , Convert (..) , LedgerEra @@ -93,6 +94,11 @@ data Some (f :: k -> Type) where => f a -> Some f +-- | Pair an era witness with a value indexed by that era, +-- hiding the era type parameter existentially. +data InAnyEra f where + InAnyEra :: IsEra era => Era era -> f era -> InAnyEra f + -- | Represents the latest Cardano blockchain eras, including -- the one currently on mainnet and the upcoming one. -- diff --git a/cardano-api/src/Cardano/Api/Experimental/Tx.hs b/cardano-api/src/Cardano/Api/Experimental/Tx.hs index f67964e269..2281cf1ff5 100644 --- a/cardano-api/src/Cardano/Api/Experimental/Tx.hs +++ b/cardano-api/src/Cardano/Api/Experimental/Tx.hs @@ -3,7 +3,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} -{-# LANGUAGE InstanceSigs #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} @@ -205,6 +205,11 @@ module Cardano.Api.Experimental.Tx , TxBodyErrorAutoBalance (..) , TxFeeEstimationError (..) + -- * Validation + , TxValidationResult (..) + , QueryValidateTxError (..) + , validateTx + -- ** Internal functions , extractExecutionUnits , getTxScriptWitnessRequirements @@ -225,28 +230,36 @@ import Cardano.Api.Experimental.Tx.Internal.BodyContent.New import Cardano.Api.Experimental.Tx.Internal.Fee import Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements import Cardano.Api.Experimental.Tx.Internal.Type -import Cardano.Api.HasTypeProxy (HasTypeProxy (..), Proxy, asType) +import Cardano.Api.Experimental.Tx.Internal.Validate (QueryValidateTxError (..), queryValidateTx) import Cardano.Api.Ledger.Internal.Reexport qualified as L +import Cardano.Api.Network.IPC (LocalStateQueryExpr) import Cardano.Api.Plutus.Internal.Script qualified as Api import Cardano.Api.Pretty (docToString, pretty) -import Cardano.Api.ProtocolParameters -import Cardano.Api.Serialise.Raw - ( SerialiseAsRawBytes (..) - , SerialiseAsRawBytesError (SerialiseAsRawBytesError) +import Cardano.Api.Query.Internal.Expr + ( queryEraHistory + , queryProtocolParameters + , querySystemStart + , queryUtxo + ) +import Cardano.Api.Query.Internal.Type.QueryInMode + ( QueryInMode + , QueryUTxOFilter (..) + , toLedgerEpochInfo + , toLedgerUTxO ) import Cardano.Api.Tx.Internal.Body qualified as Api +import Cardano.Api.Tx.Internal.Fee (EvalTxExecutionUnitsLog, ScriptExecutionError) import Cardano.Api.Tx.Internal.Sign import Cardano.Crypto.Hash qualified as Hash import Cardano.Ledger.Alonzo.Tx qualified as L import Cardano.Ledger.Api qualified as L -import Cardano.Ledger.Binary qualified as Ledger import Cardano.Ledger.Core qualified as Ledger import Cardano.Ledger.Hashes qualified as L hiding (Hash) +import Cardano.Ledger.Shelley.API (ApplyTxError) -import Control.Exception (displayException) -import Data.Bifunctor (bimap) -import Data.ByteString.Lazy (fromStrict) +import Data.Bifunctor (bimap, first) +import Data.List.NonEmpty qualified as NE import Data.Map.Strict (Map) import Data.Map.Strict qualified as Map import Data.Set qualified as Set @@ -279,39 +292,6 @@ makeKeyWitness era (UnsignedTx unsignedTx) wsk = signature = makeShelleySignature txhash sk in L.WitVKey vk signature --- | A transaction that has been witnesssed -data SignedTx era - = L.EraTx (LedgerEra era) => SignedTx (Ledger.Tx Ledger.TopTx (LedgerEra era)) - -deriving instance Eq (SignedTx era) - -deriving instance Show (SignedTx era) - -instance HasTypeProxy era => HasTypeProxy (SignedTx era) where - data AsType (SignedTx era) = AsSignedTx (AsType era) - proxyToAsType :: Proxy (SignedTx era) -> AsType (SignedTx era) - proxyToAsType _ = AsSignedTx (asType @era) - -instance - ( HasTypeProxy era - , L.EraTx (LedgerEra era) - ) - => SerialiseAsRawBytes (SignedTx era) - where - serialiseToRawBytes (SignedTx tx) = - Ledger.serialize' (Ledger.eraProtVerHigh @(LedgerEra era)) tx - deserialiseFromRawBytes _ = - bimap wrapError SignedTx - . Ledger.decodeFullAnnotator - (Ledger.eraProtVerHigh @(LedgerEra era)) - "SignedTx" - Ledger.decCBOR - . fromStrict - where - wrapError - :: Ledger.DecoderError -> SerialiseAsRawBytesError - wrapError = SerialiseAsRawBytesError . displayException - signTx :: Era era -> [L.BootstrapWitness] @@ -380,3 +360,90 @@ purposeAsIxItemToAsIx -> L.PlutusPurpose L.AsIx (LedgerEra era) purposeAsIxItemToAsIx purpose = obtainCommonConstraints (useEra @era) $ L.hoistPlutusPurpose L.toAsIx purpose + +data TxValidationResult era = TxValidationResult + { phase1Result :: Either (ApplyTxError (LedgerEra era)) () + , phase2Result + :: Map + Api.ScriptWitnessIndex + (Either ScriptExecutionError (EvalTxExecutionUnitsLog, Api.ExecutionUnits)) + } + +deriving instance Show (ApplyTxError (LedgerEra era)) => Show (TxValidationResult era) + +validateTx + :: forall era block point r + . IsEra era + => SignedTx era + -> LocalStateQueryExpr + block + point + QueryInMode + r + IO + (Either QueryValidateTxError (TxValidationResult era)) +validateTx stx@(SignedTx ledgerTx) = + obtainCommonConstraints (useEra @era) $ do + let sbe = convert (useEra @era) + ePhase1 <- queryValidateTx stx + + eSystemStart <- querySystemStart + eEraHistory <- queryEraHistory + ePparams <- queryProtocolParameters sbe + let relevantTxIns = + Set.map Api.fromShelleyTxIn (ledgerTx ^. L.bodyTxL . L.allInputsTxBodyF) + eUtxo <- queryUtxo sbe (QueryUTxOByTxIn relevantTxIns) + + return $ do + phase1 <- ePhase1 + systemStart <- first QueryValidateTxUnsupportedNtcVersion eSystemStart + eraHistory <- first QueryValidateTxUnsupportedNtcVersion eEraHistory + pparams <- + first QueryValidateTxUnsupportedNtcVersion ePparams + >>= first QueryValidateTxEraMismatch + utxo <- + first QueryValidateTxUnsupportedNtcVersion eUtxo + >>= first QueryValidateTxEraMismatch + + let ledgerUtxo = toLedgerUTxO sbe utxo + ledgerEpochInfo = toLedgerEpochInfo eraHistory + phase2 = + evaluateTransactionExecutionUnits + systemStart + ledgerEpochInfo + pparams + ledgerUtxo + ledgerTx + + let phase1Filtered = filterScriptFailures (useEra @era) phase1 + Right $ TxValidationResult phase1Filtered phase2 + +filterScriptFailures + :: Era era + -> Either (ApplyTxError (LedgerEra era)) () + -> Either (ApplyTxError (LedgerEra era)) () +filterScriptFailures era = \case + Right () -> Right () + Left err -> case era of + DijkstraEra -> error "TODO Dijkstra: filterScriptFailures" + ConwayEra -> + let L.ConwayApplyTxError failures = err + isScript = \case + L.ConwayUtxowFailure (L.UtxoFailure (L.UtxosFailure{})) -> True + L.ConwayUtxowFailure{} -> False + L.ConwayCertsFailure{} -> False + L.ConwayGovFailure{} -> False + L.ConwayWdrlNotDelegatedToDRep{} -> False + L.ConwayTreasuryValueMismatch{} -> False + L.ConwayTxRefScriptsSizeTooBig{} -> False + L.ConwayMempoolFailure{} -> False + L.ConwayWithdrawalsMissingAccounts{} -> False + L.ConwayIncompleteWithdrawals{} -> False + in filterFailures L.ConwayApplyTxError isScript failures + +filterFailures + :: (NE.NonEmpty a -> b) -> (a -> Bool) -> NE.NonEmpty a -> Either b () +filterFailures wrap isScript failures = + case NE.nonEmpty (filter (not . isScript) (NE.toList failures)) of + Nothing -> Right () + Just remaining -> Left (wrap remaining) diff --git a/cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Type.hs b/cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Type.hs index 6b0571314d..77742fc1c1 100644 --- a/cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Type.hs +++ b/cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Type.hs @@ -14,10 +14,12 @@ module Cardano.Api.Experimental.Tx.Internal.Type ( UnsignedTx (..) + , SignedTx (..) ) where import Cardano.Api.Era.Internal.Core qualified as Api +import Cardano.Api.Experimental.Era (LedgerEra) import Cardano.Api.HasTypeProxy (HasTypeProxy (..), asType) import Cardano.Api.Ledger.Internal.Reexport qualified as L import Cardano.Api.ProtocolParameters @@ -98,4 +100,37 @@ instance deriving instance Eq (UnsignedTx era) +-- | A transaction that has been witnessed +data SignedTx era + = L.EraTx (LedgerEra era) => SignedTx (Ledger.Tx Ledger.TopTx (LedgerEra era)) + +deriving instance Eq (SignedTx era) + +deriving instance Show (SignedTx era) + +instance HasTypeProxy era => HasTypeProxy (SignedTx era) where + data AsType (SignedTx era) = AsSignedTx (AsType era) + proxyToAsType :: Proxy (SignedTx era) -> AsType (SignedTx era) + proxyToAsType _ = AsSignedTx (asType @era) + +instance + ( HasTypeProxy era + , L.EraTx (LedgerEra era) + ) + => SerialiseAsRawBytes (SignedTx era) + where + serialiseToRawBytes (SignedTx tx) = + Ledger.serialize' (Ledger.eraProtVerHigh @(LedgerEra era)) tx + deserialiseFromRawBytes _ = + bimap wrapError SignedTx + . Ledger.decodeFullAnnotator + (Ledger.eraProtVerHigh @(LedgerEra era)) + "SignedTx" + Ledger.decCBOR + . fromStrict + where + wrapError + :: Ledger.DecoderError -> SerialiseAsRawBytesError + wrapError = SerialiseAsRawBytesError . displayException + deriving instance Show (UnsignedTx era) diff --git a/cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Validate.hs b/cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Validate.hs new file mode 100644 index 0000000000..f3ed0b52b8 --- /dev/null +++ b/cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Validate.hs @@ -0,0 +1,47 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeApplications #-} + +module Cardano.Api.Experimental.Tx.Internal.Validate + ( queryValidateTx + , QueryValidateTxError (..) + ) +where + +import Cardano.Api.Era.Internal.Eon.Convert (convert) +import Cardano.Api.Experimental.Era (IsEra, LedgerEra, obtainCommonConstraints, useEra) +import Cardano.Api.Experimental.Tx.Internal.Type (SignedTx (..)) +import Cardano.Api.Network.IPC (LocalStateQueryExpr) +import Cardano.Api.Network.IPC.Internal.Version (UnsupportedNtcVersionError) +import Cardano.Api.Query.Internal.Expr +import Cardano.Api.Query.Internal.Type.QueryInMode +import Cardano.Api.Tx.Internal.Sign (Tx (..)) + +import Cardano.Ledger.Shelley.API (ApplyTxError) +import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (EraMismatch) + +data QueryValidateTxError + = QueryValidateTxUnsupportedNtcVersion UnsupportedNtcVersionError + | QueryValidateTxEraMismatch EraMismatch + deriving Show + +queryValidateTx + :: forall era block point r + . IsEra era + => SignedTx era + -> LocalStateQueryExpr + block + point + QueryInMode + r + IO + (Either QueryValidateTxError (Either (ApplyTxError (LedgerEra era)) ())) +queryValidateTx (SignedTx ledgerTx) = obtainCommonConstraints (useEra @era) $ do + let tx = ShelleyTx (convert (useEra @era)) ledgerTx + result <- querySbe (useEra @era) (QueryValidateTx tx) + return $ case result of + Left err -> Left (QueryValidateTxUnsupportedNtcVersion err) + Right (Left mismatch) -> Left (QueryValidateTxEraMismatch mismatch) + Right (Right r) -> Right r diff --git a/cardano-api/src/Cardano/Api/Ledger/Internal/Reexport.hs b/cardano-api/src/Cardano/Api/Ledger/Internal/Reexport.hs index 6c92113e0b..c33dfba1ab 100644 --- a/cardano-api/src/Cardano/Api/Ledger/Internal/Reexport.hs +++ b/cardano-api/src/Cardano/Api/Ledger/Internal/Reexport.hs @@ -46,6 +46,7 @@ module Cardano.Api.Ledger.Internal.Reexport -- Core , Addr , Coin (..) + , DeltaCoin (..) , Compactible (..) , partialCompactFL , toCompactPartial @@ -71,6 +72,7 @@ module Cardano.Api.Ledger.Internal.Reexport , Val (..) , addDeltaCoin , castSafeHash + , coinTxOutL , getScriptsNeeded , mkBasicTxOut , toDeltaCoin @@ -84,6 +86,22 @@ module Cardano.Api.Ledger.Internal.Reexport -- Dijkstra , DijkstraPlutusPurpose (..) -- Conway + , ApplyTxError (..) + , ConwayLedgerPredFailure (..) + , ConwayUtxowPredFailure (..) + , ConwayUtxoPredFailure (..) + , ConwayCertsPredFailure (..) + , ConwayCertPredFailure (..) + , ConwayDelegPredFailure (..) + , ConwayGovCertPredFailure (..) + , ConwayGovPredFailure (..) + , ConwayUtxosPredFailure (..) + , ShelleyPoolPredFailure (..) + , TagMismatchDescription (..) + , FailureDescription (..) + , CollectError (..) + , IsValid (..) + , Withdrawals (..) , Anchor (..) , Committee (..) , Delegatee (..) @@ -148,6 +166,7 @@ module Cardano.Api.Ledger.Internal.Reexport , AlonzoEraTxWits (..) , AlonzoPlutusPurpose (..) , AlonzoScriptsNeeded (..) + , AsItem (..) , AsIx (..) , CoinPerWord (..) , Data (..) @@ -179,6 +198,8 @@ module Cardano.Api.Ledger.Internal.Reexport , showTimelock , toAsIx -- Base + , Mismatch (..) + , Relation (..) , boundRational , unboundRational , DnsName @@ -201,12 +222,16 @@ module Cardano.Api.Ledger.Internal.Reexport -- Crypto , hashToBytes , hashFromBytes + , hashToTextAsHex , Crypto , StandardCrypto , ADDRHASH -- Slotting , EpochNo (..) -- SafeHash + , ScriptHash (..) + , DataHash + , TxAuxDataHash (..) , SafeHash , unsafeMakeSafeHash , extractHash @@ -215,13 +240,14 @@ module Cardano.Api.Ledger.Internal.Reexport ) where -import Cardano.Crypto.Hash.Class (hashFromBytes, hashToBytes) -import Cardano.Ledger.Address (AccountAddress (..), Addr (..)) +import Cardano.Crypto.Hash.Class (hashFromBytes, hashToBytes, hashToTextAsHex) +import Cardano.Ledger.Address (AccountAddress (..), Addr (..), Withdrawals (..)) import Cardano.Ledger.Allegra.Scripts (AllegraEraScript (..), Timelock (..), showTimelock) import Cardano.Ledger.Alonzo.Core ( AlonzoEraScript (..) , AlonzoEraTxBody (..) , AlonzoEraTxWits (..) + , AsItem (..) , AsIx (..) , AsIxItem (AsIxItem) , CoinPerWord (..) @@ -244,6 +270,9 @@ import Cardano.Ledger.Alonzo.Scripts , plutusScriptLanguage , toAsIx ) +import Cardano.Ledger.Alonzo.Plutus.Evaluate (CollectError (..)) +import Cardano.Ledger.Alonzo.Rules (FailureDescription (..), TagMismatchDescription (..)) +import Cardano.Ledger.Alonzo.Tx (IsValid (..)) import Cardano.Ledger.Alonzo.TxWits (Redeemers (..), TxDats (..)) import Cardano.Ledger.Alonzo.UTxO (AlonzoScriptsNeeded (..)) import Cardano.Ledger.Api @@ -276,9 +305,11 @@ import Cardano.Ledger.BaseTypes , DnsName , EpochInterval (..) , Inject (..) + , Mismatch (..) , Network (..) , NonNegativeInterval , ProtVer (..) + , Relation (..) , StrictMaybe (..) , UnitInterval , Url @@ -306,7 +337,7 @@ import Cardano.Ledger.Binary , toPlainDecoder ) import Cardano.Ledger.Binary.Plain (Decoder, serializeAsHexText) -import Cardano.Ledger.Coin (Coin (..), addDeltaCoin, toDeltaCoin) +import Cardano.Ledger.Coin (Coin (..), DeltaCoin (..), addDeltaCoin, toDeltaCoin) import Cardano.Ledger.Compactible import Cardano.Ledger.Conway.Core ( DRepVotingThresholds (..) @@ -317,7 +348,19 @@ import Cardano.Ledger.Conway.Core , dvtPPTechnicalGroupL , dvtUpdateToConstitutionL ) +import Cardano.Ledger.Conway (ApplyTxError (..)) import Cardano.Ledger.Conway.Genesis (ConwayGenesis (..)) +import Cardano.Ledger.Conway.Rules + ( ConwayCertPredFailure (..) + , ConwayCertsPredFailure (..) + , ConwayDelegPredFailure (..) + , ConwayGovCertPredFailure (..) + , ConwayGovPredFailure (..) + , ConwayLedgerPredFailure (..) + , ConwayUtxoPredFailure (..) + , ConwayUtxosPredFailure (..) + , ConwayUtxowPredFailure (..) + ) import Cardano.Ledger.Conway.Governance ( Anchor (..) , Committee (..) @@ -350,6 +393,7 @@ import Cardano.Ledger.Core , PoolCert (..) , TxOut , Value + , coinTxOutL , fromEraCBOR , mkBasicTxOut , ppMinFeeAL @@ -362,7 +406,10 @@ import Cardano.Ledger.DRep (DRep (..), drepAnchorL, drepDepositL, drepExpiryL) import Cardano.Ledger.Dijkstra.Scripts (DijkstraPlutusPurpose (..)) import Cardano.Ledger.Hashes ( ADDRHASH + , DataHash , SafeHash + , ScriptHash (..) + , TxAuxDataHash (..) , castSafeHash , extractHash , unsafeMakeSafeHash @@ -394,6 +441,7 @@ import Cardano.Ledger.Shelley.API , WitVKey (..) , hashKey ) +import Cardano.Ledger.Shelley.Rules (ShelleyPoolPredFailure (..)) import Cardano.Ledger.Shelley.Genesis ( ShelleyGenesisStaking (..) , secondsToNominalDiffTimeMicro diff --git a/cardano-api/src/Cardano/Api/Query.hs b/cardano-api/src/Cardano/Api/Query.hs index 6b5f63039f..c10a78c809 100644 --- a/cardano-api/src/Cardano/Api/Query.hs +++ b/cardano-api/src/Cardano/Api/Query.hs @@ -89,6 +89,8 @@ module Cardano.Api.Query , queryProposals , queryStakePoolDefaultVote , queryLedgerConfig + , queryValidateTx + , QueryValidateTxError (..) , DelegationsAndRewards (..) , mergeDelegsAndRewards @@ -99,6 +101,7 @@ module Cardano.Api.Query ) where +import Cardano.Api.Experimental.Tx.Internal.Validate import Cardano.Api.Query.Internal.Convenience import Cardano.Api.Query.Internal.Expr import Cardano.Api.Query.Internal.Type.DebugLedgerState diff --git a/cardano-api/src/Cardano/Api/Query/Internal/Expr.hs b/cardano-api/src/Cardano/Api/Query/Internal/Expr.hs index 53cdf55d44..2e4a778e26 100644 --- a/cardano-api/src/Cardano/Api/Query/Internal/Expr.hs +++ b/cardano-api/src/Cardano/Api/Query/Internal/Expr.hs @@ -43,6 +43,7 @@ module Cardano.Api.Query.Internal.Expr , queryStakePoolDefaultVote , queryLedgerConfig , queryDRepDelegations + , querySbe ) where diff --git a/cardano-api/src/Cardano/Api/Query/Internal/Type/QueryInMode.hs b/cardano-api/src/Cardano/Api/Query/Internal/Type/QueryInMode.hs index e467998d74..4efce94e8f 100644 --- a/cardano-api/src/Cardano/Api/Query/Internal/Type/QueryInMode.hs +++ b/cardano-api/src/Cardano/Api/Query/Internal/Type/QueryInMode.hs @@ -87,6 +87,7 @@ import Cardano.Api.Serialise.TextEnvelope.Internal , TextEnvelopeType ) import Cardano.Api.Tx.Internal.Body +import Cardano.Api.Tx.Internal.Sign (Tx (..)) import Cardano.Api.UTxO (UTxO (..)) import Cardano.Binary qualified as CBOR @@ -342,6 +343,9 @@ data QueryInShelleyBasedEra era result where GetDRepDelegations :: Set Ledger.DRep -> QueryInShelleyBasedEra era (Map Ledger.DRep (Set (Ledger.Credential Ledger.Staking))) + QueryValidateTx + :: Tx era + -> QueryInShelleyBasedEra era (Either (Ledger.ApplyTxError (ShelleyLedgerEra era)) ()) deriving instance Show (QueryInShelleyBasedEra era result) @@ -576,7 +580,7 @@ toConsensusQueryShelleyBased . HasCallStack => ConsensusBlockForEra era ~ Consensus.ShelleyBlock protocol (ShelleyLedgerEra era) => Consensus.CardanoBlock StandardCrypto ~ block - => L.EraGov (ShelleyLedgerEra era) + => Consensus.ShelleyCompatible protocol (ShelleyLedgerEra era) => ShelleyBasedEra era -> QueryInShelleyBasedEra era result -> Some (Consensus.Query block) @@ -746,6 +750,8 @@ toConsensusQueryShelleyBased sbe = \case (consensusQueryInEraInMode era (Consensus.GetDRepDelegations dreps)) ) sbe + QueryValidateTx (ShelleyTx _ tx) -> + Some (consensusQueryInEraInMode era (Consensus.ValidateTx (Consensus.mkShelleyTx tx))) where era = toCardanoEra sbe @@ -1075,6 +1081,11 @@ fromConsensusQueryResultShelleyBased sbe sbeQuery q' r' = Consensus.GetDRepDelegations{} -> r' _ -> fromConsensusQueryResultMismatch + QueryValidateTx{} -> + case q' of + Consensus.ValidateTx{} -> + r' + _ -> fromConsensusQueryResultMismatch -- | This should /only/ happen if we messed up the mapping in 'toConsensusQuery' -- and 'fromConsensusQueryResult' so they are inconsistent with each other. diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Cip129.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Cip129.hs index 2fded15406..9a9f61d22f 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Cip129.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Cip129.hs @@ -11,7 +11,6 @@ import Cardano.Api import Cardano.Api.Ledger qualified as L import Cardano.Ledger.Api.Governance qualified as Gov -import Cardano.Ledger.Core qualified as L import Data.Text qualified as T import GHC.Stack