Skip to content

Commit

Permalink
Delete TxFeesExplicitInEra and TxFeesImplicitInEra
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Sep 14, 2023
1 parent a4605b0 commit e0eff20
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 95 deletions.
8 changes: 4 additions & 4 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -720,10 +720,10 @@ genTxTotalCollateral era =
TxTotalCollateral supp <$> genPositiveLovelace

genTxFee :: CardanoEra era -> Gen (TxFee era)
genTxFee era =
case txFeesExplicitInEra era of
Left supported -> pure (TxFeeImplicit supported)
Right supported -> TxFeeExplicit supported <$> genLovelace
genTxFee =
caseByronOrShelleyBasedEra
(pure . TxFeeImplicit)
(\w -> TxFeeExplicit w <$> genLovelace)

genTxBody :: IsCardanoEra era => CardanoEra era -> Gen (TxBody era)
genTxBody era = do
Expand Down
5 changes: 3 additions & 2 deletions cardano-api/internal/Cardano/Api/Eras/Case.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ import Cardano.Api.Eras.Constraints
import Cardano.Api.Eras.Core
import Cardano.Api.Feature.AlonzoEraOnwards
import Cardano.Api.Feature.BabbageEraOnwards
import Cardano.Api.Feature.ByronEraOnly
import Cardano.Api.Feature.ConwayEraOnwards
import Cardano.Api.Feature.ShelleyBasedEra
import Cardano.Api.Feature.ShelleyToAlonzoEra
import Cardano.Api.Feature.ShelleyToBabbageEra
import Cardano.Api.Feature.ShelleyToMaryEra

