Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cardano-api: 8.46 -> 9.1 #34

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ repository cardano-haskell-packages

-- See CONTRIBUTING.adoc for how to update index-state
index-state:
, hackage.haskell.org 2024-06-12T10:10:17Z
, cardano-haskell-packages 2024-06-12T10:10:17Z
, hackage.haskell.org 2024-09-26T12:18:58Z
, cardano-haskell-packages 2024-09-25T16:01:20Z

packages: plutus-ledger
plutus-script-utils
Expand Down Expand Up @@ -45,14 +45,3 @@ package cardano-api
optimization: False
package cardano-crypto-praos
flags: -external-libsodium-vrf

-- This is quickcheck-contractmodel's HEAD of the Conway branch:
-- https://github.com/input-output-hk/quickcheck-contractmodel/tree/Conway
source-repository-package
type: git
location: https://github.com/input-output-hk/quickcheck-contractmodel
tag: b19a7689a0d40ba3c7f91da87ef5fbcf20f3926c
--sha256: sha256-ronNW9uJoleclzLjRJhDWdWd9Dso2XSnUl4m3/2eb2k=
subdir:
quickcheck-contractmodel
quickcheck-threatmodel
4 changes: 2 additions & 2 deletions cardano-node-emulator/cardano-node-emulator.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ library
-- Other IOG dependencies
--------------------------
build-depends:
, cardano-api:{cardano-api, gen, internal} ^>=8.46
, cardano-api:{cardano-api, gen, internal} ^>=9.1
, cardano-crypto
, cardano-ledger-alonzo
, cardano-ledger-api
Expand Down Expand Up @@ -138,7 +138,7 @@ test-suite cardano-node-emulator-test
-- Other IOG dependencies
--------------------------
build-depends:
, cardano-api:{cardano-api, gen, internal} ^>=8.46
, cardano-api:{cardano-api, gen, internal} ^>=9.1
, plutus-ledger-api >=1.0.0
, plutus-tx >=1.0.0
, plutus-tx-plugin >=1.0.0
Expand Down
19 changes: 13 additions & 6 deletions cardano-node-emulator/src/Cardano/Node/Emulator/Generators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ module Cardano.Node.Emulator.Generators (
) where

import Cardano.Api qualified as C
import Cardano.Api.Ledger (StandardCrypto)
import Cardano.Api.Shelley qualified as C
import Cardano.Crypto.Wallet qualified as Crypto
import Cardano.Ledger.Api.PParams (ppMaxCollateralInputsL)
import Cardano.Node.Emulator.Internal.Node.Params (Params (pSlotConfig), testnet)
import Cardano.Node.Emulator.Internal.Node.Params (
Params (pSlotConfig),
defaultConfig,
paramsFromConfig,
testnet,
)
import Cardano.Node.Emulator.Internal.Node.TimeSlot (SlotConfig)
import Cardano.Node.Emulator.Internal.Node.TimeSlot qualified as TimeSlot
import Cardano.Node.Emulator.Internal.Node.Validation (
Expand Down Expand Up @@ -171,20 +177,21 @@ data Mockchain = Mockchain
deriving (Show)

-- | The empty mockchain.
emptyChain :: Mockchain
emptyChain = Mockchain [] Map.empty def
emptyChain :: Params -> Mockchain
emptyChain = Mockchain [] Map.empty

{- | Generate a mockchain.

TODO: Generate more than 1 txn
-}
genMockchain'
:: GeneratorModel
-> C.CardanoEra StandardCrypto
-> Gen Mockchain
genMockchain' gm = do
genMockchain' gm era = do
slotCfg <- genSlotConfig
(txn, ot) <- genInitialTransaction gm
let params = def{pSlotConfig = slotCfg}
let params = (paramsFromConfig $ defaultConfig era){pSlotConfig = slotCfg}
-- There is a problem that txId of emulator tx and tx of cardano tx are different.
-- We convert the emulator tx to cardano tx here to get the correct transaction id
-- because later we anyway will use the converted cardano tx so the utxo should match it.
Expand All @@ -197,7 +204,7 @@ genMockchain' gm = do
}

-- | Generate a mockchain using the default 'GeneratorModel'.
genMockchain :: Gen Mockchain
genMockchain :: C.CardanoEra StandardCrypto -> Gen Mockchain
genMockchain = genMockchain' generatorModel

