Skip to content

Commit 2124f5a

Browse files
authored
Merge pull request #1252 from IntersectMBO/jordan/refactor-2025-07-23
Run weeder
2 parents 9f69609 + 781305c commit 2124f5a

File tree

18 files changed

+8
-502
lines changed

18 files changed

+8
-502
lines changed

cardano-cli/cardano-cli.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ library
220220
Cardano.CLI.Type.Error.StakeAddressRegistrationError
221221
Cardano.CLI.Type.Error.StakeCredentialError
222222
Cardano.CLI.Type.Error.StakePoolCmdError
223-
Cardano.CLI.Type.Error.TextViewFileError
224223
Cardano.CLI.Type.Error.TxCmdError
225224
Cardano.CLI.Type.Error.TxValidationError
226225
Cardano.CLI.Type.Governance

cardano-cli/src/Cardano/CLI/Byron/Delegation.hs

Lines changed: 2 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -4,126 +4,21 @@
44
{-# LANGUAGE ScopedTypeVariables #-}
55

66
module Cardano.CLI.Byron.Delegation
7-
( ByronDelegationError (..)
8-
, checkByronGenesisDelegation
9-
, issueByronGenesisDelegation
10-
, renderByronDelegationError
11-
, serialiseDelegationCert
7+
( serialiseDelegationCert
128
, serialiseByronWitness
139
)
1410
where
1511

16-
import Cardano.Api.Byron (ACertificate (delegateVK))
1712
import Cardano.Api.Byron hiding (delegateVK)
18-
import Cardano.Api.Ledger qualified as L
19-
import Cardano.Api.Monad.Error
20-
import Cardano.Api.Pretty
2113
import Cardano.Api.Serialise.Raw
2214

23-
import Cardano.CLI.Type.Common (CertificateFile (..))
24-
import Cardano.Crypto (ProtocolMagicId)
25-
import Cardano.Crypto qualified as Crypto
26-
import Cardano.Prelude (canonicalDecodePretty, canonicalEncodePretty)
15+
import Cardano.Prelude (canonicalEncodePretty)
2716

2817
import Prelude hiding ((.))
2918

3019
import Control.Category
31-
import Control.Monad (unless)
3220
import Data.ByteString (ByteString)
3321
import Data.ByteString.Lazy qualified as LB
34-
import Data.Text (Text)
35-
import Formatting (Format, sformat)
36-
37-
data ByronDelegationError
38-
= CertificateValidationErrors !FilePath ![Text]
39-
| DlgCertificateDeserialisationFailed !FilePath !Text
40-
deriving Show
41-
42-
renderByronDelegationError :: ByronDelegationError -> Doc ann
43-
renderByronDelegationError = \case
44-
CertificateValidationErrors certFp errs ->
45-
"Certificate validation error(s) at: " <> pshow certFp <> " Errors: " <> pshow errs
46-
DlgCertificateDeserialisationFailed certFp deSererr ->
47-
"Certificate deserialisation error at: " <> pshow certFp <> " Error: " <> pshow deSererr
48-
49-
-- TODO: we need to support password-protected secrets.
50-
51-
-- | Issue a certificate for genesis delegation to a delegate key, signed by the
52-
-- issuer key, for a given protocol magic and coming into effect at given epoch.
53-
issueByronGenesisDelegation
54-
:: ProtocolMagicId
55-
-> EpochNumber
56-
-> Crypto.SigningKey
57-
-> Crypto.VerificationKey
58-
-> Certificate
59-
issueByronGenesisDelegation magic epoch issuerSK delegateVK' =
60-
signCertificate magic delegateVK' epoch $
61-
Crypto.noPassSafeSigner issuerSK
62-
63-
-- | Verify that a certificate signifies genesis delegation by assumed genesis key
64-
-- to a delegate key, for a given protocol magic.
65-
-- If certificate fails validation, throw an error.
66-
checkByronGenesisDelegation
67-
:: CertificateFile
68-
-> ProtocolMagicId
69-
-> Crypto.VerificationKey
70-
-> Crypto.VerificationKey
71-
-> ExceptT ByronDelegationError IO ()
72-
checkByronGenesisDelegation (CertificateFile certF) magic issuer delegate = do
73-
ecert <- liftIO $ canonicalDecodePretty <$> LB.readFile certF
74-
case ecert of
75-
Left e -> left $ DlgCertificateDeserialisationFailed certF e
76-
Right (cert :: Certificate) -> do
77-
let issues = checkDlgCert cert magic issuer delegate
78-
unless (null issues) $
79-
left $
80-
CertificateValidationErrors certF issues
81-
82-
checkDlgCert
83-
:: ACertificate a
84-
-> ProtocolMagicId
85-
-> Crypto.VerificationKey
86-
-> Crypto.VerificationKey
87-
-> [Text]
88-
checkDlgCert cert magic issuerVK' delegateVK' =
89-
mconcat
90-
[ [ sformat "Certificate does not have a valid signature."
91-
| not (isValid magic' cert')
92-
]
93-
, [ sformat
94-
("Certificate issuer " . vkF . " doesn't match expected: " . vkF)
95-
(issuerVK cert)
96-
issuerVK'
97-
| issuerVK cert /= issuerVK'
98-
]
99-
, [ sformat
100-
("Certificate delegate " . vkF . " doesn't match expected: " . vkF)
101-
(delegateVK cert)
102-
delegateVK'
103-
| delegateVK cert /= delegateVK'
104-
]
105-
]
106-
where
107-
magic' :: L.Annotated ProtocolMagicId ByteString
108-
magic' = L.Annotated magic (L.serialize' L.byronProtVer magic)
109-
110-
epoch :: EpochNumber
111-
epoch = L.unAnnotated $ aEpoch cert
112-
113-
cert' :: ACertificate ByteString
114-
cert' =
115-
let unannotated =
116-
cert
117-
{ aEpoch = L.Annotated epoch ()
118-
, annotation = ()
119-
}
120-
in unannotated
121-
{ annotation = L.serialize' L.byronProtVer unannotated
122-
, aEpoch = L.Annotated epoch (L.serialize' L.byronProtVer epoch)
123-
}
124-
125-
vkF :: forall r. Format r (Crypto.VerificationKey -> r)
126-
vkF = Crypto.fullVerificationKeyF
12722

12823
serialiseDelegationCert :: Certificate -> ByteString
12924
serialiseDelegationCert = LB.toStrict . canonicalEncodePretty

cardano-cli/src/Cardano/CLI/Byron/Legacy.hs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
module Cardano.CLI.Byron.Legacy
77
( LegacyDelegateKey (..)
8-
, encodeLegacyDelegateKey
98
, decodeLegacyDelegateKey
109
)
1110
where
@@ -16,7 +15,6 @@ import Cardano.Crypto.Signing (SigningKey (..))
1615
import Cardano.Crypto.Wallet qualified as Wallet
1716

1817
import Codec.CBOR.Decoding qualified as D
19-
import Codec.CBOR.Encoding qualified as E
2018
import Control.Monad (when)
2119
import Data.Text (Text)
2220
import Formatting (build, formatToString)
@@ -29,9 +27,6 @@ import Formatting (build, formatToString)
2927
-- Legacy reference: https://github.com/input-output-hk/cardano-sl/blob/release/3.0.1/lib/src/Pos/Util/UserSecret.hs#L189
3028
newtype LegacyDelegateKey = LegacyDelegateKey {lrkSigningKey :: SigningKey}
3129

32-
encodeXPrv :: Wallet.XPrv -> E.Encoding
33-
encodeXPrv a = E.encodeBytes $ Wallet.unXPrv a
34-
3530
decodeXPrv :: D.Decoder s Wallet.XPrv
3631
decodeXPrv =
3732
either (fail . formatToString build) pure . Wallet.xprv =<< D.decodeBytesCanonical
@@ -59,19 +54,6 @@ matchSize requestedSize lbl actualSize =
5954
<> textShow actualSize
6055
)
6156

62-
-- | Encoder for a Byron/Classic signing key.
63-
-- Lifted from cardano-sl legacy codebase.
64-
encodeLegacyDelegateKey :: LegacyDelegateKey -> E.Encoding
65-
encodeLegacyDelegateKey (LegacyDelegateKey (SigningKey sk)) =
66-
E.encodeListLen 4
67-
<> E.encodeListLen 1
68-
<> E.encodeBytes "vss deprecated"
69-
<> E.encodeListLen 1
70-
<> encodeXPrv sk
71-
<> E.encodeListLenIndef
72-
<> E.encodeBreak
73-
<> E.encodeListLen 0
74-
7557
-- | Decoder for a Byron/Classic signing key.
7658
-- Lifted from cardano-sl legacy codebase.
7759
decodeLegacyDelegateKey :: D.Decoder s LegacyDelegateKey

cardano-cli/src/Cardano/CLI/Byron/Tx.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module Cardano.CLI.Byron.Tx
1818
, renderByronTxError
1919
-- TODO: remove when they are exported from the ledger
2020
, fromCborTxAux
21-
, toCborTxAux
2221
, ScriptValidity (..)
2322
)
2423
where
@@ -220,6 +219,3 @@ fromCborTxAux lbs =
220219
where
221220
annotationBytes :: Functor f => LB.ByteString -> f L.ByteSpan -> f B.ByteString
222221
annotationBytes bytes = fmap (LB.toStrict . L.slice bytes)
223-
224-
toCborTxAux :: Byron.ATxAux ByteString -> LB.ByteString
225-
toCborTxAux = LB.fromStrict . Byron.aTaAnnotation -- The ByteString anotation is the CBOR encoded version.

