Skip to content

Commit

Permalink
Document GADT constructor arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy authored and palas committed Jul 6, 2024
1 parent 19da63d commit 3d95c7d
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 6 deletions.
1 change: 1 addition & 0 deletions cardano-api/internal/Cardano/Api/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ fromShelleyAddrIsSbe sbe = \case

fromShelleyAddr
:: ShelleyBasedEra era
-- ^ Witness that the era is shelley era onwards
-> Shelley.Addr StandardCrypto
-> AddressInEra era
fromShelleyAddr _ (Shelley.AddrBootstrap (Shelley.BootstrapAddress addr)) =
Expand Down
2 changes: 2 additions & 0 deletions cardano-api/internal/Cardano/Api/Block.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ getShelleyBlockTxs era (Ledger.Block _header txs) =
data BlockInMode where
BlockInMode
:: CardanoEra era
-- ^ The era of the block
-> Block era
-- ^ The block itself
-> BlockInMode

deriving instance Show BlockInMode
Expand Down
43 changes: 43 additions & 0 deletions cardano-api/internal/Cardano/Api/Certificate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,17 @@ data DRepMetadataReference
data StakeAddressRequirements era where
StakeAddrRegistrationConway
:: ConwayEraOnwards era
-- ^ Witness that the era is conway onwards
-> L.Coin
-- ^ Deposit
-> StakeCredential
-- ^ Stake credential
-> StakeAddressRequirements era
StakeAddrRegistrationPreConway
:: ShelleyToBabbageEra era
-- ^ Witness that the era is shelley to babbage
-> StakeCredential
-- ^ Stake credential
-> StakeAddressRequirements era

makeStakeAddressRegistrationCertificate :: StakeAddressRequirements era -> Certificate era
Expand Down Expand Up @@ -281,13 +286,19 @@ makeStakeAddressUnregistrationCertificate req =
data StakeDelegationRequirements era where
StakeDelegationRequirementsConwayOnwards
:: ConwayEraOnwards era
-- ^ Witness that the era is conway onwards
-> StakeCredential
-- ^ Stake credential
-> Ledger.Delegatee (EraCrypto (ShelleyLedgerEra era))
-- ^ Delegatee
-> StakeDelegationRequirements era
StakeDelegationRequirementsPreConway
:: ShelleyToBabbageEra era
-- ^ Witness that the era is shelley to babbage
-> StakeCredential
-- ^ Stake credential
-> PoolId
-- ^ Pool id
-> StakeDelegationRequirements era

makeStakeAddressDelegationCertificate :: StakeDelegationRequirements era -> Certificate era
Expand All @@ -304,11 +315,15 @@ makeStakeAddressDelegationCertificate = \case
data StakePoolRegistrationRequirements era where
StakePoolRegistrationRequirementsConwayOnwards
:: ConwayEraOnwards era
-- ^ Witness that the era is conway onwards
-> Ledger.PoolParams (EraCrypto (ShelleyLedgerEra era))
-- ^ Pool parameters
-> StakePoolRegistrationRequirements era
StakePoolRegistrationRequirementsPreConway
:: ShelleyToBabbageEra era
-- ^ Witness that the era is shelley to babbage
-> Ledger.PoolParams (EraCrypto (ShelleyLedgerEra era))
-- ^ Pool parameters
-> StakePoolRegistrationRequirements era

makeStakePoolRegistrationCertificate
Expand All @@ -328,13 +343,19 @@ makeStakePoolRegistrationCertificate = \case
data StakePoolRetirementRequirements era where
StakePoolRetirementRequirementsConwayOnwards
:: ConwayEraOnwards era
-- ^ Witness that the era is conway onwards
-> PoolId
-- ^ Pool id
-> Ledger.EpochNo
-- ^ Retirement epoch number
-> StakePoolRetirementRequirements era
StakePoolRetirementRequirementsPreConway
:: ShelleyToBabbageEra era
-- ^ Witness that the era is shelley to babbage
-> PoolId
-- ^ Pool id
-> Ledger.EpochNo
-- ^ Retirement epoch number
-> StakePoolRetirementRequirements era

makeStakePoolRetirementCertificate
Expand All @@ -355,9 +376,13 @@ makeStakePoolRetirementCertificate req =
data GenesisKeyDelegationRequirements ere where
GenesisKeyDelegationRequirements
:: ShelleyToBabbageEra era
-- ^ Witness that the era is shelley to babbage
-> Hash GenesisKey
-- ^ Genesis key hash
-> Hash GenesisDelegateKey
-- ^ Genesis delegate key hash
-> Hash VrfKey
-- ^ VRF key hash
-> GenesisKeyDelegationRequirements era

