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 TxExtraKeyWitnessesSupportedInEra #278

Merged
merged 1 commit into from
Sep 28, 2023
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
80 changes: 19 additions & 61 deletions cardano-api/internal/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,13 @@ module Cardano.Api.TxBody (
ValidityNoUpperBoundSupportedInEra(..),
ValidityLowerBoundSupportedInEra(..),
AuxScriptsSupportedInEra(..),
TxExtraKeyWitnessesSupportedInEra(..),

-- ** Feature availability functions
collateralSupportedInEra,
validityUpperBoundSupportedInEra,
validityNoUpperBoundSupportedInEra,
validityLowerBoundSupportedInEra,
auxScriptsSupportedInEra,
extraKeyWitnessesSupportedInEra,
txScriptValiditySupportedInShelleyBasedEra,
txScriptValiditySupportedInCardanoEra,

Expand Down Expand Up @@ -1026,33 +1024,6 @@ auxScriptsSupportedInEra BabbageEra = Just AuxScriptsInBabbageEra
auxScriptsSupportedInEra ConwayEra = Just AuxScriptsInConwayEra


-- | A representation of whether the era supports transactions that specify
-- in the body that they need extra key witnesses, and where this fact is
-- visible to scripts.
--
-- Extra key witnesses visible to scripts are supported from the Alonzo era
-- onwards.
--
data TxExtraKeyWitnessesSupportedInEra era where

ExtraKeyWitnessesInAlonzoEra :: TxExtraKeyWitnessesSupportedInEra AlonzoEra
ExtraKeyWitnessesInBabbageEra :: TxExtraKeyWitnessesSupportedInEra BabbageEra
ExtraKeyWitnessesInConwayEra :: TxExtraKeyWitnessesSupportedInEra ConwayEra

deriving instance Eq (TxExtraKeyWitnessesSupportedInEra era)
deriving instance Show (TxExtraKeyWitnessesSupportedInEra era)

extraKeyWitnessesSupportedInEra :: CardanoEra era
-> Maybe (TxExtraKeyWitnessesSupportedInEra era)
extraKeyWitnessesSupportedInEra ByronEra = Nothing
extraKeyWitnessesSupportedInEra ShelleyEra = Nothing
extraKeyWitnessesSupportedInEra AllegraEra = Nothing
extraKeyWitnessesSupportedInEra MaryEra = Nothing
extraKeyWitnessesSupportedInEra AlonzoEra = Just ExtraKeyWitnessesInAlonzoEra
extraKeyWitnessesSupportedInEra BabbageEra = Just ExtraKeyWitnessesInBabbageEra
extraKeyWitnessesSupportedInEra ConwayEra = Just ExtraKeyWitnessesInConwayEra


-- ----------------------------------------------------------------------------
-- Building vs viewing transactions
--
Expand Down Expand Up @@ -1392,11 +1363,13 @@ deriving instance Show (TxAuxScripts era)

data TxExtraKeyWitnesses era where

TxExtraKeyWitnessesNone :: TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone
:: TxExtraKeyWitnesses era

TxExtraKeyWitnesses :: TxExtraKeyWitnessesSupportedInEra era
-> [Hash PaymentKey]
-> TxExtraKeyWitnesses era
TxExtraKeyWitnesses
:: AlonzoEraOnwards era
-> [Hash PaymentKey]
-> TxExtraKeyWitnesses era

deriving instance Eq (TxExtraKeyWitnesses era)
deriving instance Show (TxExtraKeyWitnesses era)
Expand Down Expand Up @@ -2812,34 +2785,19 @@ fromLedgerTxExtraKeyWitnesses :: ShelleyBasedEra era
-> Ledger.TxBody (ShelleyLedgerEra era)
-> TxExtraKeyWitnesses era
fromLedgerTxExtraKeyWitnesses sbe body =
case sbe of
ShelleyBasedEraShelley -> TxExtraKeyWitnessesNone
ShelleyBasedEraAllegra -> TxExtraKeyWitnessesNone
ShelleyBasedEraMary -> TxExtraKeyWitnessesNone
ShelleyBasedEraAlonzo
| Set.null keyhashes -> TxExtraKeyWitnessesNone
| otherwise -> TxExtraKeyWitnesses
ExtraKeyWitnessesInAlonzoEra
[ PaymentKeyHash (Shelley.coerceKeyRole keyhash)
| keyhash <- Set.toList keyhashes ]
where
keyhashes = body ^. L.reqSignerHashesTxBodyL
ShelleyBasedEraBabbage
| Set.null keyhashes -> TxExtraKeyWitnessesNone
| otherwise -> TxExtraKeyWitnesses
ExtraKeyWitnessesInBabbageEra
[ PaymentKeyHash (Shelley.coerceKeyRole keyhash)
| keyhash <- Set.toList keyhashes ]
where
keyhashes = body ^. L.reqSignerHashesTxBodyL
ShelleyBasedEraConway
| Set.null keyhashes -> TxExtraKeyWitnessesNone
| otherwise -> TxExtraKeyWitnesses
ExtraKeyWitnessesInConwayEra
[ PaymentKeyHash (Shelley.coerceKeyRole keyhash)
| keyhash <- Set.toList keyhashes ]
where
keyhashes = body ^. L.reqSignerHashesTxBodyL
caseShelleyToMaryOrAlonzoEraOnwards
(const TxExtraKeyWitnessesNone)
(\w ->
let keyhashes = body ^. L.reqSignerHashesTxBodyL in
if Set.null keyhashes
then TxExtraKeyWitnessesNone
else
TxExtraKeyWitnesses w
[ PaymentKeyHash (Shelley.coerceKeyRole keyhash)
| keyhash <- Set.toList $ body ^. L.reqSignerHashesTxBodyL
]
)
sbe

fromLedgerTxWithdrawals
:: 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 @@ -392,15 +392,13 @@ module Cardano.Api (
ValidityNoUpperBoundSupportedInEra(..),
ValidityLowerBoundSupportedInEra(..),
AuxScriptsSupportedInEra(..),
TxExtraKeyWitnessesSupportedInEra(..),

-- ** Feature availability functions
collateralSupportedInEra,
validityUpperBoundSupportedInEra,
validityNoUpperBoundSupportedInEra,
validityLowerBoundSupportedInEra,
auxScriptsSupportedInEra,
extraKeyWitnessesSupportedInEra,

-- ** Era-dependent protocol features
ProtocolUTxOCostPerByteFeature(..),
Expand Down