Skip to content

Commit

Permalink
Remove Either from return type of convPParamsToScriptIntegrityHash
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Oct 9, 2023
1 parent 2014b06 commit 7100692
Showing 1 changed file with 43 additions and 56 deletions.
99 changes: 43 additions & 56 deletions cardano-api/internal/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1928,16 +1928,11 @@ createTransactionBody sbe txBodyContent =
ShelleyBasedEraAlonzo -> do
update <- convTxUpdateProposal sbe (txUpdateProposal txBodyContent)
let sData = convScriptData sbe apiTxOuts apiScriptWitnesses
scriptIntegrityHash <-
case sData of
TxBodyNoScriptData -> pure SNothing
TxBodyScriptData _ datums redeemers ->
convPParamsToScriptIntegrityHash
AlonzoEraOnwardsAlonzo
apiProtocolParameters
redeemers
datums
languages
let scriptIntegrityHash =
case sData of
TxBodyNoScriptData -> SNothing
TxBodyScriptData w datums redeemers ->
convPParamsToScriptIntegrityHash w apiProtocolParameters redeemers datums languages
let ledgerTxBody =
mkTxBody ShelleyBasedEraAlonzo txBodyContent txAuxData
& L.certsTxBodyL .~ certs
Expand All @@ -1959,28 +1954,23 @@ createTransactionBody sbe txBodyContent =
ShelleyBasedEraBabbage -> do
update <- convTxUpdateProposal sbe (txUpdateProposal txBodyContent)
let sData = convScriptData sbe apiTxOuts apiScriptWitnesses
scriptIntegrityHash <-
case sData of
TxBodyNoScriptData -> pure SNothing
TxBodyScriptData _sDataSupported datums redeemers ->
convPParamsToScriptIntegrityHash
AlonzoEraOnwardsBabbage
apiProtocolParameters
redeemers
datums
languages
let scriptIntegrityHash =
case sData of
TxBodyNoScriptData -> SNothing
TxBodyScriptData w datums redeemers ->
convPParamsToScriptIntegrityHash w apiProtocolParameters redeemers datums languages
let ledgerTxBody =
mkTxBody ShelleyBasedEraBabbage txBodyContent txAuxData
& L.certsTxBodyL .~ certs
& L.updateTxBodyL .~ update
& L.vldtTxBodyL .~ validityInterval
& L.collateralInputsTxBodyL .~ collTxIns
& L.reqSignerHashesTxBodyL .~ convExtraKeyWitnesses apiExtraKeyWitnesses
& L.mintTxBodyL .~ convMintValue apiMintValue
& L.scriptIntegrityHashTxBodyL .~ scriptIntegrityHash
& L.referenceInputsTxBodyL .~ refTxIns
& L.collateralReturnTxBodyL .~ returnCollateral
& L.totalCollateralTxBodyL .~ totalCollateral
& L.certsTxBodyL .~ certs
& L.updateTxBodyL .~ update
& L.vldtTxBodyL .~ validityInterval
& L.collateralInputsTxBodyL .~ collTxIns
& L.reqSignerHashesTxBodyL .~ convExtraKeyWitnesses apiExtraKeyWitnesses
& L.mintTxBodyL .~ convMintValue apiMintValue
& L.scriptIntegrityHashTxBodyL .~ scriptIntegrityHash
& L.referenceInputsTxBodyL .~ refTxIns
& L.collateralReturnTxBodyL .~ returnCollateral
& L.totalCollateralTxBodyL .~ totalCollateral
-- TODO: NetworkId for hardware wallets. We don't always want this
-- & L.networkIdTxBodyL .~ ...
pure $ ShelleyTxBody sbe
Expand All @@ -1992,28 +1982,22 @@ createTransactionBody sbe txBodyContent =

