Skip to content

Commit

Permalink
Address PR feedback and cleanup a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Apr 11, 2023
1 parent a149c57 commit b1b4e38
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 42 deletions.
18 changes: 1 addition & 17 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ tests: True

test-show-details: direct

-- Always write GHC env files, because they are needed by for repl.
-- Always write GHC env files, because they are needed for ghci.
write-ghc-environment-files: always

package snap-server
Expand Down Expand Up @@ -129,22 +129,6 @@ source-repository-package
-- ouroboros-network-protocols
-- ouroboros-consensus-diffusion

-- source-repository-package
-- type: git
-- location: https://github.com/input-output-hk/fs-sim
-- tag: 13a1cfa5a82740c5723fb0a279b3f32f98c8b494
-- --sha256: 1q783gsb0hh4i0slvfwp5nppi8h425pkvj0kqr2lpl06y7y2gq41
-- subdir:
-- fs-api
-- fs-sim

-- Waiting for proper Windows ghc-9.2 release.
source-repository-package
type: git
location: https://github.com/input-output-hk/snap-core
tag: b87b2ffa52bf58867a7239ebe74f61b1a2c762d2
--sha256: 0ndm57z5zpxd5n8s47kh8k1jfqf3b78qv7gkgrx9wwaajs9bf196


source-repository-package
type: git
Expand Down
17 changes: 17 additions & 0 deletions cardano-api/src/Cardano/Api/Eras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}


Expand Down Expand Up @@ -37,6 +38,7 @@ module Cardano.Api.Eras

-- ** Mapping to era types from the Shelley ledger library
, ShelleyLedgerEra
, eraProtVerLow

-- * Cardano eras, as Byron vs Shelley-based
, CardanoEraStyle(..)
Expand All @@ -54,6 +56,8 @@ import Data.Aeson (FromJSON (..), ToJSON, toJSON, withText)
import qualified Data.Text as Text
import Data.Type.Equality (TestEquality (..), (:~:) (Refl))

import qualified Cardano.Ledger.Api as L
import qualified Cardano.Ledger.BaseTypes as L
import Ouroboros.Consensus.Shelley.Eras as Consensus (StandardAllegra, StandardAlonzo,
StandardBabbage, StandardConway, StandardMary, StandardShelley)

Expand Down Expand Up @@ -437,3 +441,16 @@ type family ShelleyLedgerEra era where
ShelleyLedgerEra AlonzoEra = Consensus.StandardAlonzo
ShelleyLedgerEra BabbageEra = Consensus.StandardBabbage
ShelleyLedgerEra ConwayEra = Consensus.StandardConway


-- | Lookup the lower major protocol version for the shelley based era. In other words
-- this is the major protocol version that the era has started in.
eraProtVerLow :: ShelleyBasedEra era -> L.Version
eraProtVerLow era =
case era of
ShelleyBasedEraShelley -> L.eraProtVerLow @L.Shelley
ShelleyBasedEraAllegra -> L.eraProtVerLow @L.Allegra
ShelleyBasedEraMary -> L.eraProtVerLow @L.Mary
ShelleyBasedEraAlonzo -> L.eraProtVerLow @L.Alonzo
ShelleyBasedEraBabbage -> L.eraProtVerLow @L.Babbage
ShelleyBasedEraConway -> L.eraProtVerLow @L.Conway
4 changes: 2 additions & 2 deletions cardano-api/src/Cardano/Api/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Lens.Micro

