Skip to content

Commit

Permalink
Convert UpdateProposalFeatureSupportedInEra to UpdateProposalFeature …
Browse files Browse the repository at this point in the history
…using new Feature API.
  • Loading branch information
newhoggy committed Jun 9, 2023
1 parent e9b9e91 commit f25d117
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 85 deletions.
13 changes: 1 addition & 12 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ module Test.Gen.Cardano.Api.Typed
, genTxOutValue
, genTxReturnCollateral
, genTxTotalCollateral
, genTxUpdateProposal
, genTxValidityLowerBound
, genTxValidityRange
, genTxValidityUpperBound
Expand Down Expand Up @@ -604,16 +603,6 @@ genCertificate =
, StakeAddressDeregistrationCertificate <$> genStakeCredential
]

genTxUpdateProposal :: CardanoEra era -> Gen (TxUpdateProposal era)
genTxUpdateProposal era =
case updateProposalSupportedInEra era of
Nothing -> pure TxUpdateProposalNone
Just supported ->
Gen.choice
[ pure TxUpdateProposalNone
, TxUpdateProposal supported <$> genUpdateProposal era
]

genTxMintValue :: CardanoEra era -> Gen (TxMintValue BuildTx era)
genTxMintValue era =
case multiAssetSupportedInEra era of
Expand All @@ -640,7 +629,7 @@ genTxBodyContent era = do
txProtocolParams <- BuildTxWith <$> Gen.maybe (genValidProtocolParameters era)
txWithdrawals <- genTxWithdrawals era
txCertificates <- genTxCertificates era
txUpdateProposal <- genTxUpdateProposal era
txUpdateProposal <- genFeatureValueInEra (genUpdateProposal era) era
txMintValue <- genTxMintValue era
txScriptValidity <- genFeatureValueInEra genScriptValidity era

