Skip to content

Commit

Permalink
Merge branch 'master' into lc/flake-update
Browse files Browse the repository at this point in the history
  • Loading branch information
locallycompact authored Feb 27, 2024
2 parents 6044f02 + 3006762 commit d3e1aaf
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 23 deletions.
1 change: 1 addition & 0 deletions hydra-cardano-api/hydra-cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ library
Hydra.Cardano.Api
Hydra.Cardano.Api.Address
Hydra.Cardano.Api.AddressInEra
Hydra.Cardano.Api.AllegraEraOnwards
Hydra.Cardano.Api.AlonzoEraOnwards
Hydra.Cardano.Api.BabbageEraOnwards
Hydra.Cardano.Api.BlockHeader
Expand Down
3 changes: 2 additions & 1 deletion hydra-cardano-api/src/Cardano/Api/UTxO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Data.Text (Text)
import Data.Text qualified as T
import Hydra.Cardano.Api.AlonzoEraOnwards (IsAlonzoEraOnwards (..))
import Hydra.Cardano.Api.BabbageEraOnwards (IsBabbageEraOnwards (..))
import Hydra.Cardano.Api.MaryEraOnwards (IsMaryEraOnwards (..))
import Prelude

type Era = BabbageEra
Expand Down Expand Up @@ -112,7 +113,7 @@ fromApi (Cardano.Api.UTxO eraUTxO) =

convertValueToEra :: TxOutValue era -> TxOutValue Era
convertValueToEra (TxOutValueByron lovelace) = lovelaceToTxOutValue shelleyBasedEra lovelace
convertValueToEra (TxOutValueShelleyBased sbe value) = TxOutValueShelleyBased shelleyBasedEra (toLedgerValue MaryEraOnwardsBabbage $ fromLedgerValue sbe value)
convertValueToEra (TxOutValueShelleyBased sbe value) = TxOutValueShelleyBased shelleyBasedEra (toLedgerValue (maryEraOnwards @Era) $ fromLedgerValue sbe value)

convertDatumToEra :: TxOutDatum CtxUTxO era -> TxOutDatum CtxUTxO Era
convertDatumToEra TxOutDatumNone = TxOutDatumNone
Expand Down
30 changes: 16 additions & 14 deletions hydra-cardano-api/src/Hydra/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
import Cardano.Ledger.Core qualified as Ledger
import Cardano.Ledger.Keys qualified as Ledger
import Data.ByteString.Short (ShortByteString)
import Hydra.Cardano.Api.AllegraEraOnwards (IsAllegraEraOnwards (..))
import Hydra.Cardano.Api.BabbageEraOnwards (IsBabbageEraOnwards (..))
import Prelude