import Cardano.Ledger.BaseTypes as Ledger
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Crypto (Crypto)
import Cardano.Ledger.Crypto (StandardCrypto)
import Cardano.Ledger.Shelley.Core
import Cardano.Ledger.Shelley.Genesis (NominalDiffTimeMicro, ShelleyGenesis (..),
emptyGenesisStaking)
Expand All @@ -32,7 +32,7 @@ import Cardano.Ledger.Shelley.Genesis (NominalDiffTimeMicro, ShelleyGe
-- * 'sgMaxLovelaceSupply' must be at least the sum of the 'sgInitialFunds'
-- but more if you want to allow for rewards.
--
shelleyGenesisDefaults :: Crypto crypto => ShelleyGenesis crypto
shelleyGenesisDefaults :: ShelleyGenesis StandardCrypto
shelleyGenesisDefaults =
ShelleyGenesis
{
Expand Down
2 changes: 0 additions & 2 deletions cardano-api/src/Cardano/Api/LedgerState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1445,8 +1445,6 @@ instance Error LeadershipError where

nextEpochEligibleLeadershipSlots
:: forall era. ()
-- => Core.EraTxOut (ShelleyLedgerEra era)
-- => Core.EraGovernance (ShelleyLedgerEra era)
=> FromCBOR (Consensus.ChainDepState (Api.ConsensusProtocol era))
=> Consensus.PraosProtocolSupportsNode (Api.ConsensusProtocol era)
=> ShelleyBasedEra era
Expand Down
1 change: 0 additions & 1 deletion cardano-api/src/Cardano/Api/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ import Cardano.Api.Modes
import Cardano.Api.NetworkId
import Cardano.Api.ProtocolParameters
import Cardano.Api.TxBody
import Cardano.Api.Tx (eraProtVerLow)
import Cardano.Api.Value
import Data.Word (Word64)

Expand Down
22 changes: 2 additions & 20 deletions cardano-api/src/Cardano/Api/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ module Cardano.Api.Tx (
-- * Data family instances
AsType(AsTx, AsByronTx, AsShelleyTx, AsMaryTx, AsAllegraTx, AsAlonzoTx,
AsKeyWitness, AsByronWitness, AsShelleyWitness),

-- * Utils
eraProtVerLow,
) where

import Data.Maybe
Expand Down Expand Up @@ -250,15 +247,13 @@ instance IsCardanoEra era => SerialiseAsCBOR (Tx era) where
-- same, but they can be handled generally with one overloaded implementation.
--
serialiseShelleyBasedTx :: forall ledgerera .
L.Era ledgerera
=> CBOR.EncCBOR (L.Tx ledgerera)
L.EraTx ledgerera
=> L.Tx ledgerera
-> ByteString
serialiseShelleyBasedTx = CBOR.serialize' (L.eraProtVerLow @ledgerera)

deserialiseShelleyBasedTx :: forall ledgerera tx' .
L.Era ledgerera
=> CBOR.DecCBOR (CBOR.Annotator (L.Tx ledgerera))
L.EraTx ledgerera
=> (L.Tx ledgerera -> tx')
-> ByteString
-> Either CBOR.DecoderError tx'
Expand Down Expand Up @@ -403,19 +398,6 @@ pattern AsShelleyWitness :: AsType (KeyWitness ShelleyEra)
pattern AsShelleyWitness = AsKeyWitness AsShelleyEra
{-# COMPLETE AsShelleyWitness #-}

-- This could be a useful function in other places, so it would be nice to find a beter
-- home for it.
-- | Lookup the lower major protocol version for the shelley based era
eraProtVerLow :: ShelleyBasedEra era -> CBOR.Version
eraProtVerLow era =
case era of
ShelleyBasedEraShelley -> L.eraProtVerLow @L.Shelley
ShelleyBasedEraAllegra -> L.eraProtVerLow @L.Allegra
ShelleyBasedEraMary -> L.eraProtVerLow @L.Mary
ShelleyBasedEraAlonzo -> L.eraProtVerLow @L.Alonzo
ShelleyBasedEraBabbage -> L.eraProtVerLow @L.Babbage
ShelleyBasedEraConway -> L.eraProtVerLow @L.Conway

-- This custom instance differs from cardano-ledger
-- because we want to be able to tell the difference between
-- on disk witnesses for the cli's 'assemble' command.
Expand Down
9 changes: 9 additions & 0 deletions cardano-api/src/Cardano/Api/TxMetadata.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ instance SerialiseAsCBOR TxMetadata where
-- This is a workaround. There is a tiny chance that serialization could change
-- for Metadata in the future, depending on the era it is being used in. For now
-- we can pretend like it is the same for all eras starting with Shelley
--
-- Versioned cbor works only when we have protocol version available during
-- [de]serialization. The only two ways to fix this:
--
-- - Paramterize TxMetadata with era. This would allow us to get protocol version
-- from the type level
--
-- - Change SerialiseAsCBOR interface in such a way that it allows major
-- protocol version be supplied as an argument.
CBOR.serialize' CBOR.shelleyProtVer
. toShelleyMetadata
. (\(TxMetadata m) -> m)
Expand Down

0 comments on commit b1b4e38

Please sign in to comment.