diff --git a/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs b/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs index 87a6d58230..b8bee0b5dc 100644 --- a/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs +++ b/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs @@ -583,15 +583,16 @@ genTxAuxScripts era = (genScriptInEra era) genTxWithdrawals :: CardanoEra era -> Gen (TxWithdrawals BuildTx era) -genTxWithdrawals era = - case withdrawalsSupportedInEra era of - Nothing -> pure TxWithdrawalsNone - Just supported -> +genTxWithdrawals = + inEonForEra + (pure TxWithdrawalsNone) + (\w -> Gen.choice [ pure TxWithdrawalsNone - , pure (TxWithdrawals supported mempty) + , pure (TxWithdrawals w mempty) -- TODO: Generate withdrawals ] + ) genTxCertificates :: CardanoEra era -> Gen (TxCertificates BuildTx era) genTxCertificates = diff --git a/cardano-api/internal/Cardano/Api/Tx.hs b/cardano-api/internal/Cardano/Api/Tx.hs index 3619b60a76..442185e737 100644 --- a/cardano-api/internal/Cardano/Api/Tx.hs +++ b/cardano-api/internal/Cardano/Api/Tx.hs @@ -50,6 +50,7 @@ module Cardano.Api.Tx ( import Cardano.Api.Address import Cardano.Api.Certificate +import Cardano.Api.Eon.AlonzoEraOnwards import Cardano.Api.Eon.ShelleyBasedEra import Cardano.Api.Eras import Cardano.Api.Eras.Constraints diff --git a/cardano-api/internal/Cardano/Api/TxBody.hs b/cardano-api/internal/Cardano/Api/TxBody.hs index 3cebe68ed6..a0a4675de5 100644 --- a/cardano-api/internal/Cardano/Api/TxBody.hs +++ b/cardano-api/internal/Cardano/Api/TxBody.hs @@ -120,8 +120,6 @@ module Cardano.Api.TxBody ( ValidityLowerBoundSupportedInEra(..), AuxScriptsSupportedInEra(..), TxExtraKeyWitnessesSupportedInEra(..), - AlonzoEraOnwards(..), - WithdrawalsSupportedInEra(..), TxTotalAndReturnCollateralSupportedInEra(..), -- ** Feature availability functions @@ -131,7 +129,6 @@ module Cardano.Api.TxBody ( validityLowerBoundSupportedInEra, auxScriptsSupportedInEra, extraKeyWitnessesSupportedInEra, - withdrawalsSupportedInEra, txScriptValiditySupportedInShelleyBasedEra, txScriptValiditySupportedInCardanoEra, totalAndReturnCollateralSupportedInEra, @@ -1058,34 +1055,6 @@ extraKeyWitnessesSupportedInEra BabbageEra = Just ExtraKeyWitnessesInBabbageEra extraKeyWitnessesSupportedInEra ConwayEra = Just ExtraKeyWitnessesInConwayEra --- | A representation of whether the era supports withdrawals from reward --- accounts. --- --- The Shelley and subsequent eras support stake addresses, their associated --- reward accounts and support for withdrawals from them. --- -data WithdrawalsSupportedInEra era where - - WithdrawalsInShelleyEra :: WithdrawalsSupportedInEra ShelleyEra - WithdrawalsInAllegraEra :: WithdrawalsSupportedInEra AllegraEra - WithdrawalsInMaryEra :: WithdrawalsSupportedInEra MaryEra - WithdrawalsInAlonzoEra :: WithdrawalsSupportedInEra AlonzoEra - WithdrawalsInBabbageEra :: WithdrawalsSupportedInEra BabbageEra - WithdrawalsInConwayEra :: WithdrawalsSupportedInEra ConwayEra - -deriving instance Eq (WithdrawalsSupportedInEra era) -deriving instance Show (WithdrawalsSupportedInEra era) - -withdrawalsSupportedInEra :: CardanoEra era - -> Maybe (WithdrawalsSupportedInEra era) -withdrawalsSupportedInEra ByronEra = Nothing -withdrawalsSupportedInEra ShelleyEra = Just WithdrawalsInShelleyEra -withdrawalsSupportedInEra AllegraEra = Just WithdrawalsInAllegraEra -withdrawalsSupportedInEra MaryEra = Just WithdrawalsInMaryEra -withdrawalsSupportedInEra AlonzoEra = Just WithdrawalsInAlonzoEra -withdrawalsSupportedInEra BabbageEra = Just WithdrawalsInBabbageEra -withdrawalsSupportedInEra ConwayEra = Just WithdrawalsInConwayEra - -- ---------------------------------------------------------------------------- -- Building vs viewing transactions -- @@ -1454,12 +1423,13 @@ deriving instance Show (TxExtraKeyWitnesses era) data TxWithdrawals build era where - TxWithdrawalsNone :: TxWithdrawals build era + TxWithdrawalsNone + :: TxWithdrawals build era - TxWithdrawals :: WithdrawalsSupportedInEra era - -> [(StakeAddress, Lovelace, - BuildTxWith build (Witness WitCtxStake era))] - -> TxWithdrawals build era + TxWithdrawals + :: ShelleyBasedEra era + -> [(StakeAddress, Lovelace, BuildTxWith build (Witness WitCtxStake era))] + -> TxWithdrawals build era deriving instance Eq (TxWithdrawals build era) deriving instance Show (TxWithdrawals build era) @@ -2905,50 +2875,11 @@ fromLedgerTxWithdrawals -> Ledger.TxBody (ShelleyLedgerEra era) -> TxWithdrawals ViewTx era fromLedgerTxWithdrawals sbe body = - case sbe of - ShelleyBasedEraShelley - | null (L.unWithdrawals withdrawals) -> TxWithdrawalsNone - | otherwise -> - TxWithdrawals WithdrawalsInShelleyEra $ - fromShelleyWithdrawal withdrawals - where - withdrawals = body ^. L.withdrawalsTxBodyL - - ShelleyBasedEraAllegra - | null (L.unWithdrawals withdrawals) -> TxWithdrawalsNone - | otherwise -> - TxWithdrawals WithdrawalsInAllegraEra $ - fromShelleyWithdrawal withdrawals - where - withdrawals = body ^. L.withdrawalsTxBodyL - - ShelleyBasedEraMary - | null (L.unWithdrawals withdrawals) -> TxWithdrawalsNone - | otherwise -> - TxWithdrawals WithdrawalsInMaryEra $ fromShelleyWithdrawal withdrawals - where - withdrawals = body ^. L.withdrawalsTxBodyL - - ShelleyBasedEraAlonzo - | null (L.unWithdrawals withdrawals) -> TxWithdrawalsNone - | otherwise -> - TxWithdrawals WithdrawalsInAlonzoEra $ fromShelleyWithdrawal withdrawals - where - withdrawals = body ^. L.withdrawalsTxBodyL - - ShelleyBasedEraBabbage - | null (L.unWithdrawals withdrawals) -> TxWithdrawalsNone - | otherwise -> - TxWithdrawals WithdrawalsInBabbageEra $ fromShelleyWithdrawal withdrawals - where - withdrawals = body ^. L.withdrawalsTxBodyL - - ShelleyBasedEraConway - | null (L.unWithdrawals withdrawals) -> TxWithdrawalsNone - | otherwise -> - TxWithdrawals WithdrawalsInConwayEra $ fromShelleyWithdrawal withdrawals - where - withdrawals = body ^. L.withdrawalsTxBodyL + shelleyBasedEraConstraints sbe $ + let withdrawals = body ^. L.withdrawalsTxBodyL in + if null (L.unWithdrawals withdrawals) + then TxWithdrawalsNone + else TxWithdrawals sbe $ fromShelleyWithdrawal withdrawals fromLedgerTxCertificates :: ShelleyBasedEra era diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index e7ba5abe2e..829a92a2c2 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -393,7 +393,6 @@ module Cardano.Api ( ValidityLowerBoundSupportedInEra(..), AuxScriptsSupportedInEra(..), TxExtraKeyWitnessesSupportedInEra(..), - WithdrawalsSupportedInEra(..), TxTotalAndReturnCollateralSupportedInEra(..), -- ** Feature availability functions @@ -403,7 +402,6 @@ module Cardano.Api ( validityLowerBoundSupportedInEra, auxScriptsSupportedInEra, extraKeyWitnessesSupportedInEra, - withdrawalsSupportedInEra, totalAndReturnCollateralSupportedInEra, -- ** Era-dependent protocol features