Skip to content

Commit

Permalink
Example refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Dec 13, 2023
1 parent 5259d54 commit aa3ec2c
Showing 1 changed file with 10 additions and 30 deletions.
40 changes: 10 additions & 30 deletions cardano-api/internal/Cardano/Api/Protocol/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,58 +60,38 @@ protocolVersionToSbe ExperimentalProtocolVersion = ShelleyBasedEraConway

-- An Example
validateTxBodyContent'
:: ShelleyBasedEra era
:: VersionToEra version ~ era
=> SomeProtocolVersion version
-> TxBodyContent BuildTx era
-> Either TxBodyError ()
validateTxBodyContent' sbe txBodContent@TxBodyContent {
validateTxBodyContent' p txBodContent@TxBodyContent {
txIns,
txInsCollateral,
txOuts,
txProtocolParams,
txMintValue,
txMetadata} =
let witnesses = collectTxBodyScriptWitnesses sbe txBodContent

let sbe = protocolVersionToSbe p
witnesses = collectTxBodyScriptWitnesses sbe txBodContent
languages = Set.fromList
[ toAlonzoLanguage (AnyPlutusScriptVersion v)
| (_, AnyScriptWitness (PlutusScriptWitness _ v _ _ _ _)) <- witnesses
]
in case sbe of
ShelleyBasedEraShelley -> do
validateTxIns txIns
guardShelleyTxInsOverflow (map fst txIns)
validateTxOuts sbe txOuts
validateMetadata txMetadata
ShelleyBasedEraAllegra -> do
validateTxIns txIns
guardShelleyTxInsOverflow (map fst txIns)
validateTxOuts sbe txOuts
validateMetadata txMetadata
ShelleyBasedEraMary -> do
validateTxIns txIns
guardShelleyTxInsOverflow (map fst txIns)
validateTxOuts sbe txOuts
validateMetadata txMetadata
validateMintValue txMintValue
ShelleyBasedEraAlonzo -> do
validateTxIns txIns
guardShelleyTxInsOverflow (map fst txIns)
validateTxOuts sbe txOuts
validateMetadata txMetadata
validateMintValue txMintValue
validateTxInsCollateral txInsCollateral languages
validateProtocolParameters txProtocolParams languages
ShelleyBasedEraBabbage -> do
in case p of
CurrentProtocolVersion -> do
validateTxIns txIns
guardShelleyTxInsOverflow (map fst txIns)
validateTxOuts sbe txOuts
validateMetadata txMetadata
validateMintValue txMintValue
validateTxInsCollateral txInsCollateral languages
validateProtocolParameters txProtocolParams languages
ShelleyBasedEraConway -> do
ExperimentalProtocolVersion -> do
validateTxIns txIns
validateTxOuts sbe txOuts
validateMetadata txMetadata
validateMintValue txMintValue
validateTxInsCollateral txInsCollateral languages
validateProtocolParameters txProtocolParams languages

0 comments on commit aa3ec2c

Please sign in to comment.