Skip to content

Commit

Permalink
Move StakeAddressDelegationError StakeAddressRegistrationError and Sh…
Browse files Browse the repository at this point in the history
…elleyStakeAddressCmdError error types to own modules
  • Loading branch information
newhoggy committed Aug 18, 2023
1 parent 33f0e33 commit 01ecbd3
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 54 deletions.
4 changes: 3 additions & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ library
Cardano.CLI.Types.Common
Cardano.CLI.Types.Errors.GovernanceCmdError
Cardano.CLI.Types.Errors.ScriptDecodeError
Cardano.CLI.Types.Errors.StakeAddress
Cardano.CLI.Types.Errors.ShelleyStakeAddressCmdError
Cardano.CLI.Types.Errors.StakeAddressDelegationError
Cardano.CLI.Types.Errors.StakeAddressRegistrationError
Cardano.CLI.Types.Governance
Cardano.CLI.Types.Key
Cardano.CLI.Types.Output
Expand Down
3 changes: 2 additions & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Run/Certificate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import Cardano.Api.Shelley

import Cardano.CLI.Read
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Errors.StakeAddress
import Cardano.CLI.Types.Errors.ShelleyStakeAddressCmdError
import Cardano.CLI.Types.Errors.StakeAddressRegistrationError
import Cardano.CLI.Types.Key

import Control.Monad.Trans.Class
Expand Down
4 changes: 3 additions & 1 deletion cardano-cli/src/Cardano/CLI/Legacy/Run/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import Cardano.Api.Shelley
import Cardano.CLI.EraBased.Run.Certificate
import Cardano.CLI.Legacy.Commands.StakeAddress
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Errors.StakeAddress
import Cardano.CLI.Types.Errors.ShelleyStakeAddressCmdError
import Cardano.CLI.Types.Errors.StakeAddressDelegationError
import Cardano.CLI.Types.Errors.StakeAddressRegistrationError
import Cardano.CLI.Types.Key (DelegationTarget (..), StakeIdentifier (..),
StakeVerifier (..), VerificationKeyOrFile, readVerificationKeyOrFile,
readVerificationKeyOrHashOrFile)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.Types.Errors.ShelleyStakeAddressCmdError
( ShelleyStakeAddressCmdError(..)
) where

import Cardano.Api

import Cardano.CLI.Read
import Cardano.CLI.Types.Errors.StakeAddressDelegationError
import Cardano.CLI.Types.Errors.StakeAddressRegistrationError

data ShelleyStakeAddressCmdError
= ShelleyStakeAddressCmdReadKeyFileError !(FileError InputDecodeError)
| ShelleyStakeAddressCmdReadScriptFileError !(FileError ScriptDecodeError)
| ShelleyStakeAddressCmdWriteFileError !(FileError ())
| StakeRegistrationError !StakeAddressRegistrationError
| StakeDelegationError !StakeAddressDelegationError
deriving Show

instance Error ShelleyStakeAddressCmdError where
displayError = \case
ShelleyStakeAddressCmdReadKeyFileError fileErr -> displayError fileErr
ShelleyStakeAddressCmdWriteFileError fileErr -> displayError fileErr
ShelleyStakeAddressCmdReadScriptFileError fileErr -> displayError fileErr
StakeRegistrationError regErr -> displayError regErr
StakeDelegationError delegErr -> displayError delegErr
50 changes: 0 additions & 50 deletions cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddress.hs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

module Cardano.CLI.Types.Errors.StakeAddressDelegationError
( StakeAddressDelegationError(..)
) where

import Cardano.Api

import qualified Data.Text as Text

newtype StakeAddressDelegationError = VoteDelegationNotSupported AnyShelleyToBabbageEra deriving Show

instance Error StakeAddressDelegationError where
displayError = \case
VoteDelegationNotSupported (AnyShelleyToBabbageEra stbe) -> "Vote delegation not supported in " <> eraTxt stbe <> " era."
where
eraTxt :: forall era. ShelleyToBabbageEra era -> String
eraTxt stbe' = shelleyToBabbageEraConstraints stbe' $
Text.unpack . renderEra $ AnyCardanoEra (cardanoEra @era)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.Types.Errors.StakeAddressRegistrationError
( StakeAddressRegistrationError(..)
) where

import Cardano.Api

data StakeAddressRegistrationError = StakeAddressRegistrationDepositRequired
deriving Show

instance Error StakeAddressRegistrationError where
displayError = \case
StakeAddressRegistrationDepositRequired -> "Stake address deposit required."
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import Cardano.CLI.EraBased.Run.Governance.Committee
import Cardano.CLI.EraBased.Vote
import Cardano.CLI.Read
import Cardano.CLI.Types.Errors.GovernanceCmdError
import Cardano.CLI.Types.Errors.StakeAddress
import Cardano.CLI.Types.Errors.ShelleyStakeAddressCmdError
import Cardano.CLI.Types.Errors.StakeAddressDelegationError
import Cardano.CLI.Types.Errors.StakeAddressRegistrationError

import Data.Text.Encoding.Error
import GHC.Stack (HasCallStack)
Expand Down

0 comments on commit 01ecbd3

Please sign in to comment.