Skip to content

Commit

Permalink
cardano-api: 8.37 -> 8.38
Browse files Browse the repository at this point in the history
Co-author: Sebastian Nagel <[email protected]>
  • Loading branch information
locallycompact committed Feb 21, 2024
1 parent a49f7d3 commit d4e13fa
Show file tree
Hide file tree
Showing 34 changed files with 189 additions and 242 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ changes.
fees in internal wallet
[#1315](https://github.com/input-output-hk/hydra/pull/1315).

- **BREAKING** Regenerated hydra scripts.

## [0.15.0] - 2024-01-18

- Tested with `cardano-node 8.7.3` and `cardano-cli 8.17.0.0`.
Expand Down
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ repository cardano-haskell-packages

-- See CONTRIBUTING.md for information about when and how to update these.
index-state:
, hackage.haskell.org 2024-01-29T15:07:04Z
, cardano-haskell-packages 2024-01-29T19:04:02Z
, hackage.haskell.org 2024-02-07T15:07:04Z
, cardano-haskell-packages 2024-02-07T19:04:02Z

packages:
hydra-prelude
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.

26 changes: 13 additions & 13 deletions hydra-cardano-api/hydra-cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,21 @@ library
, base >=4.16
, base16-bytestring
, bytestring
, cardano-api >=8.37.0 && <8.38
, cardano-binary >=1.7.0 && <1.8
, cardano-crypto-class >=2.1.1 && <2.2
, cardano-ledger-allegra >=1.2.1 && <1.3
, cardano-ledger-alonzo >=1.5 && <1.6
, cardano-ledger-api >=1.7 && <1.8
, cardano-ledger-babbage >=1.5 && <1.6
, cardano-ledger-binary >=1.2 && <1.3
, cardano-ledger-byron >=1.0.0 && <1.1
, cardano-ledger-core >=1.9 && <1.10
, cardano-ledger-mary >=1.4 && <1.5
, cardano-ledger-shelley >=1.8 && <1.9
, cardano-api >=8.38.0 && <8.39
, cardano-binary >=1.7.0 && <1.8
, cardano-crypto-class >=2.1.1 && <2.2
, cardano-ledger-allegra >=1.3 && <1.4
, cardano-ledger-alonzo >=1.6 && <1.7
, cardano-ledger-api >=1.8 && <1.9
, cardano-ledger-babbage >=1.6 && <1.7
, cardano-ledger-binary >=1.3 && <1.4
, cardano-ledger-byron >=1.0.0 && <1.1
, cardano-ledger-core >=1.10 && <1.11
, cardano-ledger-mary >=1.5 && <1.6
, cardano-ledger-shelley >=1.9 && <1.10
, containers
, lens
, plutus-ledger-api >=1.15.0.1 && <1.16
, plutus-ledger-api >=1.21 && <1.22
, QuickCheck
, serialise
, text >=2
32 changes: 14 additions & 18 deletions hydra-cardano-api/src/Hydra/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ import Hydra.Cardano.Api.Prelude (
LedgerEra,
LedgerProtocolParameters,
Map,
Proposal,
StandardCrypto,
VotingProcedures,
ledgerEraVersion,
)

Expand Down Expand Up @@ -156,8 +154,6 @@ import Cardano.Ledger.Alonzo.TxAuxData qualified as Ledger
import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
import Cardano.Ledger.Core qualified as Ledger
import Cardano.Ledger.Keys qualified as Ledger
import Cardano.Ledger.Keys.Bootstrap qualified as Ledger
import Cardano.Ledger.Keys.WitVKey qualified as Ledger
import Data.ByteString.Short (ShortByteString)
import Prelude

Expand Down Expand Up @@ -379,13 +375,13 @@ defaultTxBodyContent = Cardano.Api.defaultTxBodyContent shelleyBasedEra

-- ** TxBodyContent

type TxBodyContent build = Cardano.Api.TxBodyContent build Era
type TxBodyContent buidl = Cardano.Api.TxBodyContent buidl Era
{-# COMPLETE TxBodyContent #-}

pattern TxBodyContent ::
TxIns build ->
TxIns buidl ->
TxInsCollateral ->
TxInsReference build ->
TxInsReference buidl ->
[TxOut CtxTx] ->
TxTotalCollateral Era ->
TxReturnCollateral CtxTx Era ->
Expand All @@ -395,15 +391,15 @@ pattern TxBodyContent ::
TxMetadataInEra ->
TxAuxScripts ->
TxExtraKeyWitnesses ->
BuildTxWith build (Maybe (LedgerProtocolParameters Era)) ->
TxWithdrawals build Era ->
TxCertificates build Era ->
BuildTxWith buidl (Maybe (LedgerProtocolParameters Era)) ->
TxWithdrawals buidl Era ->
TxCertificates buidl Era ->
TxUpdateProposal Era ->
TxMintValue build ->
TxMintValue buidl ->
TxScriptValidity ->
Maybe (Featured ConwayEraOnwards Era [Proposal Era]) ->
Maybe (Featured ConwayEraOnwards Era (VotingProcedures Era)) ->
TxBodyContent build
Maybe (Featured ConwayEraOnwards Era (TxProposalProcedures buidl Era)) ->
Maybe (Featured ConwayEraOnwards Era (TxVotingProcedures buidl Era)) ->
TxBodyContent buidl
pattern TxBodyContent
{ txIns
, txInsCollateral
Expand Down Expand Up @@ -565,10 +561,10 @@ pattern TxMetadataInEra{txMetadataInEra} <-

-- ** TxMintValue

type TxMintValue build = Cardano.Api.TxMintValue build Era
type TxMintValue buidl = Cardano.Api.TxMintValue buidl Era
{-# COMPLETE TxMintValueNone, TxMintValue #-}

pattern TxMintValueNone :: TxMintValue build
pattern TxMintValueNone :: TxMintValue buidl
pattern TxMintValueNone <-
Cardano.Api.TxMintNone
where
Expand All @@ -577,8 +573,8 @@ pattern TxMintValueNone <-

pattern TxMintValue ::
Value ->
BuildTxWith build (Map PolicyId (ScriptWitness WitCtxMint)) ->
TxMintValue build
BuildTxWith buidl (Map PolicyId (ScriptWitness WitCtxMint)) ->
TxMintValue buidl
pattern TxMintValue{txMintValueInEra, txMintValueScriptWitnesses} <-
Cardano.Api.TxMintValue _ txMintValueInEra txMintValueScriptWitnesses
where
Expand Down
5 changes: 2 additions & 3 deletions hydra-cardano-api/src/Hydra/Cardano/Api/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Hydra.Cardano.Api.Hash where

import Hydra.Cardano.Api.Prelude

import Cardano.Ledger.Alonzo.Plutus.TxInfo qualified as Ledger
import Cardano.Ledger.Keys qualified as Ledger
import Cardano.Ledger.Plutus.TxInfo (transKeyHash)
import Cardano.Ledger.SafeHash (unsafeMakeSafeHash)
import Cardano.Ledger.Shelley.Scripts qualified as Ledger
import Data.ByteString qualified as BS
Expand All @@ -13,8 +13,7 @@ import PlutusLedgerApi.V2 qualified as Plutus

-- | Convert a cardano-api 'Hash' into a plutus 'PubKeyHash'
toPlutusKeyHash :: Hash PaymentKey -> Plutus.PubKeyHash
toPlutusKeyHash (PaymentKeyHash vkh) =
Ledger.transKeyHash vkh
toPlutusKeyHash (PaymentKeyHash vkh) = transKeyHash vkh

-- | Convert a cardano-api 'Hash' into a cardano-ledger 'KeyHash'
toLedgerKeyHash :: Hash PaymentKey -> Ledger.KeyHash 'Ledger.Witness StandardCrypto
Expand Down
1 change: 0 additions & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/KeyWitness.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Hydra.Cardano.Api.Prelude
import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
import Cardano.Ledger.Era qualified as Ledger
import Cardano.Ledger.Keys qualified as Ledger
import Cardano.Ledger.Shelley.API qualified as Ledger
import Data.Set qualified as Set

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

import Cardano.Ledger.Alonzo.Scripts qualified as Ledger
import Cardano.Ledger.Babbage.Scripts qualified as Ledger
import Cardano.Ledger.Plutus.Language qualified as Ledger
import Data.ByteString.Short qualified as SBS
import PlutusLedgerApi.Common qualified as Plutus
Expand All @@ -18,10 +19,15 @@ import Test.QuickCheck (listOf)
--
-- (a) If the given script is a timelock script, it throws an impure exception;
-- (b) If the given script is in a wrong language, it silently coerces it.
fromLedgerScript :: HasCallStack => Ledger.AlonzoScript era -> PlutusScript lang
fromLedgerScript ::
( HasCallStack
, Ledger.AlonzoEraScript era
) =>
Ledger.AlonzoScript era ->
PlutusScript lang
fromLedgerScript = \case
Ledger.TimelockScript{} -> error "fromLedgerScript: TimelockScript"
Ledger.PlutusScript (Ledger.Plutus _ (Ledger.BinaryPlutus bytes)) -> PlutusScriptSerialised bytes
Ledger.PlutusScript x -> Ledger.withPlutusScript x (\(Ledger.Plutus (Ledger.PlutusBinary bytes)) -> PlutusScriptSerialised bytes)

-- | Convert a cardano-api 'PlutusScript' into a cardano-ledger 'Script'.
toLedgerScript ::
Expand All @@ -30,11 +36,10 @@ toLedgerScript ::
PlutusScript lang ->
Ledger.AlonzoScript (ShelleyLedgerEra Era)
toLedgerScript (PlutusScriptSerialised bytes) =
let lang = case plutusScriptVersion @lang of
PlutusScriptV1 -> Ledger.PlutusV1
PlutusScriptV2 -> Ledger.PlutusV2
PlutusScriptV3 -> Ledger.PlutusV3
in Ledger.PlutusScript $ Ledger.Plutus lang (Ledger.BinaryPlutus bytes)
Ledger.PlutusScript $ case plutusScriptVersion @lang of
PlutusScriptV1 -> Ledger.BabbagePlutusV1 $ Ledger.Plutus (Ledger.PlutusBinary bytes)
PlutusScriptV2 -> Ledger.BabbagePlutusV2 $ Ledger.Plutus (Ledger.PlutusBinary bytes)
PlutusScriptV3 -> error "toLedgerScript: PlutusV3 not supported in Babbage"

-- | Convert a serialized plutus script into a cardano-api 'PlutusScript'.
fromPlutusScript :: Plutus.SerialisedScript -> PlutusScript lang
Expand Down
11 changes: 4 additions & 7 deletions hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,8 @@ renderTxWithUTxO utxo (Tx body _wits) =

totalScriptSize = sum $ BL.length . serialize <$> scripts

prettyScript (Api.fromLedgerScript -> script) =
"Script (" <> scriptHash <> ")"
where
scriptHash =
show (Ledger.hashScript @(ShelleyLedgerEra Era) (Api.toLedgerScript @PlutusScriptV2 script))
prettyScript script =
"Script (" <> show (Ledger.hashScript script) <> ")"

datumLines = case scriptsData of
Api.TxBodyNoScriptData -> []
Expand All @@ -171,9 +168,9 @@ renderTxWithUTxO utxo (Tx body _wits) =
in "== REDEEMERS (" <> show (length rdmrs) <> ")"
: (("- " <>) . prettyRedeemer <$> rdmrs)

prettyRedeemer (Ledger.RdmrPtr tag ix, (redeemerData, redeemerBudget)) =
prettyRedeemer (purpose, (redeemerData, redeemerBudget)) =
unwords
[ show tag <> "#" <> show ix
[ show purpose
, mconcat
[ "( cpu = " <> show (Ledger.exUnitsSteps redeemerBudget)
, ", mem = " <> show (Ledger.exUnitsMem redeemerBudget) <> " )"
Expand Down
7 changes: 4 additions & 3 deletions hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ lookupScriptData (Tx (ShelleyTxBody _ _ _ scriptsData _ _) _) (TxOut _ _ datum _
(TxOutDatumInline _ dat) ->
Just dat
where
datums = case scriptsData of
TxBodyNoScriptData -> mempty
TxBodyScriptData _ (Ledger.TxDats m) _ -> m
datums :: Map (Ledger.DataHash StandardCrypto) (Ledger.Data (ShelleyLedgerEra era)) =
case (scriptsData :: TxBodyScriptData era) of
TxBodyNoScriptData -> mempty
TxBodyScriptData _ (Ledger.TxDats m) _ -> m

-- * Type Conversions

Expand Down
22 changes: 9 additions & 13 deletions hydra-cardano-api/src/Hydra/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,36 @@ module Hydra.Cardano.Api.TxBody where
import Hydra.Cardano.Api.Prelude

import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
import Cardano.Ledger.Babbage.Tx qualified as Ledger
import Cardano.Ledger.Api (AlonzoPlutusPurpose (..), AsIndex, AsItem (..), PlutusPurpose)
import Cardano.Ledger.Babbage.Core (redeemerPointer)
import Cardano.Ledger.BaseTypes (strictMaybeToMaybe)
import Cardano.Ledger.Core qualified as Ledger
import Cardano.Ledger.Plutus.Data qualified as Ledger
import Data.List (find)
import Data.Map qualified as Map
import Hydra.Cardano.Api.PlutusScript (fromLedgerScript)
import Hydra.Cardano.Api.PolicyId (toLedgerPolicyID, toLedgerScriptHash)
import Hydra.Cardano.Api.ScriptData (FromScriptData)
import Hydra.Cardano.Api.TxIn (toLedgerTxIn)
import PlutusLedgerApi.V2 qualified as Plutus

-- | Find and deserialise from 'ScriptData', a redeemer from the transaction
-- associated to the given input.
findRedeemerSpending ::
FromScriptData a =>
Plutus.FromData a =>
Tx Era ->
TxIn ->
Maybe a
findRedeemerSpending (getTxBody -> ShelleyTxBody _ body _ scriptData _ _) txIn = do
ptr <- strictMaybeToMaybe $ Ledger.rdptr body (Ledger.Spending $ toLedgerTxIn txIn)
ptr <- strictMaybeToMaybe $ redeemerPointer body (AlonzoSpending . AsItem $ toLedgerTxIn txIn)
lookupRedeemer ptr scriptData

findRedeemerMinting ::
forall a.
FromScriptData a =>
Plutus.FromData a =>
Tx Era ->
PolicyId ->
Maybe a
findRedeemerMinting (getTxBody -> ShelleyTxBody _ body _ scriptData _ _) pid = do
ptr <- strictMaybeToMaybe $ Ledger.rdptr body (Ledger.Minting $ toLedgerPolicyID pid)
ptr <- strictMaybeToMaybe $ redeemerPointer body (AlonzoMinting . AsItem $ toLedgerPolicyID pid)
lookupRedeemer ptr scriptData

findScriptMinting ::
Expand All @@ -53,12 +52,9 @@ findScriptMinting (getTxBody -> ShelleyTxBody _ _ scripts _ _ _) pid = do
--

lookupRedeemer ::
forall a era.
( FromScriptData a
, Ledger.Era (ShelleyLedgerEra era)
) =>
Ledger.RdmrPtr ->
TxBodyScriptData era ->
Plutus.FromData a =>
PlutusPurpose AsIndex LedgerEra ->
TxBodyScriptData Era ->
Maybe a
lookupRedeemer ptr scriptData = do
(d, _exUnits) <- Map.lookup ptr redeemers
Expand Down
4 changes: 2 additions & 2 deletions hydra-cardano-api/src/Hydra/Cardano/Api/TxIn.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Hydra.Cardano.Api.Prelude

import Cardano.Ledger.BaseTypes qualified as Ledger
import Cardano.Ledger.Binary qualified as Ledger
import Cardano.Ledger.Plutus.TxInfo qualified as Ledger
import Cardano.Ledger.Plutus (transTxIn)
import Cardano.Ledger.TxIn qualified as Ledger
import Data.ByteString qualified as BS
import Data.Set qualified as Set
Expand Down Expand Up @@ -54,7 +54,7 @@ fromPlutusTxOutRef (Plutus.TxOutRef (Plutus.TxId bytes) ix) =

-- | Convert a cardano-api 'TxIn' into a plutus 'TxOutRef'.
toPlutusTxOutRef :: TxIn -> Plutus.TxOutRef
toPlutusTxOutRef = Ledger.txInfoIn' . toLedgerTxIn
toPlutusTxOutRef = transTxIn . toLedgerTxIn

-- * Arbitrary values

Expand Down
6 changes: 3 additions & 3 deletions hydra-cardano-api/src/Hydra/Cardano/Api/TxOut.hs
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ fromPlutusTxOut network out = do

-- | Convert a cardano-api 'TxOut' into a plutus 'TxOut'. Returns 'Nothing'
-- if a byron address is used in the given 'TxOut'.
toPlutusTxOut :: TxOut CtxUTxO Era -> Maybe Plutus.TxOut
toPlutusTxOut :: HasCallStack => TxOut CtxUTxO Era -> Maybe Plutus.TxOut
toPlutusTxOut =
-- NOTE: The txInfoOutV2 conversion does take this 'TxOutSource' to report
-- NOTE: The transTxOutV2 conversion does take this 'TxOutSource' to report
-- origins of 'TranslationError'. However, this value is NOT used for
-- constructing the Plutus.TxOut and hence we error out should it be used via
-- a 'Left', which we expect to throw away anyway on 'eitherToMaybe'.
eitherToMaybe . Ledger.txInfoOutV2 (error "TxOutSource used unexpectedly") . toLedgerTxOut
eitherToMaybe . Ledger.transTxOutV2 (error "TxOutSource used unexpectedly") . toLedgerTxOut
where
eitherToMaybe = \case
Left _ -> Nothing
Expand Down
2 changes: 1 addition & 1 deletion hydra-cluster/src/Hydra/Cluster/Faucet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Hydra.Ledger.Cardano ()

data FaucetException
= FaucetHasNotEnoughFunds {faucetUTxO :: UTxO}
| FaucetFailedToBuildTx {reason :: TxBodyErrorAutoBalance}
| FaucetFailedToBuildTx {reason :: TxBodyErrorAutoBalance Era}
deriving stock (Show)

instance Exception FaucetException
Expand Down
5 changes: 2 additions & 3 deletions hydra-node/hydra-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ library
Hydra.Ledger.Cardano.Builder
Hydra.Ledger.Cardano.Configuration
Hydra.Ledger.Cardano.Evaluate
Hydra.Ledger.Cardano.Json
Hydra.Ledger.Cardano.Time
Hydra.Ledger.Simple
Hydra.Logging
Expand Down Expand Up @@ -151,8 +150,8 @@ library
, ouroboros-network-api >=0.1.0.0
, ouroboros-network-framework >=0.3.0.0
, ouroboros-network-protocols >=0.3.0.0
, plutus-core >=1.15.0.1 && <1.16
, plutus-ledger-api >=1.15.0.1 && <1.16
, plutus-core >=1.21 && <1.22
, plutus-ledger-api >=1.21 && <1.22
, prometheus
, QuickCheck
, quickcheck-instances
Expand Down
Loading

0 comments on commit d4e13fa

Please sign in to comment.