-- ** AddressInEra
Expand Down Expand Up @@ -355,7 +357,7 @@ pattern TxAuxScripts{txAuxScripts'} <-
Cardano.Api.TxAuxScripts _ txAuxScripts'
where
TxAuxScripts =
Cardano.Api.TxAuxScripts AllegraEraOnwardsBabbage
Cardano.Api.TxAuxScripts allegraEraOnwards

-- ** TxBody

Expand Down Expand Up @@ -466,7 +468,7 @@ pattern TxBodyScriptData{txBodyScriptDatums, txBodyScriptRedeemers} <-
Cardano.Api.TxBodyScriptData _ txBodyScriptDatums txBodyScriptRedeemers
where
TxBodyScriptData =
Cardano.Api.TxBodyScriptData AlonzoEraOnwardsBabbage
Cardano.Api.TxBodyScriptData alonzoEraOnwards

-- ** TxExtraKeyWitnesses

Expand All @@ -484,7 +486,7 @@ pattern TxExtraKeyWitnesses{txExtraKeyWitnesses} <-
Cardano.Api.TxExtraKeyWitnesses _ txExtraKeyWitnesses
where
TxExtraKeyWitnesses =
Cardano.Api.TxExtraKeyWitnesses AlonzoEraOnwardsBabbage
Cardano.Api.TxExtraKeyWitnesses alonzoEraOnwards

-- ** TxFee

Expand All @@ -496,7 +498,7 @@ pattern TxFeeExplicit{txFeeExplicit} <-
Cardano.Api.TxFeeExplicit _ txFeeExplicit
where
TxFeeExplicit =
Cardano.Api.TxFeeExplicit ShelleyBasedEraBabbage
Cardano.Api.TxFeeExplicit shelleyBasedEra

-- ** TxIns

Expand All @@ -519,7 +521,7 @@ pattern TxInsReference{txInsReference'} <-
Cardano.Api.TxInsReference _ txInsReference'
where
TxInsReference =
Cardano.Api.TxInsReference Cardano.Api.Shelley.BabbageEraOnwardsBabbage
Cardano.Api.TxInsReference babbageEraOnwards

-- ** TxInsCollateral

Expand All @@ -538,7 +540,7 @@ pattern TxInsCollateral{txInsCollateral'} <-
Cardano.Api.TxInsCollateral _ txInsCollateral'
where
TxInsCollateral =
Cardano.Api.TxInsCollateral AlonzoEraOnwardsBabbage
Cardano.Api.TxInsCollateral alonzoEraOnwards

-- ** TxMetadataInEra

Expand All @@ -557,7 +559,7 @@ pattern TxMetadataInEra{txMetadataInEra} <-
Cardano.Api.TxMetadataInEra _ txMetadataInEra
where
TxMetadataInEra =
Cardano.Api.TxMetadataInEra ShelleyBasedEraBabbage
Cardano.Api.TxMetadataInEra shelleyBasedEra

-- ** TxMintValue

Expand All @@ -579,7 +581,7 @@ pattern TxMintValue{txMintValueInEra, txMintValueScriptWitnesses} <-
Cardano.Api.TxMintValue _ txMintValueInEra txMintValueScriptWitnesses
where
TxMintValue =
Cardano.Api.TxMintValue MaryEraOnwardsBabbage
Cardano.Api.TxMintValue maryEraOnwards

-- ** TxOut

Expand All @@ -598,7 +600,7 @@ pattern TxOut{txOutAddress, txOutValue, txOutDatum, txOutReferenceScript} <-
TxOut addr value datum ref =
Cardano.Api.TxOut
addr
(TxOutValueShelleyBased ShelleyBasedEraBabbage (Extras.toLedgerValue value))
(TxOutValueShelleyBased shelleyBasedEra (Extras.toLedgerValue value))
datum
ref

Expand Down Expand Up @@ -641,21 +643,21 @@ pattern TxOutDatumHash{txOutDatumHash} <-
Cardano.Api.TxOutDatumHash _ txOutDatumHash
where
TxOutDatumHash =
Cardano.Api.TxOutDatumHash AlonzoEraOnwardsBabbage
Cardano.Api.TxOutDatumHash alonzoEraOnwards

pattern TxOutDatumInTx :: HashableScriptData -> TxOutDatum CtxTx
pattern TxOutDatumInTx{txOutDatumScriptData} <-
Cardano.Api.TxOutDatumInTx _ txOutDatumScriptData
where
TxOutDatumInTx =
Cardano.Api.TxOutDatumInTx AlonzoEraOnwardsBabbage
Cardano.Api.TxOutDatumInTx alonzoEraOnwards

pattern TxOutDatumInline :: HashableScriptData -> TxOutDatum ctx
pattern TxOutDatumInline{txOutDatumInlineScriptData} <-
Cardano.Api.TxOutDatumInline _ txOutDatumInlineScriptData
where
TxOutDatumInline =
Cardano.Api.TxOutDatumInline Cardano.Api.Shelley.BabbageEraOnwardsBabbage
Cardano.Api.TxOutDatumInline babbageEraOnwards

-- ** TxScriptValidity

Expand All @@ -674,7 +676,7 @@ pattern TxScriptValidity{txScriptValidity'} <-
Cardano.Api.TxScriptValidity _ txScriptValidity'
where
TxScriptValidity =
Cardano.Api.TxScriptValidity AlonzoEraOnwardsBabbage
Cardano.Api.TxScriptValidity alonzoEraOnwards

-- ** TxValidityLowerBound

Expand All @@ -693,7 +695,7 @@ pattern TxValidityLowerBound{lowerBound} <-
Cardano.Api.TxValidityLowerBound _ lowerBound
where
TxValidityLowerBound =
Cardano.Api.TxValidityLowerBound AllegraEraOnwardsBabbage
Cardano.Api.TxValidityLowerBound allegraEraOnwards

-- ** TxValidityUpperBound

Expand Down
23 changes: 23 additions & 0 deletions hydra-cardano-api/src/Hydra/Cardano/Api/AllegraEraOnwards.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Hydra.Cardano.Api.AllegraEraOnwards where

import Cardano.Api (AllegraEra, AllegraEraOnwards (..), AlonzoEra, BabbageEra, ConwayEra, MaryEra)

-- | Type class to produce 'AllegraEraOnwards' witness values while staying
-- parameterized by era.
class IsAllegraEraOnwards era where
allegraEraOnwards :: AllegraEraOnwards era

instance IsAllegraEraOnwards AllegraEra where
allegraEraOnwards = AllegraEraOnwardsAllegra

instance IsAllegraEraOnwards MaryEra where
allegraEraOnwards = AllegraEraOnwardsMary

instance IsAllegraEraOnwards AlonzoEra where
allegraEraOnwards = AllegraEraOnwardsAlonzo

instance IsAllegraEraOnwards BabbageEra where
allegraEraOnwards = AllegraEraOnwardsBabbage

instance IsAllegraEraOnwards ConwayEra where
allegraEraOnwards = AllegraEraOnwardsConway
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/MaryEraOnwards.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Hydra.Cardano.Api.MaryEraOnwards where

import Hydra.Cardano.Api.Prelude
import Cardano.Api (AlonzoEra, BabbageEra, ConwayEra, MaryEra, MaryEraOnwards (..))

-- | Type class to produce 'MaryEraOnwards' witness values while staying
-- parameterized by era.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ instance HasScriptLanguage PlutusScriptV1 BabbageEra where

instance HasScriptLanguage PlutusScriptV2 BabbageEra where
scriptLanguageInEra = PlutusScriptV2InBabbage

instance HasScriptLanguage PlutusScriptV1 ConwayEra where
scriptLanguageInEra = PlutusScriptV1InConway

instance HasScriptLanguage PlutusScriptV2 ConwayEra where
scriptLanguageInEra = PlutusScriptV2InConway

instance HasScriptLanguage PlutusScriptV3 ConwayEra where
scriptLanguageInEra = PlutusScriptV3InConway
5 changes: 3 additions & 2 deletions hydra-cardano-api/src/Hydra/Cardano/Api/ValidityInterval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Hydra.Cardano.Api.Prelude

import Cardano.Ledger.Allegra.Scripts qualified as Ledger
import Cardano.Ledger.BaseTypes (StrictMaybe (..), maybeToStrictMaybe)
import Hydra.Cardano.Api.AllegraEraOnwards (IsAllegraEraOnwards (..))
import Test.QuickCheck (oneof)

toLedgerValidityInterval ::
Expand All @@ -28,7 +29,7 @@ fromLedgerValidityInterval validityInterval =
let Ledger.ValidityInterval{Ledger.invalidBefore = invalidBefore, Ledger.invalidHereafter = invalidHereAfter} = validityInterval
lowerBound = case invalidBefore of
SNothing -> TxValidityNoLowerBound
SJust s -> TxValidityLowerBound AllegraEraOnwardsBabbage s
SJust s -> TxValidityLowerBound allegraEraOnwards s
upperBound = case invalidHereAfter of
SNothing -> TxValidityUpperBound shelleyBasedEra Nothing
SJust s -> TxValidityUpperBound shelleyBasedEra (Just s)
Expand All @@ -38,7 +39,7 @@ instance Arbitrary (TxValidityLowerBound Era) where
arbitrary =
oneof
[ pure TxValidityNoLowerBound
, TxValidityLowerBound AllegraEraOnwardsBabbage . SlotNo <$> arbitrary
, TxValidityLowerBound allegraEraOnwards . SlotNo <$> arbitrary
]

instance Arbitrary (TxValidityUpperBound Era) where
Expand Down
7 changes: 2 additions & 5 deletions hydra-test-utils/src/Test/Network/Ports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import Hydra.Prelude

import Network.Socket (
PortNumber,
close',
)
import Network.Socket.Free (openFreePort)
import Network.Socket.Free (getFreePort)

-- | Find a TCPv4 port which is likely to be free for listening on
-- @localhost@. This binds a socket, receives an OS-assigned port, then closes
Expand All @@ -19,9 +18,7 @@ import Network.Socket.Free (openFreePort)
-- Do not use this unless you have no other option.
getRandomPort :: IO PortNumber
getRandomPort = do
(port, sock) <- openFreePort
liftIO $ close' sock
return $ fromIntegral port
fromIntegral <$> getFreePort

-- | Find a free TCPv4 port and pass it to the given 'action'.
--
Expand Down

0 comments on commit d3e1aaf

Please sign in to comment.