Skip to content

Commit

Permalink
Add legacy prefix to legacy run commands
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Aug 30, 2023
1 parent 79f63a4 commit c3f8eed
Show file tree
Hide file tree
Showing 12 changed files with 333 additions and 311 deletions.
18 changes: 9 additions & 9 deletions cardano-cli/src/Cardano/CLI/Legacy/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import Control.Monad.Trans.Except.Extra (firstExceptT)

runLegacyCmds :: LegacyCmds -> ExceptT CmdError IO ()
runLegacyCmds = \case
LegacyAddressCmds cmd -> firstExceptT CmdAddressError $ runAddressCmds cmd
LegacyGenesisCmds cmd -> firstExceptT CmdGenesisError $ runGenesisCmds cmd
LegacyAddressCmds cmd -> firstExceptT CmdAddressError $ runLegacyAddressCmds cmd
LegacyGenesisCmds cmd -> firstExceptT CmdGenesisError $ runLegacyGenesisCmds cmd
LegacyGovernanceCmds cmd -> firstExceptT CmdGovernanceCmdError $ runLegacyGovernanceCmds cmd
LegacyKeyCmds cmd -> firstExceptT CmdKeyError $ runKeyCmds cmd
LegacyNodeCmds cmd -> firstExceptT CmdNodeError $ runNodeCmds cmd
LegacyPoolCmds cmd -> firstExceptT CmdPoolError $ runPoolCmds cmd
LegacyQueryCmds cmd -> firstExceptT CmdQueryError $ runQueryCmds cmd
LegacyStakeAddressCmds cmd -> firstExceptT CmdStakeAddressError $ runStakeAddressCmds cmd
LegacyTextViewCmds cmd -> firstExceptT CmdTextViewError $ runTextViewCmds cmd
LegacyTransactionCmds cmd -> firstExceptT CmdTransactionError $ runTransactionCmds cmd
LegacyKeyCmds cmd -> firstExceptT CmdKeyError $ runLegacyKeyCmds cmd
LegacyNodeCmds cmd -> firstExceptT CmdNodeError $ runLegacyNodeCmds cmd
LegacyPoolCmds cmd -> firstExceptT CmdPoolError $ runLegacyPoolCmds cmd
LegacyQueryCmds cmd -> firstExceptT CmdQueryError $ runLegacyQueryCmds cmd
LegacyStakeAddressCmds cmd -> firstExceptT CmdStakeAddressError $ runLegacyStakeAddressCmds cmd
LegacyTextViewCmds cmd -> firstExceptT CmdTextViewError $ runLegacyTextViewCmds cmd
LegacyTransactionCmds cmd -> firstExceptT CmdTransactionError $ runLegacyTransactionCmds cmd
37 changes: 20 additions & 17 deletions cardano-cli/src/Cardano/CLI/Legacy/Run/Address.hs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.CLI.Legacy.Run.Address
( SomeAddressVerificationKey(..)
, buildShelleyAddress
, renderShelleyAddressCmdError
, runAddressCmds
, runAddressKeyGenToFile
, runLegacyAddressCmds
, makeStakeAddressRef
) where

import Cardano.Api
import Cardano.Api.Shelley