cardano-cli/src/Cardano/CLI/Compatible/Transaction/TxOut.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ toTxAlonzoDatum supp cliDatum =
8585
pure $ TxOutDatumInline babbageOnwards sData
8686

8787
getReferenceScript
88-
:: ()
89-
=> BabbageEraOnwards era
88+
:: BabbageEraOnwards era
9089
-> ReferenceScriptAnyEra
9190
-> CIO e (ReferenceScript era)
9291
getReferenceScript w = \case

cardano-cli/src/Cardano/CLI/Environment.hs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
-- | This module defines constants derived from the environment.
55
module Cardano.CLI.Environment
66
( EnvCli (..)
7-
, envCliAnyEon
87
, envCliEra
98
, getEnvCli
109
, getEnvNetworkId
@@ -15,15 +14,11 @@ where
1514
import Cardano.Api
1615
( AnyCardanoEra (..)
1716
, CardanoEra (..)
18-
, Eon
19-
, EraInEon (..)
2017
, NetworkId (..)
2118
, NetworkMagic (..)
22-
, forEraInEonMaybe
2319
)
2420
import Cardano.Api.Experimental qualified as Exp
2521

26-
import Data.Typeable
2722
import Data.Word (Word32)
2823
import System.Environment qualified as IO
2924
import System.IO qualified as IO
@@ -48,11 +43,6 @@ getEnvCli = do
4843
, envCliAnyCardanoEra = mCardanoEra
4944
}
5045

51-
envCliAnyEon :: Typeable eon => Eon eon => EnvCli -> Maybe (EraInEon eon)
52-
envCliAnyEon envCli = do
53-
AnyCardanoEra era <- envCliAnyCardanoEra envCli
54-
forEraInEonMaybe era EraInEon
55-
5646
anyCardanoEraToEra :: AnyCardanoEra -> Maybe (Exp.Era Exp.ConwayEra)
5747
anyCardanoEraToEra (AnyCardanoEra era) =
5848
case era of

0 commit comments

Comments
 (0)