Skip to content

Commit

Permalink
Refactor: move certificate witness lookup to cardano-api
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Nov 24, 2023
1 parent cead75f commit a1acc61
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 51 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository cardano-haskell-packages
-- you need to run if you change them
index-state:
, hackage.haskell.org 2023-11-09T23:50:15Z
, cardano-haskell-packages 2023-11-21T19:00:47Z
, cardano-haskell-packages 2023-11-24T10:15:21Z

packages:
cardano-cli
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ library
, binary
, bytestring
, canonical-json
, cardano-api ^>= 8.34.0.0
, cardano-api ^>= 8.34.1.0
, cardano-binary
, cardano-crypto
, cardano-crypto-class ^>= 2.1.2
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ readScriptWitness era (PlutusReferenceScriptWitnessFiles refTxIn
error "readScriptWitness: Should not be possible to specify a simple script"
PlutusScriptLanguage version -> do
datum <- firstExceptT ScriptWitnessErrorScriptData
$ readScriptDatumOrFile datumOrFile
$ readScriptDatumOrFile datumOrFile
redeemer <- firstExceptT ScriptWitnessErrorScriptData
$ readScriptRedeemerOrFile redeemerOrFile
$ readScriptRedeemerOrFile redeemerOrFile
return $ PlutusScriptWitness
sLangInEra
version
Expand Down
50 changes: 6 additions & 44 deletions cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ module Cardano.CLI.Types.Errors.TxValidationError
) where

import Cardano.Api
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Pretty
import Cardano.Api.Shelley

Expand Down Expand Up @@ -225,9 +224,8 @@ validateTxWithdrawals era withdrawals = do
-> (StakeAddress, Lovelace, BuildTxWith BuildTx (Witness WitCtxStake era))
convert (sAddr, ll, mScriptWitnessFiles) =
case mScriptWitnessFiles of
Just sWit -> do
(sAddr, ll, BuildTxWith $ ScriptWitness ScriptWitnessForStakeAddr sWit)
Nothing -> (sAddr,ll, BuildTxWith $ KeyWitness KeyWitnessForStakeAddr)
Just sWit -> (sAddr, ll, BuildTxWith $ ScriptWitness ScriptWitnessForStakeAddr sWit)
Nothing -> (sAddr, ll, BuildTxWith $ KeyWitness KeyWitnessForStakeAddr)

newtype TxCertificatesValidationError
= TxCertificatesValidationNotSupported AnyCardanoEra
Expand All @@ -249,50 +247,14 @@ validateTxCertificates era certsAndScriptWitnesses = cardanoEraConstraints era $
reqWits = Map.fromList $ mapMaybe convert certsAndScriptWitnesses
pure $ TxCertificates supported certs $ BuildTxWith reqWits
where
-- We get the stake credential witness for a certificate that requires it.
-- NB: Only stake address deregistration and delegation requires
-- witnessing (witness can be script or key)
deriveStakeCredentialWitness
:: Certificate era
-> Maybe StakeCredential
deriveStakeCredentialWitness = fmap fromShelleyStakeCredential . \case
ShelleyRelatedCertificate stbEra shelleyCert -> shelleyToBabbageEraConstraints stbEra $
case shelleyCert of
L.RegTxCert _sCred -> Nothing -- not required
L.UnRegTxCert sCred -> Just sCred
L.DelegStakeTxCert sCred _ -> Just sCred
L.RegPoolTxCert _ -> Nothing
L.RetirePoolTxCert _ _ -> Nothing
L.MirTxCert _ -> Nothing
L.GenesisDelegTxCert{} -> Nothing

ConwayCertificate cEra conwayCert -> conwayEraOnwardsConstraints cEra $
case conwayCert of
L.RegPoolTxCert _ -> Nothing
L.RetirePoolTxCert _ _ -> Nothing
L.RegTxCert _ -> Nothing
L.UnRegTxCert sCred -> Just sCred
L.RegDepositTxCert _ _ -> Nothing
L.UnRegDepositTxCert sCred _ -> Just sCred
L.DelegTxCert sCred _ -> Just sCred
L.RegDepositDelegTxCert sCred _ _ -> Just sCred
L.AuthCommitteeHotKeyTxCert{} -> Nothing
L.ResignCommitteeColdTxCert _ _ -> Nothing
L.RegDRepTxCert{} -> Nothing
L.UnRegDRepTxCert{} -> Nothing
L.UpdateDRepTxCert{} -> Nothing

convert
:: (Certificate era, Maybe (ScriptWitness WitCtxStake era))
-> Maybe (StakeCredential, Witness WitCtxStake era)
convert (cert, mScriptWitnessFiles) = do
sCred <- deriveStakeCredentialWitness cert
case mScriptWitnessFiles of
Just sWit -> do
Just ( sCred
, ScriptWitness ScriptWitnessForStakeAddr sWit
)
Nothing -> Just (sCred, KeyWitness KeyWitnessForStakeAddr)
sCred <- selectStakeCredentialWitness cert
Just $ case mScriptWitnessFiles of
Just sWit -> (sCred, ScriptWitness ScriptWitnessForStakeAddr sWit)
Nothing -> (sCred, KeyWitness KeyWitnessForStakeAddr)

newtype TxProtocolParametersValidationError
= ProtocolParametersNotSupported AnyCardanoEra
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a1acc61

Please sign in to comment.