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

Convert to use typesafe features in data types #37

Closed
wants to merge 3 commits into from
Closed
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
21 changes: 2 additions & 19 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ module Test.Gen.Cardano.Api.Typed
, genTxOutDatumHashUTxOContext
, genTxOutValue
, genTxReturnCollateral
, genTxScriptValidity
, genTxTotalCollateral
, genTxUpdateProposal
, genTxValidityLowerBound
, genTxValidityRange
, genTxValidityUpperBound
Expand Down Expand Up @@ -605,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 @@ -641,9 +629,9 @@ 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 <- genTxScriptValidity era
txScriptValidity <- genFeatureValueInEra genScriptValidity era

pure $ TxBodyContent
{ Api.txIns
Expand Down Expand Up @@ -718,11 +706,6 @@ genFeatureValueInEra gen =
featureInEra (pure NoFeatureValue) $ \witness ->
pure NoFeatureValue <|> fmap (FeatureValue witness) gen

genTxScriptValidity :: CardanoEra era -> Gen (TxScriptValidity era)
genTxScriptValidity era = case txScriptValiditySupportedInCardanoEra era of
Nothing -> pure TxScriptValidityNone
Just witness -> TxScriptValidity witness <$> genScriptValidity

genScriptValidity :: Gen ScriptValidity
genScriptValidity = Gen.element [ScriptInvalid, ScriptValid]

Expand Down
15 changes: 8 additions & 7 deletions cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import Cardano.Api.Address
import Cardano.Api.Certificate
import Cardano.Api.Eras
import Cardano.Api.Error
import Cardano.Api.Feature
import Cardano.Api.NetworkId
import Cardano.Api.ProtocolParameters
import Cardano.Api.Query
Expand Down Expand Up @@ -303,9 +304,9 @@ estimateTransactionKeyWitnessCount TxBodyContent {
_ -> 0

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


-- ----------------------------------------------------------------------------
Expand Down Expand Up @@ -674,7 +675,7 @@ evaluateTransactionBalance bpp poolids stakeDelegDeposits utxo
=> ShelleyEraTxBody ledgerera
=> LedgerEraConstraints ledgerera
=> LedgerMultiAssetConstraints ledgerera
=> MultiAssetSupportedInEra era
=> MultiAssetFeature era
-> TxOutValue era
evalMultiAsset evidence =
TxOutValue evidence . fromMaryValue $
Expand All @@ -690,7 +691,7 @@ evaluateTransactionBalance bpp poolids stakeDelegDeposits utxo
=> ShelleyEraTxBody ledgerera
=> LedgerEraConstraints ledgerera
=> LedgerAdaOnlyConstraints ledgerera
=> OnlyAdaSupportedInEra era
=> OnlyAdaFeature era
-> TxOutValue era
evalAdaOnly evidence =
TxOutAdaOnly evidence . fromShelleyLovelace
Expand All @@ -709,13 +710,13 @@ evaluateTransactionBalance bpp poolids stakeDelegDeposits utxo
=> LedgerAdaOnlyConstraints ledgerera
=> LedgerPParamsConstraints ledgerera
=> LedgerTxBodyConstraints ledgerera
=> OnlyAdaSupportedInEra era
=> OnlyAdaFeature era
-> a)
-> ( LedgerEraConstraints ledgerera
=> LedgerMultiAssetConstraints ledgerera
=> LedgerPParamsConstraints ledgerera
=> LedgerTxBodyConstraints ledgerera
=> MultiAssetSupportedInEra era
=> MultiAssetFeature era
-> a)
-> a
withLedgerConstraints ShelleyBasedEraShelley f _ = f AdaOnlyInShelleyEra
Expand Down Expand Up @@ -939,7 +940,7 @@ makeTransactionBodyAutoBalance systemstart history pparams poolids stakeDelegDep
case Map.mapEither id exUnitsMap of
(failures, exUnitsMap') ->
handleExUnitsErrors
(txScriptValidityToScriptValidity (txScriptValidity txbodycontent))
(valueOrDefault defaultScriptValidity (txScriptValidity txbodycontent))
failures
exUnitsMap'

Expand Down
9 changes: 5 additions & 4 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.Eras
import Cardano.Api.Feature
import Cardano.Api.HasTypeProxy
import Cardano.Api.Keys.Byron
import Cardano.Api.Keys.Class
Expand Down Expand Up @@ -490,13 +491,13 @@ getTxBody (ShelleyTx era tx') =
(Map.elems scriptWits)
TxBodyNoScriptData
(strictMaybeToMaybe txAuxData)
TxScriptValidityNone
NoFeatureValue

getAlonzoTxBody :: forall ledgerera.
ShelleyLedgerEra era ~ ledgerera
=> L.AlonzoEraTx ledgerera
=> ScriptDataSupportedInEra era
-> TxScriptValiditySupportedInEra era
-> TxScriptValidityFeature era
-> L.Tx ledgerera
-> TxBody era
getAlonzoTxBody scriptDataInEra txScriptValidityInEra tx =
Expand All @@ -510,7 +511,7 @@ getTxBody (ShelleyTx era tx') =
(Map.elems scriptWits)
(TxBodyScriptData scriptDataInEra datsWits redeemerWits)
(strictMaybeToMaybe txAuxData)
(TxScriptValidity txScriptValidityInEra (isValidToScriptValidity isValid))
(FeatureValue txScriptValidityInEra (isValidToScriptValidity isValid))

getTxWitnesses :: forall era. Tx era -> [KeyWitness era]
getTxWitnesses (ByronTx Byron.ATxAux { Byron.aTaWitness = witnesses }) =
Expand Down Expand Up @@ -607,7 +608,7 @@ makeSignedTransaction witnesses (ShelleyTxBody era txbody
(txCommon
& L.witsTxL . L.datsTxWitsL .~ datums
& L.witsTxL . L.rdmrsTxWitsL .~ redeemers
& L.isValidTxL .~ txScriptValidityToIsValid scriptValidity)
& L.isValidTxL .~ scriptValidityToIsValid (valueOrDefault defaultScriptValidity scriptValidity))
where
(datums, redeemers) =
case txscriptdata of
Expand Down
Loading