makeGenesisKeyDelegationCertificate :: GenesisKeyDelegationRequirements era -> Certificate era
Expand All @@ -376,8 +401,11 @@ makeGenesisKeyDelegationCertificate
data MirCertificateRequirements era where
MirCertificateRequirements
:: ShelleyToBabbageEra era
-- ^ Witness that the era is shelley to babbage
-> Ledger.MIRPot
-- ^ MIR pot
-> Ledger.MIRTarget (EraCrypto (ShelleyLedgerEra era))
-- ^ MIR target
-> MirCertificateRequirements era

makeMIRCertificate
Expand All @@ -392,8 +420,11 @@ makeMIRCertificate (MirCertificateRequirements atMostEra mirPot mirTarget) =
data DRepRegistrationRequirements era where
DRepRegistrationRequirements
:: ConwayEraOnwards era
-- ^ Witness that the era is conway onwards
-> (Ledger.Credential Ledger.DRepRole (EraCrypto (ShelleyLedgerEra era)))
-- ^ DRep credential
-> L.Coin
-- ^ Deposit
-> DRepRegistrationRequirements era

makeDrepRegistrationCertificate
Expand All @@ -409,8 +440,11 @@ makeDrepRegistrationCertificate (DRepRegistrationRequirements conwayOnwards vcre
data CommitteeHotKeyAuthorizationRequirements era where
CommitteeHotKeyAuthorizationRequirements
:: ConwayEraOnwards era
-- ^ Witness that the era is conway onwards
-> Ledger.Credential Ledger.ColdCommitteeRole (EraCrypto (ShelleyLedgerEra era))
-- ^ Cold key credential
-> Ledger.Credential Ledger.HotCommitteeRole (EraCrypto (ShelleyLedgerEra era))
-- ^ Hot key credential
-> CommitteeHotKeyAuthorizationRequirements era

makeCommitteeHotKeyAuthorizationCertificate
Expand All @@ -425,8 +459,11 @@ makeCommitteeHotKeyAuthorizationCertificate (CommitteeHotKeyAuthorizationRequire
data CommitteeColdkeyResignationRequirements era where
CommitteeColdkeyResignationRequirements
:: ConwayEraOnwards era
-- ^ Witness that the era is conway onwards
-> Ledger.Credential Ledger.ColdCommitteeRole (EraCrypto (ShelleyLedgerEra era))
-- ^ Cold key credential
-> Maybe (Ledger.Anchor (EraCrypto (ShelleyLedgerEra era)))
-- ^ Anchor
-> CommitteeColdkeyResignationRequirements era

makeCommitteeColdkeyResignationCertificate
Expand All @@ -443,8 +480,11 @@ makeCommitteeColdkeyResignationCertificate (CommitteeColdkeyResignationRequireme
data DRepUnregistrationRequirements era where
DRepUnregistrationRequirements
:: ConwayEraOnwards era
-- ^ Witness that the era is conway onwards
-> (Ledger.Credential Ledger.DRepRole (EraCrypto (ShelleyLedgerEra era)))
-- ^ DRep credential
-> L.Coin
-- ^ Deposit
-> DRepUnregistrationRequirements era

makeDrepUnregistrationCertificate
Expand All @@ -471,7 +511,9 @@ makeStakeAddressAndDRepDelegationCertificate w cred delegatee deposit =
data DRepUpdateRequirements era where
DRepUpdateRequirements
:: ConwayEraOnwards era
-- ^ Witness that the era is conway onwards
-> Ledger.Credential Ledger.DRepRole (EraCrypto (ShelleyLedgerEra era))
-- ^ DRep credential
-> DRepUpdateRequirements era

makeDrepUpdateCertificate
Expand All @@ -489,6 +531,7 @@ makeDrepUpdateCertificate (DRepUpdateRequirements conwayOnwards vcred) mAnchor =

getTxCertWitness
:: ShelleyBasedEra era
-- ^ Witness that the era is shelley era onwards
-> Ledger.TxCert (ShelleyLedgerEra era)
-> Maybe StakeCredential
getTxCertWitness sbe ledgerCert = shelleyBasedEraConstraints sbe $
Expand Down
6 changes: 5 additions & 1 deletion cardano-api/internal/Cardano/Api/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ throwErrorAsException :: Error e => e -> IO a
throwErrorAsException e = throwIO (ErrorAsException e)

data ErrorAsException where
ErrorAsException :: Error e => e -> ErrorAsException
ErrorAsException
:: Error e
=> e
-- ^ The error
-> ErrorAsException

instance Error ErrorAsException where
prettyError (ErrorAsException e) =
Expand Down
1 change: 1 addition & 0 deletions cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ data ResolvablePointers where
, Ledger.ScriptHash Ledger.StandardCrypto
)
)
-- ^ A mapping of pointers that are possible to resolve
-> ResolvablePointers

deriving instance Show ResolvablePointers
Expand Down
9 changes: 9 additions & 0 deletions cardano-api/internal/Cardano/Api/InMode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ data TxInMode where
-- | Shelley based transactions.
TxInMode
:: ShelleyBasedEra era
-- ^ Witness that the era is shelley era onwards
-> Tx era
-- ^ The transaction itself
-> TxInMode
-- | Legacy Byron transactions and things we can
-- post to the chain which are not actually transactions.
Expand Down Expand Up @@ -146,7 +148,9 @@ toConsensusGenTx (TxInMode ShelleyBasedEraConway (ShelleyTx _ tx)) =
data TxIdInMode where
TxIdInMode
:: CardanoEra era
-- ^ The cardano era
-> TxId
-- ^ The transaction id
-> TxIdInMode

toConsensusTxId
Expand Down Expand Up @@ -202,10 +206,13 @@ toConsensusTxId (TxIdInMode ConwayEra txid) =
data TxValidationError era where
ByronTxValidationError
:: Consensus.ApplyTxErr Consensus.ByronBlock
-- ^ The error from trying to submit a Byron transaction
-> TxValidationError era
ShelleyTxValidationError
:: ShelleyBasedEra era
-- ^ Witness that the era is shelley era onwards
-> Consensus.ApplyTxErr (Consensus.ShelleyBlock (ConsensusProtocol era) (ShelleyLedgerEra era))
-- ^ The error from trying to submit a Shelley transaction
-> TxValidationError era

deriving instance Generic (TxValidationError era)
Expand Down Expand Up @@ -258,10 +265,12 @@ data TxValidationErrorInCardanoMode where
TxValidationErrorInCardanoMode
:: ()
=> TxValidationError era
-- ^ The transaction validation error
-> TxValidationErrorInCardanoMode
TxValidationEraMismatch
:: ()
=> EraMismatch
-- ^ The error from trying to submit a transaction to the wrong era
-> TxValidationErrorInCardanoMode

deriving instance Show TxValidationErrorInCardanoMode
Expand Down
1 change: 1 addition & 0 deletions cardano-api/internal/Cardano/Api/Modes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import qualified Ouroboros.Consensus.Shelley.ShelleyHFC as Consensus
data ConsensusModeParams where
CardanoModeParams
:: Byron.EpochSlots
-- ^ The number of slots in an epoch.
-> ConsensusModeParams

deriving instance Show ConsensusModeParams
Expand Down
24 changes: 24 additions & 0 deletions cardano-api/internal/Cardano/Api/ProtocolParameters.hs
Original file line number Diff line number Diff line change
Expand Up @@ -209,39 +209,63 @@ createPParams sbe ebPParamsUpdate =
data EraBasedProtocolParametersUpdate era where
ShelleyEraBasedProtocolParametersUpdate
:: CommonProtocolParametersUpdate
-- ^ Common protocol parameters
-> DeprecatedAfterMaryPParams ShelleyEra
-- ^ Protocol parameters that have been deprecated after Mary
-> DeprecatedAfterBabbagePParams ShelleyEra
-- ^ Protocol parameters that have been deprecated after Babbage
-> ShelleyToAlonzoPParams ShelleyEra
-- ^ Protocol parameters that have been deprecated after Alonzo
-> EraBasedProtocolParametersUpdate ShelleyEra
AllegraEraBasedProtocolParametersUpdate
:: CommonProtocolParametersUpdate
-- ^ Common protocol parameters
-> DeprecatedAfterMaryPParams AllegraEra
-- ^ Protocol parameters that have been deprecated after Mary
-> ShelleyToAlonzoPParams AllegraEra
-- ^ Protocol parameters that have been deprecated after Alonzo
-> DeprecatedAfterBabbagePParams ShelleyEra
-- ^ Protocol parameters that have been deprecated after Babbage
-> EraBasedProtocolParametersUpdate AllegraEra
MaryEraBasedProtocolParametersUpdate
:: CommonProtocolParametersUpdate
-- ^ Common protocol parameters
-> DeprecatedAfterMaryPParams MaryEra
-- ^ Protocol parameters that have been deprecated after Mary
-> ShelleyToAlonzoPParams MaryEra
-- ^ Protocol parameters that have been deprecated after Alonzo
-> DeprecatedAfterBabbagePParams ShelleyEra
-- ^ Protocol parameters that have been deprecated after Babbage
-> EraBasedProtocolParametersUpdate MaryEra
AlonzoEraBasedProtocolParametersUpdate
:: CommonProtocolParametersUpdate
-- ^ Common protocol parameters
-> ShelleyToAlonzoPParams AlonzoEra
-- ^ Protocol parameters that have been deprecated after Alonzo
-> AlonzoOnwardsPParams AlonzoEra
-- ^ Protocol parameters that have been introduced in Alonzo
-> DeprecatedAfterBabbagePParams ShelleyEra
-- ^ Protocol parameters that have been deprecated after Babbage
-> EraBasedProtocolParametersUpdate AlonzoEra
BabbageEraBasedProtocolParametersUpdate
:: CommonProtocolParametersUpdate
-- ^ Common protocol parameters
-> AlonzoOnwardsPParams BabbageEra
-- ^ Protocol parameters that have been introduced in Babbage
-> DeprecatedAfterBabbagePParams ShelleyEra
-- ^ Protocol parameters that have been deprecated after Babbage
-> IntroducedInBabbagePParams BabbageEra
-- ^ Protocol parameters that have been introduced in Babbage
-> EraBasedProtocolParametersUpdate BabbageEra
ConwayEraBasedProtocolParametersUpdate
:: CommonProtocolParametersUpdate
-- ^ Common protocol parameters
-> AlonzoOnwardsPParams ConwayEra
-- ^ Protocol parameters that have been introduced in Conway
-> IntroducedInBabbagePParams ConwayEra
-- ^ Protocol parameters that have been introduced in Babbage
-> IntroducedInConwayPParams (ShelleyLedgerEra ConwayEra)
-- ^ Protocol parameters that have been introduced in Conway
-> EraBasedProtocolParametersUpdate ConwayEra

deriving instance Show (EraBasedProtocolParametersUpdate era)
Expand Down
10 changes: 10 additions & 0 deletions cardano-api/internal/Cardano/Api/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ data QueryInMode result where
:: QueryInMode AnyCardanoEra
QueryInEra
:: QueryInEra era result
-- ^ Query in a specific era
-> QueryInMode (Either EraMismatch result)
QueryEraHistory
:: QueryInMode EraHistory
Expand All @@ -164,6 +165,7 @@ data EraHistory where
EraHistory
:: Consensus.CardanoBlock L.StandardCrypto ~ Consensus.HardForkBlock xs
=> History.Interpreter xs
-- ^ The history interpreter for the hard fork combinator
-> EraHistory

getProgress
Expand Down Expand Up @@ -237,15 +239,19 @@ data QueryInShelleyBasedEra era result where
:: QueryInShelleyBasedEra era (Map (Hash StakePoolKey) Rational)
QueryUTxO
:: QueryUTxOFilter
-- ^ Filter the UTxO by this filter
-> QueryInShelleyBasedEra era (UTxO era)
QueryStakeAddresses
:: Set StakeCredential
-- ^ Stake addresses to query
-> NetworkId
-- ^ Network ID
-> QueryInShelleyBasedEra era (Map StakeAddress L.Coin, Map StakeAddress PoolId)
QueryStakePools
:: QueryInShelleyBasedEra era (Set PoolId)
QueryStakePoolParameters
:: Set PoolId
-- ^ Stake pools to query
-> QueryInShelleyBasedEra era (Map PoolId StakePoolParameters)
-- TODO: add support for RewardProvenance
-- QueryPoolRanking
Expand All @@ -259,15 +265,19 @@ data QueryInShelleyBasedEra era result where
:: QueryInShelleyBasedEra era (SerialisedCurrentEpochState era)
QueryPoolState
:: Maybe (Set PoolId)
-- ^ Stake pools to query
-> QueryInShelleyBasedEra era (SerialisedPoolState era)
QueryPoolDistribution
:: Maybe (Set PoolId)
-- ^ Stake pools to query
-> QueryInShelleyBasedEra era (SerialisedPoolDistribution era)
QueryStakeSnapshot
:: Maybe (Set PoolId)
-- ^ Stake pools to query
-> QueryInShelleyBasedEra era (SerialisedStakeSnapshots era)
QueryStakeDelegDeposits
:: Set StakeCredential
-- ^ Stake addresses to query
-> QueryInShelleyBasedEra era (Map StakeCredential L.Coin)
QueryAccountState
:: QueryInShelleyBasedEra era L.AccountState
Expand Down
2 changes: 2 additions & 0 deletions cardano-api/internal/Cardano/Api/SerialiseLedgerCddl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,13 @@ data FromSomeTypeCDDL c b where
:: Text
-- ^ CDDL type that we want
-> (InAnyShelleyBasedEra Tx -> b)
-- ^ Function to convert the tx to the desired type
-> FromSomeTypeCDDL TextEnvelope b
FromCDDLWitness
:: Text
-- ^ CDDL type that we want
-> (InAnyShelleyBasedEra KeyWitness -> b)
-- ^ Function to convert the witness to the desired type
-> FromSomeTypeCDDL TextEnvelope b

deserialiseFromTextEnvelopeCddlAnyOf
Expand Down
Loading

0 comments on commit 3d95c7d

Please sign in to comment.