{- | A transaction with no inputs that mints some value (to be used at the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Cardano.Node.Emulator.Internal.Node.Fee (

import Cardano.Api qualified as C
import Cardano.Api.Error qualified as C.Api
import Cardano.Api.Fees (mapTxScriptWitnesses)
import Cardano.Api.Fees ()
import Cardano.Api.Shelley qualified as C
import Cardano.Api.Shelley qualified as C.Api
import Cardano.Ledger.Api.PParams qualified as C
Expand Down Expand Up @@ -90,28 +90,7 @@ fillTxExUnits params txUtxo buildTx@(CardanoBuildTx txBodyContent) = do
Left
(Map.mapKeys (C.toScriptIndex C.AlonzoEraOnwardsConway) . fmap (C.fromAlonzoExUnits . snd))
$ getTxExUnitsWithLogs params (CardanoAPI.fromPlutusIndex txUtxo) tmpTx'
bimap (Right . TxBodyError . C.Api.displayError) CardanoBuildTx $
mapTxScriptWitnesses (mapWitness exUnitsMap') txBodyContent
where
mapWitness
:: Map.Map C.Api.ScriptWitnessIndex C.Api.ExecutionUnits
-> C.ScriptWitnessIndex
-> C.ScriptWitness witctx era
-> Either (C.TxBodyErrorAutoBalance era) (C.ScriptWitness witctx era)
mapWitness _ _ [email protected]{} = Right wit
mapWitness eum idx (C.PlutusScriptWitness langInEra version script datum redeemer _) =
case Map.lookup idx eum of
Nothing ->
Left $ C.TxBodyErrorScriptWitnessIndexMissingFromExecUnitsMap idx eum
Just exunits ->
Right $
C.PlutusScriptWitness
langInEra
version
script
datum
redeemer
exunits
substituteExecutionUnits exUnitsMap' txBodyContent

{- | Creates a balanced transaction by calculating the execution units, the fees and the change,
which is assigned to the given address. Only balances Ada.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
-- | The set of parameters, like protocol parameters and slot configuration.
module Cardano.Node.Emulator.Internal.Node.Params (
Params (..),
defaultConfig,
paramsFromConfig,
C.mkLatestTransitionConfig,
slotConfigL,
networkIdL,
emulatorPParamsL,
emulatorPParams,
pProtocolParams,
pParamsFromProtocolParams,
ledgerProtocolParameters,
increaseTransactionLimits,
increaseTransactionLimits',
Expand Down Expand Up @@ -71,7 +71,6 @@ import Control.Lens (makeLensesFor, over, (%~), (&), (.~), (^.))
import Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON))
import Data.Aeson qualified as JSON
import Data.Aeson.Types (prependFailure, typeMismatch)
import Data.Default (Default (def))
import Data.Map qualified as Map
import Data.Maybe (fromJust)
import Data.Ratio ((%))
Expand All @@ -87,7 +86,7 @@ import Ledger.Test (testNetworkMagic, testnet)
import Ouroboros.Consensus.Block (GenesisWindow (GenesisWindow))
import Ouroboros.Consensus.HardFork.History qualified as Ouroboros
import Plutus.Script.Utils.Scripts (Language (PlutusV1))
import PlutusCore.Evaluation.Machine.ExBudgetingDefaults (defaultCostModelParams)
import PlutusCore.Evaluation.Machine.ExBudgetingDefaults (defaultCostModelParamsForTesting)
import PlutusLedgerApi.V1 (POSIXTime (POSIXTime, getPOSIXTime))
import Prettyprinter (Pretty (pretty), viaShow, vsep, (<+>))

Expand Down Expand Up @@ -125,9 +124,6 @@ makeLensesFor
]
''Params

instance Default Params where
def = paramsFromConfig defaultConfig

instance Pretty Params where
pretty Params{..} =
vsep
Expand All @@ -140,11 +136,8 @@ instance Pretty Params where
emulatorPParams :: Params -> PParams
emulatorPParams = pEmulatorPParams

pProtocolParams :: Params -> C.ProtocolParameters
pProtocolParams p = C.fromLedgerPParams C.ShelleyBasedEraConway $ emulatorPParams p

pParamsFromProtocolParams :: C.ProtocolParameters -> PParams
pParamsFromProtocolParams = either (error . show) id . C.toLedgerPParams C.ShelleyBasedEraConway
pProtocolParams :: Params -> PParams
pProtocolParams = emulatorPParams

ledgerProtocolParameters :: Params -> C.LedgerProtocolParameters C.ConwayEra
ledgerProtocolParameters = C.LedgerProtocolParameters . emulatorPParams
Expand All @@ -168,11 +161,11 @@ increaseTransactionLimits' size steps mem =
emulatorProtocolMajorVersion :: Version
emulatorProtocolMajorVersion = natVersion @9

defaultConfig :: TransitionConfig
defaultConfig =
defaultConfig :: C.CardanoEra StandardCrypto -> TransitionConfig
defaultConfig era =
C.mkLatestTransitionConfig
emulatorShelleyGenesisDefaults
emulatorAlonzoGenesisDefaults
(emulatorAlonzoGenesisDefaults era)
emulatorConwayGenesisDefaults

emulatorShelleyGenesisDefaults :: C.ShelleyGenesis StandardCrypto
Expand All @@ -188,16 +181,18 @@ emulatorShelleyGenesisDefaults =
& C.ppKeyDepositL .~ Coin 2_000_000
}

emulatorAlonzoGenesisDefaults :: C.AlonzoGenesis
emulatorAlonzoGenesisDefaults =
C.alonzoGenesisDefaults
emulatorAlonzoGenesisDefaults :: C.CardanoEra StandardCrypto -> C.AlonzoGenesis
emulatorAlonzoGenesisDefaults era =
(C.alonzoGenesisDefaults era)
{ C.agPrices =
Prices (fromJust $ boundRational (577 % 10_000)) (fromJust $ boundRational (721 % 10_000_000))
, C.agMaxTxExUnits = ExUnits 14_000_000 10_000_000_000
, C.agCostModels = mkCostModels costModels
}
where
costModel lang = fromJust $ defaultCostModelParams >>= Alonzo.costModelFromMap lang . projectLangParams lang
costModel lang =
fromJust $
defaultCostModelParamsForTesting >>= Alonzo.costModelFromMap lang . projectLangParams lang
costModels = Map.fromList $ map (\lang -> (lang, costModel lang)) [minBound .. maxBound]
projectLangParams lang m =
Map.restrictKeys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,13 @@ constructValidated globals (C.Ledger.UtxoEnv _ pp _) st tx =
Left errs ->
throwError
( ApplyTxError
( ( ConwayUtxowFailure
(Core.injectFailure (UtxosFailure (Core.injectFailure $ CollectErrors errs)))
)
( ConwayUtxowFailure
(Core.injectFailure (UtxosFailure (Core.injectFailure $ CollectErrors errs)))
:| []
)
)
Right sLst ->
let scriptEvalResult = evalPlutusScripts @EmulatorEra tx sLst
let scriptEvalResult = evalPlutusScripts sLst
vTx =
AlonzoTx
(view Core.bodyTxL tx)
Expand Down Expand Up @@ -295,12 +294,14 @@ getTxExUnitsWithLogs
:: Params -> UTxO EmulatorEra -> C.Tx C.ConwayEra -> Either P.ValidationErrorInPhase P.RedeemerReport
getTxExUnitsWithLogs params utxo (C.ShelleyTx _ tx) =
case evalTxExUnitsWithLogs (emulatorPParams params) tx utxo ei ss of
Left e -> Left . (P.Phase1,) . P.CardanoLedgerValidationError . Text.pack . show $ e
Right result -> traverse (either toCardanoLedgerError Right) result
result -> traverse (either toCardanoLedgerError Right) result
where
eg = emulatorGlobals params
ss = systemStart eg
ei = epochInfo eg
toCardanoLedgerError
:: TransactionScriptFailure EmulatorEra
-> Either (P.ValidationPhase, P.ValidationError) b
toCardanoLedgerError (ValidationFailure _ (V1.CekError ce) logs _) =
Left (P.Phase2, P.ScriptFailure (P.EvaluationError logs ("CekEvaluationFailure: " ++ show ce)))
toCardanoLedgerError e = Left (P.Phase2, P.CardanoLedgerValidationError $ Text.pack $ show e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ library
-- Other IOG dependencies
--------------------------
build-depends:
, cardano-api:{cardano-api, internal} ^>=8.46
, cardano-api:{cardano-api, internal} ^>=9.1
, cardano-ledger-api
, cardano-ledger-byron
, cardano-ledger-core:{cardano-ledger-core, testlib}
Expand Down
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.

5 changes: 2 additions & 3 deletions plutus-ledger/plutus-ledger.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ library
Ledger.Blockchain
Ledger.Builtins.Orphans
Ledger.CardanoWallet
Ledger.Contexts.Orphans
Ledger.Credential.Orphans
Ledger.Crypto
Ledger.Crypto.Orphans
Expand Down Expand Up @@ -107,7 +106,7 @@ library
-- Other IOG dependencies
--------------------------
build-depends:
, cardano-api:{cardano-api, internal} ^>=8.46
, cardano-api:{cardano-api, internal} ^>=9.1
, cardano-binary
, cardano-crypto
, cardano-ledger-alonzo
Expand Down Expand Up @@ -172,7 +171,7 @@ test-suite plutus-ledger-test
-- Other IOG dependencies
--------------------------
build-depends:
, cardano-api:{cardano-api, gen} ^>=8.46
, cardano-api:{cardano-api, gen} ^>=9.1
, plutus-ledger-api >=1.0.0
, plutus-tx >=1.0.0

Expand Down
9 changes: 0 additions & 9 deletions plutus-ledger/src/Ledger/Contexts/Orphans.hs

This file was deleted.

6 changes: 4 additions & 2 deletions plutus-ledger/src/Ledger/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import PlutusLedgerApi.V1.Value qualified as Value
import PlutusLedgerApi.V2 qualified as PV2
import PlutusLedgerApi.V3 qualified as PV3
import PlutusTx qualified
import PlutusTx.Prelude (BuiltinUnit, check)
import Prelude hiding (not)

someCode
:: PlutusTx.CompiledCode (PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> ())
someCode = $$(PlutusTx.compile [||\_ _ _ -> ()||])
:: PlutusTx.CompiledCode
(PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> PlutusTx.BuiltinData -> BuiltinUnit)
someCode = $$(PlutusTx.compile [||\_ _ _ -> check True||])

someValidator :: Scripts.Validator
someValidator = Ledger.mkValidatorScript someCode
Expand Down
2 changes: 1 addition & 1 deletion plutus-ledger/src/Ledger/Tx/CardanoAPI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fromCardanoTxInsCollateral C.TxInsCollateralNone = []
fromCardanoTxInsCollateral (C.TxInsCollateral _ txIns) = txIns

toCardanoDatumWitness :: Maybe PV1.Datum -> C.ScriptDatum C.WitCtxTxIn
toCardanoDatumWitness = maybe C.InlineScriptDatum (C.ScriptDatumForTxIn . toCardanoScriptData . PV1.getDatum)
toCardanoDatumWitness = maybe C.InlineScriptDatum (C.ScriptDatumForTxIn . Just . toCardanoScriptData . PV1.getDatum)

type WitnessHeader witctx =
C.ScriptDatum witctx -> C.ScriptRedeemer -> C.ExecutionUnits -> C.ScriptWitness witctx C.ConwayEra
Expand Down
3 changes: 2 additions & 1 deletion plutus-ledger/src/Ledger/Tx/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import Data.Map qualified as Map
import GHC.Generics (Generic)

import Ledger.Address (CardanoAddress, cardanoPubKeyHash)
import Ledger.Contexts.Orphans ()
import Ledger.Crypto
import Ledger.DCert.Orphans ()
import Ledger.Tx.Orphans ()
Expand Down Expand Up @@ -216,4 +215,6 @@ emptyTxBodyContent =
, txUpdateProposal = C.TxUpdateProposalNone
, txProposalProcedures = Nothing
, txVotingProcedures = Nothing
, txCurrentTreasuryValue = Nothing
, txTreasuryDonation = Nothing
}
2 changes: 1 addition & 1 deletion plutus-ledger/src/Ledger/Value/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ instance (ToJSON v, ToJSON k) => ToJSON (Map.Map k v) where
instance (FromJSON v, FromJSON k, PlutusTx.Eq k) => FromJSON (Map.Map k v) where
parseJSON v = Map.safeFromList <$> JSON.parseJSON v

deriving anyclass instance (Hashable k, Hashable v) => Hashable (Map.Map k v)
deriving anyclass instance (Hashable k, Hashable v, Ord k) => Hashable (Map.Map k v)

deriving anyclass instance (Serialise k, Serialise v) => Serialise (Map.Map k v)

Expand Down
2 changes: 1 addition & 1 deletion plutus-script-utils/plutus-script-utils.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ library
-- Other IOG dependencies
--------------------------
build-depends:
, cardano-api ^>=8.46
, cardano-api ^>=9.1
, cardano-ledger-core
, plutus-core >=1.0.0
, plutus-ledger-api >=1.0.0
Expand Down
Loading
Loading