ShelleyBasedEraConway -> do
let sData = convScriptData sbe apiTxOuts apiScriptWitnesses
scriptIntegrityHash <-
case sData of
TxBodyNoScriptData -> pure SNothing
TxBodyScriptData _sDataSupported datums redeemers ->
shelleyBasedEraConstraints sbe
$ convPParamsToScriptIntegrityHash
AlonzoEraOnwardsConway
apiProtocolParameters
redeemers
datums
languages
let scriptIntegrityHash =
case sData of
TxBodyNoScriptData -> SNothing
TxBodyScriptData w datums redeemers ->
convPParamsToScriptIntegrityHash w apiProtocolParameters redeemers datums languages
let ledgerTxBody =
mkTxBody ShelleyBasedEraConway txBodyContent txAuxData
& L.certsTxBodyL .~ certs
& L.vldtTxBodyL .~ validityInterval
& L.collateralInputsTxBodyL .~ collTxIns
& L.reqSignerHashesTxBodyL .~ convExtraKeyWitnesses apiExtraKeyWitnesses
& L.mintTxBodyL .~ convMintValue apiMintValue
& L.scriptIntegrityHashTxBodyL .~ scriptIntegrityHash
& L.referenceInputsTxBodyL .~ refTxIns
& L.collateralReturnTxBodyL .~ returnCollateral
& L.totalCollateralTxBodyL .~ totalCollateral
& L.certsTxBodyL .~ certs
& L.vldtTxBodyL .~ validityInterval
& L.collateralInputsTxBodyL .~ collTxIns
& L.reqSignerHashesTxBodyL .~ convExtraKeyWitnesses apiExtraKeyWitnesses
& L.mintTxBodyL .~ convMintValue apiMintValue
& L.scriptIntegrityHashTxBodyL .~ scriptIntegrityHash
& L.referenceInputsTxBodyL .~ refTxIns
& L.collateralReturnTxBodyL .~ returnCollateral
& L.totalCollateralTxBodyL .~ totalCollateral
-- TODO: NetworkId for hardware wallets. We don't always want this
-- & L.networkIdTxBodyL .~ ...
pure $ ShelleyTxBody sbe
Expand Down Expand Up @@ -2812,13 +2796,13 @@ convPParamsToScriptIntegrityHash :: ()
-> Alonzo.Redeemers (ShelleyLedgerEra era)
-> Alonzo.TxDats (ShelleyLedgerEra era)
-> Set Alonzo.Language
-> Either TxBodyError (StrictMaybe (L.ScriptIntegrityHash (Ledger.EraCrypto (ShelleyLedgerEra era))))
-> StrictMaybe (L.ScriptIntegrityHash (Ledger.EraCrypto (ShelleyLedgerEra era)))
convPParamsToScriptIntegrityHash w txProtocolParams redeemers datums languages =
alonzoEraOnwardsConstraints w $
case txProtocolParams of
BuildTxWith Nothing -> return SNothing
BuildTxWith Nothing -> SNothing
BuildTxWith (Just (LedgerProtocolParameters pp)) ->
pure $ Alonzo.hashScriptIntegrity (Set.map (L.getLanguageView pp) languages ) redeemers datums
Alonzo.hashScriptIntegrity (Set.map (L.getLanguageView pp) languages) redeemers datums

convLanguages :: [(ScriptWitnessIndex, AnyScriptWitness era)] -> Set Alonzo.Language
convLanguages witnesses =
Expand Down Expand Up @@ -2999,7 +2983,8 @@ makeShelleyTransactionBody sbe@ShelleyBasedEraAlonzo

validateTxBodyContent sbe txbodycontent
update <- convTxUpdateProposal sbe txUpdateProposal
scriptIntegrityHash <- convPParamsToScriptIntegrityHash AlonzoEraOnwardsAlonzo txProtocolParams redeemers datums languages
let scriptIntegrityHash =
convPParamsToScriptIntegrityHash AlonzoEraOnwardsAlonzo txProtocolParams redeemers datums languages
return $
ShelleyTxBody sbe
(mkCommonTxBody sbe txIns txOuts txFee txWithdrawals txAuxData
Expand Down Expand Up @@ -3085,7 +3070,8 @@ makeShelleyTransactionBody sbe@ShelleyBasedEraBabbage

validateTxBodyContent sbe txbodycontent
update <- convTxUpdateProposal sbe txUpdateProposal
scriptIntegrityHash <- convPParamsToScriptIntegrityHash AlonzoEraOnwardsBabbage txProtocolParams redeemers datums languages
let scriptIntegrityHash =
convPParamsToScriptIntegrityHash AlonzoEraOnwardsBabbage txProtocolParams redeemers datums languages
return $
ShelleyTxBody sbe
(mkCommonTxBody sbe txIns txOuts txFee txWithdrawals txAuxData
Expand Down Expand Up @@ -3186,7 +3172,8 @@ makeShelleyTransactionBody sbe@ShelleyBasedEraConway
} = do

validateTxBodyContent sbe txbodycontent
scriptIntegrityHash <- convPParamsToScriptIntegrityHash AlonzoEraOnwardsConway txProtocolParams redeemers datums languages
let scriptIntegrityHash =
convPParamsToScriptIntegrityHash AlonzoEraOnwardsConway txProtocolParams redeemers datums languages
return $
ShelleyTxBody sbe
(mkCommonTxBody sbe txIns txOuts txFee txWithdrawals txAuxData
Expand Down

0 comments on commit 7100692

Please sign in to comment.