Expand Down
4 changes: 2 additions & 2 deletions cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ estimateTransactionKeyWitnessCount TxBodyContent {
_ -> 0

+ case txUpdateProposal of
TxUpdateProposal _ (UpdateProposal updatePerGenesisKey _)
FeatureValue _ (UpdateProposal updatePerGenesisKey _)
-> Map.size updatePerGenesisKey
_ -> 0
NoFeatureValue -> 0


-- ----------------------------------------------------------------------------
Expand Down
108 changes: 40 additions & 68 deletions cardano-api/internal/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ module Cardano.Api.TxBody (
TxExtraKeyWitnesses(..),
TxWithdrawals(..),
TxCertificates(..),
TxUpdateProposal(..),
TxMintValue(..),

-- ** Building vs viewing transactions
Expand All @@ -127,7 +126,7 @@ module Cardano.Api.TxBody (
ScriptDataSupportedInEra(..),
WithdrawalsSupportedInEra(..),
CertificatesSupportedInEra(..),
UpdateProposalSupportedInEra(..),
UpdateProposalFeature(..),
TxTotalAndReturnCollateralSupportedInEra(..),

-- ** Feature availability functions
Expand All @@ -143,7 +142,6 @@ module Cardano.Api.TxBody (
scriptDataSupportedInEra,
withdrawalsSupportedInEra,
certificatesSupportedInEra,
updateProposalSupportedInEra,
totalAndReturnCollateralSupportedInEra,

-- * Inspecting 'ScriptWitness'es
Expand Down Expand Up @@ -1247,27 +1245,26 @@ certificatesSupportedInEra ConwayEra = Just CertificatesInConwayEra
-- era has a notion of an update proposal, but it is a standalone chain object
-- and not embedded in a transaction.
--
data UpdateProposalSupportedInEra era where

UpdateProposalInShelleyEra :: UpdateProposalSupportedInEra ShelleyEra
UpdateProposalInAllegraEra :: UpdateProposalSupportedInEra AllegraEra
UpdateProposalInMaryEra :: UpdateProposalSupportedInEra MaryEra
UpdateProposalInAlonzoEra :: UpdateProposalSupportedInEra AlonzoEra
UpdateProposalInBabbageEra :: UpdateProposalSupportedInEra BabbageEra
UpdateProposalInConwayEra :: UpdateProposalSupportedInEra ConwayEra

deriving instance Eq (UpdateProposalSupportedInEra era)
deriving instance Show (UpdateProposalSupportedInEra era)

updateProposalSupportedInEra :: CardanoEra era
-> Maybe (UpdateProposalSupportedInEra era)
updateProposalSupportedInEra ByronEra = Nothing
updateProposalSupportedInEra ShelleyEra = Just UpdateProposalInShelleyEra
updateProposalSupportedInEra AllegraEra = Just UpdateProposalInAllegraEra
updateProposalSupportedInEra MaryEra = Just UpdateProposalInMaryEra
updateProposalSupportedInEra AlonzoEra = Just UpdateProposalInAlonzoEra
updateProposalSupportedInEra BabbageEra = Just UpdateProposalInBabbageEra
updateProposalSupportedInEra ConwayEra = Just UpdateProposalInConwayEra
data UpdateProposalFeature era where
UpdateProposalInShelleyEra :: UpdateProposalFeature ShelleyEra
UpdateProposalInAllegraEra :: UpdateProposalFeature AllegraEra
UpdateProposalInMaryEra :: UpdateProposalFeature MaryEra
UpdateProposalInAlonzoEra :: UpdateProposalFeature AlonzoEra
UpdateProposalInBabbageEra :: UpdateProposalFeature BabbageEra
UpdateProposalInConwayEra :: UpdateProposalFeature ConwayEra

deriving instance Eq (UpdateProposalFeature era)
deriving instance Show (UpdateProposalFeature era)

instance FeatureInEra UpdateProposalFeature where
featureInEra no yes = \case
ByronEra -> no
ShelleyEra -> yes UpdateProposalInShelleyEra
AllegraEra -> yes UpdateProposalInAllegraEra
MaryEra -> yes UpdateProposalInMaryEra
AlonzoEra -> yes UpdateProposalInAlonzoEra
BabbageEra -> yes UpdateProposalInBabbageEra
ConwayEra -> yes UpdateProposalInConwayEra

-- ----------------------------------------------------------------------------
-- Building vs viewing transactions
Expand Down Expand Up @@ -1662,21 +1659,6 @@ data TxCertificates build era where
deriving instance Eq (TxCertificates build era)
deriving instance Show (TxCertificates build era)

-- ----------------------------------------------------------------------------
-- Transaction update proposal (era-dependent)
--

data TxUpdateProposal era where

TxUpdateProposalNone :: TxUpdateProposal era

TxUpdateProposal :: UpdateProposalSupportedInEra era
-> UpdateProposal
-> TxUpdateProposal era

deriving instance Eq (TxUpdateProposal era)
deriving instance Show (TxUpdateProposal era)

-- ----------------------------------------------------------------------------
-- Value minting within transactions (era-dependent)
--
Expand Down Expand Up @@ -1715,7 +1697,7 @@ data TxBodyContent build era =
txProtocolParams :: BuildTxWith build (Maybe ProtocolParameters),
txWithdrawals :: TxWithdrawals build era,
txCertificates :: TxCertificates build era,
txUpdateProposal :: TxUpdateProposal era,
txUpdateProposal :: FeatureValue UpdateProposalFeature era UpdateProposal,
txMintValue :: TxMintValue build era,
txScriptValidity :: FeatureValue TxScriptValidityFeature era ScriptValidity
}
Expand All @@ -1737,7 +1719,7 @@ defaultTxBodyContent = TxBodyContent
, txProtocolParams = BuildTxWith Nothing
, txWithdrawals = TxWithdrawalsNone
, txCertificates = TxCertificatesNone
, txUpdateProposal = TxUpdateProposalNone
, txUpdateProposal = NoFeatureValue
, txMintValue = TxMintNone
, txScriptValidity = NoFeatureValue
}
Expand Down Expand Up @@ -1796,7 +1778,7 @@ setTxWithdrawals v txBodyContent = txBodyContent { txWithdrawals = v }
setTxCertificates :: TxCertificates build era -> TxBodyContent build era -> TxBodyContent build era
setTxCertificates v txBodyContent = txBodyContent { txCertificates = v }

setTxUpdateProposal :: TxUpdateProposal era -> TxBodyContent build era -> TxBodyContent build era
setTxUpdateProposal :: FeatureValue UpdateProposalFeature era UpdateProposal -> TxBodyContent build era -> TxBodyContent build era
setTxUpdateProposal v txBodyContent = txBodyContent { txUpdateProposal = v }

setTxMintValue :: TxMintValue build era -> TxBodyContent build era -> TxBodyContent build era
Expand Down Expand Up @@ -3251,45 +3233,35 @@ fromLedgerTxCertificates era body =
fromLedgerTxUpdateProposal
:: ShelleyBasedEra era
-> Ledger.TxBody (ShelleyLedgerEra era)
-> TxUpdateProposal era
-> FeatureValue UpdateProposalFeature era UpdateProposal
fromLedgerTxUpdateProposal era body =
case era of
ShelleyBasedEraShelley ->
case body ^. L.updateTxBodyL of
SNothing -> TxUpdateProposalNone
SJust p ->
TxUpdateProposal UpdateProposalInShelleyEra
(fromLedgerUpdate era p)
SNothing -> NoFeatureValue
SJust p -> FeatureValue UpdateProposalInShelleyEra (fromLedgerUpdate era p)

ShelleyBasedEraAllegra ->
case body ^. L.updateTxBodyL of
SNothing -> TxUpdateProposalNone
SJust p ->
TxUpdateProposal UpdateProposalInAllegraEra
(fromLedgerUpdate era p)
SNothing -> NoFeatureValue
SJust p -> FeatureValue UpdateProposalInAllegraEra (fromLedgerUpdate era p)

ShelleyBasedEraMary ->
case body ^. L.updateTxBodyL of
SNothing -> TxUpdateProposalNone
SJust p ->
TxUpdateProposal UpdateProposalInMaryEra
(fromLedgerUpdate era p)
SNothing -> NoFeatureValue
SJust p -> FeatureValue UpdateProposalInMaryEra (fromLedgerUpdate era p)

ShelleyBasedEraAlonzo ->
case body ^. L.updateTxBodyL of
SNothing -> TxUpdateProposalNone
SJust p ->
TxUpdateProposal UpdateProposalInAlonzoEra
(fromLedgerUpdate era p)
SNothing -> NoFeatureValue
SJust p -> FeatureValue UpdateProposalInAlonzoEra (fromLedgerUpdate era p)

ShelleyBasedEraBabbage ->
case body ^. L.updateTxBodyL of
SNothing -> TxUpdateProposalNone
SJust p ->
TxUpdateProposal UpdateProposalInBabbageEra
(fromLedgerUpdate era p)
SNothing -> NoFeatureValue
SJust p -> FeatureValue UpdateProposalInBabbageEra (fromLedgerUpdate era p)

ShelleyBasedEraConway -> TxUpdateProposalNone
ShelleyBasedEraConway -> NoFeatureValue

fromLedgerTxMintValue
:: ShelleyBasedEra era
Expand Down Expand Up @@ -3368,7 +3340,7 @@ getByronTxBodyContent (Annotated Byron.UnsafeTx{txInputs, txOutputs} _) =
, txProtocolParams = ViewTx
, txWithdrawals = TxWithdrawalsNone
, txCertificates = TxCertificatesNone
, txUpdateProposal = TxUpdateProposalNone
, txUpdateProposal = NoFeatureValue
, txMintValue = TxMintNone
, txScriptValidity = NoFeatureValue
}
Expand Down Expand Up @@ -3463,13 +3435,13 @@ convTxUpdateProposal
:: forall era ledgerera. ShelleyLedgerEra era ~ ledgerera
=> Ledger.EraCrypto ledgerera ~ StandardCrypto
=> ShelleyBasedEra era
-> TxUpdateProposal era
-> FeatureValue UpdateProposalFeature era UpdateProposal
-> Either TxBodyError (StrictMaybe (Ledger.Update ledgerera))
-- ^ 'Left' when there's protocol params conversion error, 'Right' otherwise, 'Right SNothing' means that
-- there's no update proposal
convTxUpdateProposal era = \case
TxUpdateProposalNone -> Right SNothing
TxUpdateProposal _ p -> bimap TxBodyProtocolParamsConversionError pure $ toLedgerUpdate era p
NoFeatureValue -> Right SNothing
FeatureValue _ p -> bimap TxBodyProtocolParamsConversionError pure $ toLedgerUpdate era p

convMintValue :: TxMintValue build era -> MultiAsset StandardCrypto
convMintValue txMintValue =
Expand Down
4 changes: 1 addition & 3 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ module Cardano.Api (
TxExtraKeyWitnesses(..),
TxWithdrawals(..),
TxCertificates(..),
TxUpdateProposal(..),
TxMintValue(..),

-- ** Building vs viewing transactions
Expand All @@ -275,7 +274,7 @@ module Cardano.Api (
ScriptDataSupportedInEra(..),
WithdrawalsSupportedInEra(..),
CertificatesSupportedInEra(..),
UpdateProposalSupportedInEra(..),
UpdateProposalFeature(..),
TxTotalAndReturnCollateralSupportedInEra(..),
FeatureInEra(..),

Expand All @@ -291,7 +290,6 @@ module Cardano.Api (
extraKeyWitnessesSupportedInEra,
withdrawalsSupportedInEra,
certificatesSupportedInEra,
updateProposalSupportedInEra,
scriptDataSupportedInEra,
totalAndReturnCollateralSupportedInEra,

Expand Down

0 comments on commit f25d117

Please sign in to comment.