caseByronOrShelleyBasedEra :: ()
=> (CardanoEra ByronEra -> a)
=> (ByronEraOnly era -> a)
-> (ShelleyBasedEraConstraints era => ShelleyBasedEra era -> a)
-> CardanoEra era
-> a
caseByronOrShelleyBasedEra l r = \case
ByronEra -> l ByronEra
ByronEra -> l ByronEraOnlyByron
ShelleyEra -> r ShelleyBasedEraShelley
AllegraEra -> r ShelleyBasedEraAllegra
MaryEra -> r ShelleyBasedEraMary
Expand Down
9 changes: 3 additions & 6 deletions cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -952,9 +952,6 @@ makeTransactionBodyAutoBalance systemstart history lpp@(LedgerProtocolParameters

txbodycontent1 <- substituteExecutionUnits sbe exUnitsMap' txbodycontent

explicitTxFees <- first (const TxBodyErrorByronEraNotSupported) $
txFeesExplicitInEra era'

-- Make a txbody that we will use for calculating the fees. For the purpose
-- of fees we just need to make a txbody of the right size in bytes. We do
-- not need the right values for the fee or change output. We use
Expand Down Expand Up @@ -984,7 +981,7 @@ makeTransactionBodyAutoBalance systemstart history lpp@(LedgerProtocolParameters
let (dummyCollRet, dummyTotColl) = maybeDummyTotalCollAndCollReturnOutput txbodycontent changeaddr
txbody1 <- first TxBodyError $ -- TODO: impossible to fail now
createAndValidateTransactionBody txbodycontent1 {
txFee = TxFeeExplicit explicitTxFees $ Lovelace (2^(32 :: Integer) - 1),
txFee = TxFeeExplicit sbe $ Lovelace (2^(32 :: Integer) - 1),
txOuts = TxOut changeaddr
changeTxOut
TxOutDatumNone ReferenceScriptNone
Expand Down Expand Up @@ -1013,7 +1010,7 @@ makeTransactionBodyAutoBalance systemstart history lpp@(LedgerProtocolParameters
-- we need to calculate.
txbody2 <- first TxBodyError $ -- TODO: impossible to fail now
createAndValidateTransactionBody txbodycontent1 {
txFee = TxFeeExplicit explicitTxFees fee,
txFee = TxFeeExplicit sbe fee,
txReturnCollateral = retColl,
txTotalCollateral = reqCol
}
Expand All @@ -1034,7 +1031,7 @@ makeTransactionBodyAutoBalance systemstart history lpp@(LedgerProtocolParameters
-- Yes this could be an over-estimate by a few bytes if the fee or change
-- would fit within 2^16-1. That's a possible optimisation.
let finalTxBodyContent = txbodycontent1 {
txFee = TxFeeExplicit explicitTxFees fee,
txFee = TxFeeExplicit sbe fee,
txOuts = accountForNoChange
(TxOut changeaddr balance TxOutDatumNone ReferenceScriptNone)
(txOuts txbodycontent),
Expand Down
139 changes: 59 additions & 80 deletions cardano-api/internal/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ module Cardano.Api.TxBody (
CollateralSupportedInEra(..),
MultiAssetSupportedInEra(..),
OnlyAdaSupportedInEra(..),
TxFeesExplicitInEra(..),
TxFeesImplicitInEra(..),
ValidityUpperBoundSupportedInEra(..),
ValidityNoUpperBoundSupportedInEra(..),
ValidityLowerBoundSupportedInEra(..),
Expand All @@ -134,7 +132,6 @@ module Cardano.Api.TxBody (
-- ** Feature availability functions
collateralSupportedInEra,
multiAssetSupportedInEra,
txFeesExplicitInEra,
validityUpperBoundSupportedInEra,
validityNoUpperBoundSupportedInEra,
validityLowerBoundSupportedInEra,
Expand Down Expand Up @@ -190,6 +187,7 @@ import Cardano.Api.EraCast
import Cardano.Api.Eras
import Cardano.Api.Error
import Cardano.Api.Feature
import Cardano.Api.Feature.ByronEraOnly
import Cardano.Api.Feature.ConwayEraOnwards
import Cardano.Api.Feature.ShelleyBasedEra
import Cardano.Api.Governance.Actions.ProposalProcedure
Expand Down Expand Up @@ -988,46 +986,46 @@ multiAssetSupportedInEra BabbageEra = Right MultiAssetInBabbageEra
multiAssetSupportedInEra ConwayEra = Right MultiAssetInConwayEra


-- | A representation of whether the era requires explicitly specified fees in
-- transactions.
--
-- The Byron era tx fees are implicit (as the difference bettween the sum of
-- outputs and sum of inputs), but all later eras the fees are specified in the
-- transaction explicitly.
--
data TxFeesExplicitInEra era where

TxFeesExplicitInShelleyEra :: TxFeesExplicitInEra ShelleyEra
TxFeesExplicitInAllegraEra :: TxFeesExplicitInEra AllegraEra
TxFeesExplicitInMaryEra :: TxFeesExplicitInEra MaryEra
TxFeesExplicitInAlonzoEra :: TxFeesExplicitInEra AlonzoEra
TxFeesExplicitInBabbageEra :: TxFeesExplicitInEra BabbageEra
TxFeesExplicitInConwayEra :: TxFeesExplicitInEra ConwayEra

deriving instance Eq (TxFeesExplicitInEra era)
deriving instance Show (TxFeesExplicitInEra era)

-- | A representation of whether the era requires implicitly specified fees in
-- transactions.
--
-- This is the negation of 'TxFeesExplicitInEra'.
--
data TxFeesImplicitInEra era where
TxFeesImplicitInByronEra :: TxFeesImplicitInEra ByronEra

deriving instance Eq (TxFeesImplicitInEra era)
deriving instance Show (TxFeesImplicitInEra era)

txFeesExplicitInEra :: CardanoEra era
-> Either (TxFeesImplicitInEra era)
(TxFeesExplicitInEra era)
txFeesExplicitInEra ByronEra = Left TxFeesImplicitInByronEra
txFeesExplicitInEra ShelleyEra = Right TxFeesExplicitInShelleyEra
txFeesExplicitInEra AllegraEra = Right TxFeesExplicitInAllegraEra
txFeesExplicitInEra MaryEra = Right TxFeesExplicitInMaryEra
txFeesExplicitInEra AlonzoEra = Right TxFeesExplicitInAlonzoEra
txFeesExplicitInEra BabbageEra = Right TxFeesExplicitInBabbageEra
txFeesExplicitInEra ConwayEra = Right TxFeesExplicitInConwayEra
-- -- | A representation of whether the era requires explicitly specified fees in
-- -- transactions.
-- --
-- -- The Byron era tx fees are implicit (as the difference bettween the sum of
-- -- outputs and sum of inputs), but all later eras the fees are specified in the
-- -- transaction explicitly.
-- --
-- data TxFeesExplicitInEra era where

-- TxFeesExplicitInShelleyEra :: TxFeesExplicitInEra ShelleyEra
-- TxFeesExplicitInAllegraEra :: TxFeesExplicitInEra AllegraEra
-- TxFeesExplicitInMaryEra :: TxFeesExplicitInEra MaryEra
-- TxFeesExplicitInAlonzoEra :: TxFeesExplicitInEra AlonzoEra
-- TxFeesExplicitInBabbageEra :: TxFeesExplicitInEra BabbageEra
-- TxFeesExplicitInConwayEra :: TxFeesExplicitInEra ConwayEra

-- deriving instance Eq (TxFeesExplicitInEra era)
-- deriving instance Show (TxFeesExplicitInEra era)

-- -- | A representation of whether the era requires implicitly specified fees in
-- -- transactions.
-- --
-- -- This is the negation of 'TxFeesExplicitInEra'.
-- --
-- data TxFeesImplicitInEra era where
-- TxFeesImplicitInByronEra :: TxFeesImplicitInEra ByronEra

-- deriving instance Eq (TxFeesImplicitInEra era)
-- deriving instance Show (TxFeesImplicitInEra era)

-- txFeesExplicitInEra :: CardanoEra era
-- -> Either (TxFeesImplicitInEra era)
-- (TxFeesExplicitInEra era)
-- txFeesExplicitInEra ByronEra = Left TxFeesImplicitInByronEra
-- txFeesExplicitInEra ShelleyEra = Right TxFeesExplicitInShelleyEra
-- txFeesExplicitInEra AllegraEra = Right TxFeesExplicitInAllegraEra
-- txFeesExplicitInEra MaryEra = Right TxFeesExplicitInMaryEra
-- txFeesExplicitInEra AlonzoEra = Right TxFeesExplicitInAlonzoEra
-- txFeesExplicitInEra BabbageEra = Right TxFeesExplicitInBabbageEra
-- txFeesExplicitInEra ConwayEra = Right TxFeesExplicitInConwayEra


-- | A representation of whether the era supports transactions with an upper
Expand Down Expand Up @@ -1567,24 +1565,19 @@ parseHash asType = do
--

data TxFee era where
TxFeeImplicit :: ByronEraOnly era -> TxFee era

TxFeeImplicit :: TxFeesImplicitInEra era -> TxFee era

TxFeeExplicit :: TxFeesExplicitInEra era -> Lovelace -> TxFee era
TxFeeExplicit :: ShelleyBasedEra era -> Lovelace -> TxFee era

deriving instance Eq (TxFee era)
deriving instance Show (TxFee era)

defaultTxFee :: forall era. IsCardanoEra era => TxFee era
defaultTxFee = case cardanoEra @era of
ByronEra -> TxFeeImplicit TxFeesImplicitInByronEra
ShelleyEra -> TxFeeExplicit TxFeesExplicitInShelleyEra mempty
AllegraEra -> TxFeeExplicit TxFeesExplicitInAllegraEra mempty
MaryEra -> TxFeeExplicit TxFeesExplicitInMaryEra mempty
AlonzoEra -> TxFeeExplicit TxFeesExplicitInAlonzoEra mempty
BabbageEra -> TxFeeExplicit TxFeesExplicitInBabbageEra mempty
ConwayEra -> TxFeeExplicit TxFeesExplicitInConwayEra mempty

defaultTxFee =
caseByronOrShelleyBasedEra
TxFeeImplicit
(\w -> TxFeeExplicit w mempty)
(cardanoEra @era)

-- ----------------------------------------------------------------------------
-- Transaction validity range
Expand Down Expand Up @@ -2964,25 +2957,9 @@ fromLedgerTxReturnCollateral sbe txbody =
fromLedgerTxFee
:: ShelleyBasedEra era -> Ledger.TxBody (ShelleyLedgerEra era) -> TxFee era
fromLedgerTxFee sbe body =
case sbe of
ShelleyBasedEraShelley ->
TxFeeExplicit TxFeesExplicitInShelleyEra $
fromShelleyLovelace $ body ^. L.feeTxBodyL
ShelleyBasedEraAllegra ->
TxFeeExplicit TxFeesExplicitInAllegraEra $
fromShelleyLovelace $ body ^. L.feeTxBodyL
ShelleyBasedEraMary ->
TxFeeExplicit TxFeesExplicitInMaryEra $
fromShelleyLovelace $ body ^. L.feeTxBodyL
ShelleyBasedEraAlonzo ->
TxFeeExplicit TxFeesExplicitInAlonzoEra $
fromShelleyLovelace $ body ^. L.feeTxBodyL
ShelleyBasedEraBabbage ->
TxFeeExplicit TxFeesExplicitInBabbageEra $
fromShelleyLovelace $ body ^. L.feeTxBodyL
ShelleyBasedEraConway ->
TxFeeExplicit TxFeesExplicitInConwayEra $
fromShelleyLovelace $ body ^. L.feeTxBodyL
shelleyBasedEraConstraints sbe
$ TxFeeExplicit sbe
$ fromShelleyLovelace $ body ^. L.feeTxBodyL

fromLedgerTxValidityRange
:: ShelleyBasedEra era
Expand Down Expand Up @@ -3397,7 +3374,7 @@ getByronTxBodyContent (Annotated Byron.UnsafeTx{txInputs, txOutputs} _) =
, txOuts = fromByronTxOut <$> toList txOutputs
, txReturnCollateral = TxReturnCollateralNone
, txTotalCollateral = TxTotalCollateralNone
, txFee = TxFeeImplicit TxFeesImplicitInByronEra
, txFee = TxFeeImplicit ByronEraOnlyByron
, txValidityRange = (TxValidityNoLowerBound, TxValidityNoUpperBound ValidityNoUpperBoundInByronEra)
, txMetadata = TxMetadataNone
, txAuxScripts = TxAuxScriptsNone
Expand Down Expand Up @@ -3458,12 +3435,14 @@ convWithdrawals txWithdrawals =
TxWithdrawalsNone -> L.Withdrawals Map.empty
TxWithdrawals _ ws -> toShelleyWithdrawal ws

convTransactionFee :: ShelleyBasedEra era -> TxFee era -> Ledger.Coin
convTransactionFee sbe txFee =
case txFee of
TxFeeImplicit TxFeesImplicitInByronEra -> case sbe of {}
TxFeeExplicit _ fee -> toShelleyLovelace fee
noByronEraInShelleyBasedEra :: ShelleyBasedEra era -> ByronEraOnly era -> a
noByronEraInShelleyBasedEra sbe = \case
ByronEraOnlyByron -> case (sbe, w) of

convTransactionFee :: ShelleyBasedEra era -> TxFee era -> Ledger.Coin
convTransactionFee sbe = \case
TxFeeImplicit w -> noByronEraInShelleyBasedEra sbe w
TxFeeExplicit _ fee -> toShelleyLovelace fee

convValidityInterval
:: (TxValidityLowerBound era, TxValidityUpperBound era)
Expand Down
3 changes: 0 additions & 3 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@ module Cardano.Api (
CollateralSupportedInEra(..),
MultiAssetSupportedInEra(..),
OnlyAdaSupportedInEra(..),
TxFeesExplicitInEra(..),
TxFeesImplicitInEra(..),
ValidityUpperBoundSupportedInEra(..),
ValidityNoUpperBoundSupportedInEra(..),
ValidityLowerBoundSupportedInEra(..),
Expand All @@ -364,7 +362,6 @@ module Cardano.Api (
-- ** Feature availability functions
collateralSupportedInEra,
multiAssetSupportedInEra,
txFeesExplicitInEra,
validityUpperBoundSupportedInEra,
validityNoUpperBoundSupportedInEra,
validityLowerBoundSupportedInEra,
Expand Down

0 comments on commit e0eff20

Please sign in to comment.