import Cardano.CLI.Legacy.Commands.Address
import Cardano.CLI.Legacy.Run.Address.Info (runAddressInfo)
import Cardano.CLI.Legacy.Run.Address.Info (runLegacyAddressInfoCmd)
import Cardano.CLI.Read
import Cardano.CLI.Types.Key (PaymentVerifier (..), StakeIdentifier (..),
StakeVerifier (..), VerificationKeyTextOrFile, generateKeyPair, readVerificationKeyOrFile,
Expand All @@ -31,21 +31,24 @@ import Control.Monad.Trans.Except.Extra (firstExceptT, left, newExcept
import qualified Data.ByteString.Char8 as BS
import qualified Data.Text.IO as Text

runAddressCmds :: LegacyAddressCmds -> ExceptT ShelleyAddressCmdError IO ()
runAddressCmds cmd =
case cmd of
AddressKeyGen fmt kt vkf skf -> runAddressKeyGenToFile fmt kt vkf skf
AddressKeyHash vkf mOFp -> runAddressKeyHash vkf mOFp
AddressBuild paymentVerifier mbStakeVerifier nw mOutFp -> runAddressBuild paymentVerifier mbStakeVerifier nw mOutFp
AddressInfo txt mOFp -> firstExceptT ShelleyAddressCmdAddressInfoError $ runAddressInfo txt mOFp

runAddressKeyGenToFile
runLegacyAddressCmds :: LegacyAddressCmds -> ExceptT ShelleyAddressCmdError IO ()
runLegacyAddressCmds = \case
AddressKeyGen fmt kt vkf skf ->
runLegacyAddressKeyGenCmd fmt kt vkf skf
AddressKeyHash vkf mOFp ->
runLegacyAddressKeyHashCmd vkf mOFp
AddressBuild paymentVerifier mbStakeVerifier nw mOutFp ->
runLegacyAddressBuildCmd paymentVerifier mbStakeVerifier nw mOutFp
AddressInfo txt mOFp ->
firstExceptT ShelleyAddressCmdAddressInfoError $ runLegacyAddressInfoCmd txt mOFp

runLegacyAddressKeyGenCmd
:: KeyOutputFormat
-> AddressKeyType
-> VerificationKeyFile Out
-> SigningKeyFile Out
-> ExceptT ShelleyAddressCmdError IO ()
runAddressKeyGenToFile fmt kt vkf skf = case kt of
runLegacyAddressKeyGenCmd fmt kt vkf skf = case kt of
AddressKeyShelley -> generateAndWriteKeyFiles fmt AsPaymentKey vkf skf
AddressKeyShelleyExtended -> generateAndWriteKeyFiles fmt AsPaymentExtendedKey vkf skf
AddressKeyByron -> generateAndWriteByronKeyFiles AsByronKey vkf skf
Expand Down Expand Up @@ -135,10 +138,10 @@ writeByronPaymentKeyFiles vkeyPath skeyPath vkey skey = do
skeyDesc = "Payment Signing Key"
vkeyDesc = "Payment Verification Key"

runAddressKeyHash :: VerificationKeyTextOrFile
runLegacyAddressKeyHashCmd :: VerificationKeyTextOrFile
-> Maybe (File () Out)
-> ExceptT ShelleyAddressCmdError IO ()
runAddressKeyHash vkeyTextOrFile mOutputFp = do
runLegacyAddressKeyHashCmd vkeyTextOrFile mOutputFp = do
vkey <- firstExceptT ShelleyAddressCmdVerificationKeyTextOrFileError $
newExceptT $ readVerificationKeyTextOrFileAnyOf vkeyTextOrFile

Expand All @@ -150,12 +153,12 @@ runAddressKeyHash vkeyTextOrFile mOutputFp = do
Nothing -> liftIO $ BS.putStrLn hexKeyHash


runAddressBuild :: PaymentVerifier
runLegacyAddressBuildCmd :: PaymentVerifier
-> Maybe StakeIdentifier
-> NetworkId
-> Maybe (File () Out)
-> ExceptT ShelleyAddressCmdError IO ()
runAddressBuild paymentVerifier mbStakeVerifier nw mOutFp = do
runLegacyAddressBuildCmd paymentVerifier mbStakeVerifier nw mOutFp = do
outText <- case paymentVerifier of
PaymentVerifierKey payVkeyTextOrFile -> do
payVKey <- firstExceptT ShelleyAddressCmdVerificationKeyTextOrFileError $
Expand Down
6 changes: 3 additions & 3 deletions cardano-cli/src/Cardano/CLI/Legacy/Run/Address/Info.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# LANGUAGE GADTs #-}

module Cardano.CLI.Legacy.Run.Address.Info
( runAddressInfo
( runLegacyAddressInfoCmd
) where

import Cardano.Api
Expand Down Expand Up @@ -36,8 +36,8 @@ instance ToJSON AddressInfo where
, "base16" .= aiBase16 addrInfo
]

runAddressInfo :: Text -> Maybe (File () Out) -> ExceptT ShelleyAddressInfoError IO ()
runAddressInfo addrTxt mOutputFp = do
runLegacyAddressInfoCmd :: Text -> Maybe (File () Out) -> ExceptT ShelleyAddressInfoError IO ()
runLegacyAddressInfoCmd addrTxt mOutputFp = do
addrInfo <- case (Left <$> deserialiseAddress AsAddressAny addrTxt)
<|> (Right <$> deserialiseAddress AsStakeAddress addrTxt) of

Expand Down
Loading

0 comments on commit c3f8eed

Please sign in to comment.