Skip to content

Commit

Permalink
Merge pull request #260 from input-output-hk/newhoggy/replace-Withdra…
Browse files Browse the repository at this point in the history
…walsSupportedInEra-with-ShelleyBasedEra

Replace WithdrawalsSupportedInEra with ShelleyBasedEra
  • Loading branch information
newhoggy authored Sep 26, 2023
2 parents 26b9f1f + c4fc635 commit f009c92
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 87 deletions.
11 changes: 6 additions & 5 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions cardano-api/internal/Cardano/Api/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
91 changes: 11 additions & 80 deletions cardano-api/internal/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ module Cardano.Api.TxBody (
ValidityLowerBoundSupportedInEra(..),
AuxScriptsSupportedInEra(..),
TxExtraKeyWitnessesSupportedInEra(..),
AlonzoEraOnwards(..),
WithdrawalsSupportedInEra(..),
TxTotalAndReturnCollateralSupportedInEra(..),

-- ** Feature availability functions
Expand All @@ -131,7 +129,6 @@ module Cardano.Api.TxBody (
validityLowerBoundSupportedInEra,
auxScriptsSupportedInEra,
extraKeyWitnessesSupportedInEra,
withdrawalsSupportedInEra,
txScriptValiditySupportedInShelleyBasedEra,
txScriptValiditySupportedInCardanoEra,
totalAndReturnCollateralSupportedInEra,
Expand Down Expand Up @@ -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
--
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ module Cardano.Api (
ValidityLowerBoundSupportedInEra(..),
AuxScriptsSupportedInEra(..),
TxExtraKeyWitnessesSupportedInEra(..),
WithdrawalsSupportedInEra(..),
TxTotalAndReturnCollateralSupportedInEra(..),

-- ** Feature availability functions
Expand All @@ -403,7 +402,6 @@ module Cardano.Api (
validityLowerBoundSupportedInEra,
auxScriptsSupportedInEra,
extraKeyWitnessesSupportedInEra,
withdrawalsSupportedInEra,
totalAndReturnCollateralSupportedInEra,

-- ** Era-dependent protocol features
Expand Down

0 comments on commit f009c92

Please sign in to comment.