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

More API updates for the Allegra and Mary eras #2111

Merged
merged 31 commits into from
Nov 25, 2020
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fc87d88
Generalise toShelleyStakeAddr to work for any ledger era
dcoutts Nov 21, 2020
12fd233
Move and generalise toShelley{Metadata,MetadataHash} functions
dcoutts Nov 21, 2020
b10061d
Generalise toShelleyWithdrawal over all ledger eras
dcoutts Nov 21, 2020
1d32e24
Move toShelleyUpdate to the ProtocolParameters module
dcoutts Nov 21, 2020
3225463
Change type of Praos extra entropy update parameter
dcoutts Nov 21, 2020
dfdb712
Add functions to convert from Shelley update proposal types
dcoutts Nov 21, 2020
73a6ebf
Change representation of UpdateProposal to use the API types
dcoutts Nov 21, 2020
9fff1ad
Export UpdateProposal and protocol params from the API
dcoutts Nov 21, 2020
e9b2245
Generalise to/fromShelleyUpdate over all ledger eras
dcoutts Nov 21, 2020
e29ce3c
Change the API's stake pool metadata URL type to match ledger type
dcoutts Nov 21, 2020
92b8158
Add a fromShelleyPoolParams to allow conversion both ways
dcoutts Nov 21, 2020
1354aa3
Add to/fromShelleyCertificate conversion functions
dcoutts Nov 21, 2020
c026892
Change certificate representation to use surface types
dcoutts Nov 22, 2020
e85ad6e
Generalise the toShelley*Credential functions for all eras
dcoutts Nov 22, 2020
eb6ea84
Generalise to/fromShelleyCertificate over all eras
dcoutts Nov 22, 2020
f095db2
Generalise toShelley{TxId,TxIn,TxOut} over all ledger eras
dcoutts Nov 22, 2020
7a9cd1f
Use single Eq, Show and HasTypeProxy instance for TxBody
dcoutts Nov 22, 2020
afa2961
Use single SerialiseAsCBOR and HasTextEnvelope instance for TxBody
dcoutts Nov 22, 2020
580e50c
Initial step to generalise makeShelleyTransaction over other eras
dcoutts Nov 22, 2020
630f02d
Switch TxBody from Shelley-specific type to era-dependent
dcoutts Nov 22, 2020
67b78cf
Generalise the ShelleyTxBody representation over multiple eras
dcoutts Nov 22, 2020
134403f
Generalise several tx and witness functions over eras
dcoutts Nov 22, 2020
b54ad58
Extend TxBody serialisation to the Allegra and Mary eras
dcoutts Nov 23, 2020
49edfcb
Partially fill in makeShelleyTransaction for the Allegra & Mary eras
dcoutts Nov 23, 2020
ea18858
Add to/fromShelleyScriptHash and use them
dcoutts Nov 23, 2020
4b476ce
Add to/fromMaryValue for converting the Value type
dcoutts Nov 23, 2020
f6db51c
Cover the multi-asset case in toShelleyTxOut
dcoutts Nov 23, 2020
844dde7
Adjust the sort order of Value entries
dcoutts Nov 23, 2020
eaa770e
Move toByronLovelace and TxIn/TxOut declarations
dcoutts Nov 23, 2020
dde3664
Move TxOutValue and MintValue types to TxBody module
dcoutts Nov 23, 2020
ee54b49
Make hlint suggestions
intricate Nov 24, 2020
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
27 changes: 18 additions & 9 deletions cardano-api/src/Cardano/Api/ProtocolParameters.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

-- | Protocol parameters.
Expand Down Expand Up @@ -37,6 +38,8 @@ import Control.Monad

import Cardano.Slotting.Slot (EpochNo)
import qualified Cardano.Crypto.Hash.Class as Crypto

import qualified Cardano.Ledger.Era as Ledger
import Ouroboros.Consensus.Shelley.Eras (StandardShelley)
import Ouroboros.Consensus.Shelley.Protocol.Crypto (StandardCrypto)

Expand Down Expand Up @@ -77,10 +80,12 @@ instance HasTextEnvelope UpdateProposal where
textEnvelopeType _ = "UpdateProposalShelley"

instance ToCBOR UpdateProposal where
toCBOR = toCBOR . toShelleyUpdate
toCBOR = toCBOR . toShelleyUpdate @StandardShelley
-- We have to pick a monomorphic era type for the serialisation. We use the
-- Shelley era. This makes no difference since era type is phantom.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we define a type synonym to make this clear. Something like:

type ShelleyOnwardsCrypto = StandardShelley or something with a better name 😁


instance FromCBOR UpdateProposal where
fromCBOR = fromShelleyUpdate <$> fromCBOR
fromCBOR = fromShelleyUpdate @StandardShelley <$> fromCBOR

data ProtocolParametersUpdate =
ProtocolParametersUpdate {
Expand Down Expand Up @@ -256,21 +261,23 @@ makeShelleyUpdateProposal params genesisKeyHashes epochno =
epochno


toShelleyUpdate :: UpdateProposal -> Shelley.Update StandardShelley
toShelleyUpdate :: Ledger.Crypto ledgerera ~ StandardCrypto
=> UpdateProposal -> Shelley.Update ledgerera
toShelleyUpdate (UpdateProposal ppup epochno) =
Shelley.Update (toShelleyProposedPPUpdates ppup) epochno


toShelleyProposedPPUpdates :: Map (Hash GenesisKey) ProtocolParametersUpdate
-> Shelley.ProposedPPUpdates StandardShelley
toShelleyProposedPPUpdates :: Ledger.Crypto ledgerera ~ StandardCrypto
=> Map (Hash GenesisKey) ProtocolParametersUpdate
-> Shelley.ProposedPPUpdates ledgerera
toShelleyProposedPPUpdates =
Shelley.ProposedPPUpdates
. Map.mapKeysMonotonic (\(GenesisKeyHash kh) -> kh)
. Map.map toShelleyPParamsUpdate


toShelleyPParamsUpdate :: ProtocolParametersUpdate
-> Shelley.PParamsUpdate StandardShelley
-> Shelley.PParamsUpdate ledgerera
toShelleyPParamsUpdate
ProtocolParametersUpdate {
protocolUpdateProtocolVersion
Expand Down Expand Up @@ -320,20 +327,22 @@ toShelleyPParamsUpdate
maybeToStrictMaybe protocolUpdateMinPoolCost
}

fromShelleyUpdate :: Shelley.Update StandardShelley -> UpdateProposal
fromShelleyUpdate :: Ledger.Crypto ledgerera ~ StandardCrypto
=> Shelley.Update ledgerera -> UpdateProposal
fromShelleyUpdate (Shelley.Update ppup epochno) =
UpdateProposal (fromShelleyProposedPPUpdates ppup) epochno


fromShelleyProposedPPUpdates :: Shelley.ProposedPPUpdates StandardShelley
fromShelleyProposedPPUpdates :: Ledger.Crypto ledgerera ~ StandardCrypto
=> Shelley.ProposedPPUpdates ledgerera
-> Map (Hash GenesisKey) ProtocolParametersUpdate
fromShelleyProposedPPUpdates =
Map.map fromShelleyPParamsUpdate
. Map.mapKeysMonotonic GenesisKeyHash
. (\(Shelley.ProposedPPUpdates ppup) -> ppup)


fromShelleyPParamsUpdate :: Shelley.PParamsUpdate StandardShelley
fromShelleyPParamsUpdate :: Shelley.PParamsUpdate ledgerera
-> ProtocolParametersUpdate
fromShelleyPParamsUpdate
Shelley.PParams {
Expand Down