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

Replace WithdrawalsSupportedInEra with ShelleyBasedEra #260

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

-> [(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
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Simplified with shelleyBasedEraConstraints.


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