{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.CLI.Shelley.Run.Address
  ( ShelleyAddressCmdError(..)
  , SomeAddressVerificationKey(..)
  , buildShelleyAddress
  , renderShelleyAddressCmdError
  , runAddressCmd
  , runAddressKeyGenToFile
  , makeStakeAddressRef
  ) where

import           Control.Monad.IO.Class (MonadIO (..))
import           Control.Monad.Trans.Except (ExceptT)
import           Control.Monad.Trans.Except.Extra (firstExceptT, left, newExceptT)
import qualified Data.ByteString.Char8 as BS
import           Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.IO as Text

import           Cardano.Api
import           Cardano.Api.Shelley

import           Cardano.CLI.Shelley.Key (PaymentVerifier (..), StakeVerifier (..),
                   VerificationKeyTextOrFile, VerificationKeyTextOrFileError (..), generateKeyPair,
                   readVerificationKeyOrFile, readVerificationKeyTextOrFileAnyOf,
                   renderVerificationKeyTextOrFileError)
import           Cardano.CLI.Shelley.Parsers (AddressCmd (..), AddressKeyType (..), OutputFile (..))
import           Cardano.CLI.Shelley.Run.Address.Info (ShelleyAddressInfoError, runAddressInfo)
import           Cardano.CLI.Shelley.Run.Read
import           Cardano.CLI.Types

data ShelleyAddressCmdError
  = ShelleyAddressCmdAddressInfoError !ShelleyAddressInfoError
  | ShelleyAddressCmdReadKeyFileError !(FileError InputDecodeError)
  | ShelleyAddressCmdReadScriptFileError !(FileError ScriptDecodeError)
  | ShelleyAddressCmdVerificationKeyTextOrFileError !VerificationKeyTextOrFileError
  | ShelleyAddressCmdWriteFileError !(FileError ())
  | ShelleyAddressCmdExpectedPaymentVerificationKey SomeAddressVerificationKey
  deriving Int -> ShelleyAddressCmdError -> ShowS
[ShelleyAddressCmdError] -> ShowS
ShelleyAddressCmdError -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ShelleyAddressCmdError] -> ShowS
$cshowList :: [ShelleyAddressCmdError] -> ShowS
show :: ShelleyAddressCmdError -> String
$cshow :: ShelleyAddressCmdError -> String
showsPrec :: Int -> ShelleyAddressCmdError -> ShowS
$cshowsPrec :: Int -> ShelleyAddressCmdError -> ShowS
Show

renderShelleyAddressCmdError :: ShelleyAddressCmdError -> Text
renderShelleyAddressCmdError :: ShelleyAddressCmdError -> Text
renderShelleyAddressCmdError ShelleyAddressCmdError
err =
  case ShelleyAddressCmdError
err of
    ShelleyAddressCmdAddressInfoError ShelleyAddressInfoError
addrInfoErr ->
      String -> Text
Text.pack (forall e. Error e => e -> String
displayError ShelleyAddressInfoError
addrInfoErr)
    ShelleyAddressCmdReadKeyFileError FileError InputDecodeError
fileErr ->
      String -> Text
Text.pack (forall e. Error e => e -> String
displayError FileError InputDecodeError
fileErr)
    ShelleyAddressCmdVerificationKeyTextOrFileError VerificationKeyTextOrFileError
vkTextOrFileErr ->
      VerificationKeyTextOrFileError -> Text
renderVerificationKeyTextOrFileError VerificationKeyTextOrFileError
vkTextOrFileErr
    ShelleyAddressCmdReadScriptFileError FileError ScriptDecodeError
fileErr ->
      String -> Text
Text.pack (forall e. Error e => e -> String
displayError FileError ScriptDecodeError
fileErr)
    ShelleyAddressCmdWriteFileError FileError ()
fileErr -> String -> Text
Text.pack (forall e. Error e => e -> String
displayError FileError ()
fileErr)
    ShelleyAddressCmdExpectedPaymentVerificationKey SomeAddressVerificationKey
someAddress ->
      Text
"Expected payment verification key but got: " forall a. Semigroup a => a -> a -> a
<> SomeAddressVerificationKey -> Text
renderSomeAddressVerificationKey SomeAddressVerificationKey
someAddress

runAddressCmd :: AddressCmd -> ExceptT ShelleyAddressCmdError IO ()
runAddressCmd :: AddressCmd -> ExceptT ShelleyAddressCmdError IO ()
runAddressCmd AddressCmd
cmd =
  case AddressCmd
cmd of
    AddressKeyGen AddressKeyType
kt VerificationKeyFile
vkf SigningKeyFile
skf -> AddressKeyType
-> VerificationKeyFile
-> SigningKeyFile
-> ExceptT ShelleyAddressCmdError IO ()
runAddressKeyGenToFile AddressKeyType
kt VerificationKeyFile
vkf SigningKeyFile
skf
    AddressKeyHash VerificationKeyTextOrFile
vkf Maybe OutputFile
mOFp -> VerificationKeyTextOrFile
-> Maybe OutputFile -> ExceptT ShelleyAddressCmdError IO ()
runAddressKeyHash VerificationKeyTextOrFile
vkf Maybe OutputFile
mOFp
    AddressBuild PaymentVerifier
paymentVerifier Maybe StakeVerifier
mbStakeVerifier NetworkId
nw Maybe OutputFile
mOutFp -> PaymentVerifier
-> Maybe StakeVerifier
-> NetworkId
-> Maybe OutputFile
-> ExceptT ShelleyAddressCmdError IO ()
runAddressBuild PaymentVerifier
paymentVerifier Maybe StakeVerifier
mbStakeVerifier NetworkId
nw Maybe OutputFile
mOutFp
    AddressInfo Text
txt Maybe OutputFile
mOFp -> forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ShelleyAddressInfoError -> ShelleyAddressCmdError
ShelleyAddressCmdAddressInfoError forall a b. (a -> b) -> a -> b
$ Text -> Maybe OutputFile -> ExceptT ShelleyAddressInfoError IO ()
runAddressInfo Text
txt Maybe OutputFile
mOFp

runAddressKeyGenToFile
  :: AddressKeyType
  -> VerificationKeyFile
  -> SigningKeyFile
  -> ExceptT ShelleyAddressCmdError IO ()
runAddressKeyGenToFile :: AddressKeyType
-> VerificationKeyFile
-> SigningKeyFile
-> ExceptT ShelleyAddressCmdError IO ()
runAddressKeyGenToFile AddressKeyType
kt VerificationKeyFile
vkf SigningKeyFile
skf = case AddressKeyType
kt of
  AddressKeyType
AddressKeyShelley         -> forall keyrole.
Key keyrole =>
AsType keyrole
-> VerificationKeyFile
-> SigningKeyFile
-> ExceptT ShelleyAddressCmdError IO ()
generateAndWriteKeyFiles AsType PaymentKey
AsPaymentKey          VerificationKeyFile
vkf SigningKeyFile
skf
  AddressKeyType
AddressKeyShelleyExtended -> forall keyrole.
Key keyrole =>
AsType keyrole
-> VerificationKeyFile
-> SigningKeyFile
-> ExceptT ShelleyAddressCmdError IO ()
generateAndWriteKeyFiles AsType PaymentExtendedKey
AsPaymentExtendedKey  VerificationKeyFile
vkf SigningKeyFile
skf
  AddressKeyType
AddressKeyByron           -> forall keyrole.
Key keyrole =>
AsType keyrole
-> VerificationKeyFile
-> SigningKeyFile
-> ExceptT ShelleyAddressCmdError IO ()
generateAndWriteKeyFiles AsType ByronKey
AsByronKey            VerificationKeyFile
vkf SigningKeyFile
skf

generateAndWriteKeyFiles
  :: Key keyrole
  => AsType keyrole
  -> VerificationKeyFile
  -> SigningKeyFile
  -> ExceptT ShelleyAddressCmdError IO ()
generateAndWriteKeyFiles :: forall keyrole.
Key keyrole =>
AsType keyrole
-> VerificationKeyFile
-> SigningKeyFile
-> ExceptT ShelleyAddressCmdError IO ()
generateAndWriteKeyFiles AsType keyrole
asType VerificationKeyFile
vkf SigningKeyFile
skf = do
  forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (forall keyrole.
Key keyrole =>
VerificationKeyFile
-> SigningKeyFile
-> VerificationKey keyrole
-> SigningKey keyrole
-> ExceptT ShelleyAddressCmdError IO ()
writePaymentKeyFiles VerificationKeyFile
vkf SigningKeyFile
skf) forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (forall keyrole.
Key keyrole =>
AsType keyrole -> IO (VerificationKey keyrole, SigningKey keyrole)
generateKeyPair AsType keyrole
asType)

writePaymentKeyFiles
  :: Key keyrole
  => VerificationKeyFile
  -> SigningKeyFile
  -> VerificationKey keyrole
  -> SigningKey keyrole
  -> ExceptT ShelleyAddressCmdError IO ()
writePaymentKeyFiles :: forall keyrole.
Key keyrole =>
VerificationKeyFile
-> SigningKeyFile
-> VerificationKey keyrole
-> SigningKey keyrole
-> ExceptT ShelleyAddressCmdError IO ()
writePaymentKeyFiles (VerificationKeyFile String
vkeyPath) (SigningKeyFile String
skeyPath) VerificationKey keyrole
vkey SigningKey keyrole
skey = do
  forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError () -> ShelleyAddressCmdError
ShelleyAddressCmdWriteFileError forall a b. (a -> b) -> a -> b
$ do
    forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT forall a b. (a -> b) -> a -> b
$ forall a.
HasTextEnvelope a =>
String
-> Maybe TextEnvelopeDescr -> a -> IO (Either (FileError ()) ())
writeFileTextEnvelope String
skeyPath (forall a. a -> Maybe a
Just TextEnvelopeDescr
skeyDesc) SigningKey keyrole
skey
    forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT forall a b. (a -> b) -> a -> b
$ forall a.
HasTextEnvelope a =>
String
-> Maybe TextEnvelopeDescr -> a -> IO (Either (FileError ()) ())
writeFileTextEnvelope String
vkeyPath (forall a. a -> Maybe a
Just TextEnvelopeDescr
vkeyDesc) VerificationKey keyrole
vkey
  where
    skeyDesc, vkeyDesc :: TextEnvelopeDescr
    skeyDesc :: TextEnvelopeDescr
skeyDesc = TextEnvelopeDescr
"Payment Signing Key"
    vkeyDesc :: TextEnvelopeDescr
vkeyDesc = TextEnvelopeDescr
"Payment Verification Key"

runAddressKeyHash :: VerificationKeyTextOrFile
                  -> Maybe OutputFile
                  -> ExceptT ShelleyAddressCmdError IO ()
runAddressKeyHash :: VerificationKeyTextOrFile
-> Maybe OutputFile -> ExceptT ShelleyAddressCmdError IO ()
runAddressKeyHash VerificationKeyTextOrFile
vkeyTextOrFile Maybe OutputFile
mOutputFp = do
  SomeAddressVerificationKey
vkey <- forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT VerificationKeyTextOrFileError -> ShelleyAddressCmdError
ShelleyAddressCmdVerificationKeyTextOrFileError forall a b. (a -> b) -> a -> b
$
             forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT forall a b. (a -> b) -> a -> b
$ VerificationKeyTextOrFile
-> IO
     (Either VerificationKeyTextOrFileError SomeAddressVerificationKey)
readVerificationKeyTextOrFileAnyOf VerificationKeyTextOrFile
vkeyTextOrFile

  let hexKeyHash :: ByteString
hexKeyHash = forall a.
(forall keyrole. Key keyrole => VerificationKey keyrole -> a)
-> SomeAddressVerificationKey -> a
foldSomeAddressVerificationKey
                     (forall a. SerialiseAsRawBytes a => a -> ByteString
serialiseToRawBytesHex forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall keyrole.
Key keyrole =>
VerificationKey keyrole -> Hash keyrole
verificationKeyHash) SomeAddressVerificationKey
vkey

  case Maybe OutputFile
mOutputFp of
    Just (OutputFile String
fpath) -> forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ String -> ByteString -> IO ()
BS.writeFile String
fpath ByteString
hexKeyHash
    Maybe OutputFile
Nothing -> forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ ByteString -> IO ()
BS.putStrLn ByteString
hexKeyHash


runAddressBuild :: PaymentVerifier
                -> Maybe StakeVerifier
                -> NetworkId
                -> Maybe OutputFile
                -> ExceptT ShelleyAddressCmdError IO ()
runAddressBuild :: PaymentVerifier
-> Maybe StakeVerifier
-> NetworkId
-> Maybe OutputFile
-> ExceptT ShelleyAddressCmdError IO ()
runAddressBuild PaymentVerifier
paymentVerifier Maybe StakeVerifier
mbStakeVerifier NetworkId
nw Maybe OutputFile
mOutFp = do
  Text
outText <- case PaymentVerifier
paymentVerifier of
    PaymentVerifierKey VerificationKeyTextOrFile
payVkeyTextOrFile -> do
      SomeAddressVerificationKey
payVKey <- forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT VerificationKeyTextOrFileError -> ShelleyAddressCmdError
ShelleyAddressCmdVerificationKeyTextOrFileError forall a b. (a -> b) -> a -> b
$
         forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT forall a b. (a -> b) -> a -> b
$ VerificationKeyTextOrFile
-> IO
     (Either VerificationKeyTextOrFileError SomeAddressVerificationKey)
readVerificationKeyTextOrFileAnyOf VerificationKeyTextOrFile
payVkeyTextOrFile

      AddressAny
addr <- case SomeAddressVerificationKey
payVKey of
        AByronVerificationKey VerificationKey ByronKey
vk ->
          forall (m :: * -> *) a. Monad m => a -> m a
return (Address ByronAddr -> AddressAny
AddressByron (NetworkId -> VerificationKey ByronKey -> Address ByronAddr
makeByronAddress NetworkId
nw VerificationKey ByronKey
vk))

        APaymentVerificationKey VerificationKey PaymentKey
vk ->
          Address ShelleyAddr -> AddressAny
AddressShelley forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> VerificationKey PaymentKey
-> Maybe StakeVerifier
-> NetworkId
-> ExceptT ShelleyAddressCmdError IO (Address ShelleyAddr)
buildShelleyAddress VerificationKey PaymentKey
vk Maybe StakeVerifier
mbStakeVerifier NetworkId
nw

        APaymentExtendedVerificationKey VerificationKey PaymentExtendedKey
vk ->
          Address ShelleyAddr -> AddressAny
AddressShelley forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> VerificationKey PaymentKey
-> Maybe StakeVerifier
-> NetworkId
-> ExceptT ShelleyAddressCmdError IO (Address ShelleyAddr)
buildShelleyAddress (forall keyroleA keyroleB.
CastVerificationKeyRole keyroleA keyroleB =>
VerificationKey keyroleA -> VerificationKey keyroleB
castVerificationKey VerificationKey PaymentExtendedKey
vk) Maybe StakeVerifier
mbStakeVerifier NetworkId
nw

        AGenesisUTxOVerificationKey VerificationKey GenesisUTxOKey
vk ->
          Address ShelleyAddr -> AddressAny
AddressShelley forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> VerificationKey PaymentKey
-> Maybe StakeVerifier
-> NetworkId
-> ExceptT ShelleyAddressCmdError IO (Address ShelleyAddr)
buildShelleyAddress (forall keyroleA keyroleB.
CastVerificationKeyRole keyroleA keyroleB =>
VerificationKey keyroleA -> VerificationKey keyroleB
castVerificationKey VerificationKey GenesisUTxOKey
vk) Maybe StakeVerifier
mbStakeVerifier NetworkId
nw
        SomeAddressVerificationKey
nonPaymentKey ->
          forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left forall a b. (a -> b) -> a -> b
$ SomeAddressVerificationKey -> ShelleyAddressCmdError
ShelleyAddressCmdExpectedPaymentVerificationKey SomeAddressVerificationKey
nonPaymentKey
      forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall addr. SerialiseAddress addr => addr -> Text
serialiseAddress (AddressAny
addr :: AddressAny)

    PaymentVerifierScriptFile (ScriptFile String
fp) -> do
      ScriptInAnyLang ScriptLanguage lang
_lang Script lang
script <-
        forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError ScriptDecodeError -> ShelleyAddressCmdError
ShelleyAddressCmdReadScriptFileError forall a b. (a -> b) -> a -> b
$
          String -> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
readFileScriptInAnyLang String
fp

      let payCred :: PaymentCredential
payCred = ScriptHash -> PaymentCredential
PaymentCredentialByScript (forall lang. Script lang -> ScriptHash
hashScript Script lang
script)

      StakeAddressReference
stakeAddressReference <- forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return StakeAddressReference
NoStakeAddress) StakeVerifier
-> ExceptT ShelleyAddressCmdError IO StakeAddressReference
makeStakeAddressRef Maybe StakeVerifier
mbStakeVerifier

      forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall addr. SerialiseAddress addr => addr -> Text
serialiseAddress forall b c a. (b -> c) -> (a -> b) -> a -> c
. NetworkId
-> PaymentCredential
-> StakeAddressReference
-> Address ShelleyAddr
makeShelleyAddress NetworkId
nw PaymentCredential
payCred forall a b. (a -> b) -> a -> b
$ StakeAddressReference
stakeAddressReference

  case Maybe OutputFile
mOutFp of
    Just (OutputFile String
fpath) -> forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ String -> Text -> IO ()
Text.writeFile String
fpath Text
outText
    Maybe OutputFile
Nothing                 -> forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Text -> IO ()
Text.putStr          Text
outText

makeStakeAddressRef
  :: StakeVerifier
  -> ExceptT ShelleyAddressCmdError IO StakeAddressReference
makeStakeAddressRef :: StakeVerifier
-> ExceptT ShelleyAddressCmdError IO StakeAddressReference
makeStakeAddressRef StakeVerifier
stakeVerifier = case StakeVerifier
stakeVerifier of
      StakeVerifierKey VerificationKeyOrFile StakeKey
stkVkeyOrFile -> do
        VerificationKey StakeKey
stakeVKey <- forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError InputDecodeError -> ShelleyAddressCmdError
ShelleyAddressCmdReadKeyFileError forall a b. (a -> b) -> a -> b
$
          forall (m :: * -> *) x a. m (Either x a) -> ExceptT x m a
newExceptT forall a b. (a -> b) -> a -> b
$ forall keyrole.
(HasTextEnvelope (VerificationKey keyrole),
 SerialiseAsBech32 (VerificationKey keyrole)) =>
AsType keyrole
-> VerificationKeyOrFile keyrole
-> IO
     (Either (FileError InputDecodeError) (VerificationKey keyrole))
readVerificationKeyOrFile AsType StakeKey
AsStakeKey VerificationKeyOrFile StakeKey
stkVkeyOrFile

        forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. StakeCredential -> StakeAddressReference
StakeAddressByValue forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash StakeKey -> StakeCredential
StakeCredentialByKey forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall keyrole.
Key keyrole =>
VerificationKey keyrole -> Hash keyrole
verificationKeyHash forall a b. (a -> b) -> a -> b
$ VerificationKey StakeKey
stakeVKey

      StakeVerifierScriptFile (ScriptFile String
fp) -> do
        ScriptInAnyLang ScriptLanguage lang
_lang Script lang
script <-
          forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT FileError ScriptDecodeError -> ShelleyAddressCmdError
ShelleyAddressCmdReadScriptFileError forall a b. (a -> b) -> a -> b
$
            String -> ExceptT (FileError ScriptDecodeError) IO ScriptInAnyLang
readFileScriptInAnyLang String
fp

        let stakeCred :: StakeCredential
stakeCred = ScriptHash -> StakeCredential
StakeCredentialByScript (forall lang. Script lang -> ScriptHash
hashScript Script lang
script)
        forall (m :: * -> *) a. Monad m => a -> m a
return (StakeCredential -> StakeAddressReference
StakeAddressByValue StakeCredential
stakeCred)

      StakeVerifierAddress StakeAddress
stakeAddr ->
        forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ StakeCredential -> StakeAddressReference
StakeAddressByValue forall a b. (a -> b) -> a -> b
$ StakeAddress -> StakeCredential
stakeAddressCredential StakeAddress
stakeAddr

buildShelleyAddress
  :: VerificationKey PaymentKey
  -> Maybe StakeVerifier
  -> NetworkId
  -> ExceptT ShelleyAddressCmdError IO (Address ShelleyAddr)
buildShelleyAddress :: VerificationKey PaymentKey
-> Maybe StakeVerifier
-> NetworkId
-> ExceptT ShelleyAddressCmdError IO (Address ShelleyAddr)
buildShelleyAddress VerificationKey PaymentKey
vkey Maybe StakeVerifier
mbStakeVerifier NetworkId
nw =
  NetworkId
-> PaymentCredential
-> StakeAddressReference
-> Address ShelleyAddr
makeShelleyAddress NetworkId
nw (Hash PaymentKey -> PaymentCredential
PaymentCredentialByKey (forall keyrole.
Key keyrole =>
VerificationKey keyrole -> Hash keyrole
verificationKeyHash VerificationKey PaymentKey
vkey)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return StakeAddressReference
NoStakeAddress) StakeVerifier
-> ExceptT ShelleyAddressCmdError IO StakeAddressReference
makeStakeAddressRef Maybe StakeVerifier
mbStakeVerifier


--
-- Handling the variety of address key types
--


foldSomeAddressVerificationKey :: (forall keyrole. Key keyrole =>
                                   VerificationKey keyrole -> a)
                               -> SomeAddressVerificationKey -> a
foldSomeAddressVerificationKey :: forall a.
(forall keyrole. Key keyrole => VerificationKey keyrole -> a)
-> SomeAddressVerificationKey -> a
foldSomeAddressVerificationKey forall keyrole. Key keyrole => VerificationKey keyrole -> a
f (AByronVerificationKey           VerificationKey ByronKey
vk) = forall keyrole. Key keyrole => VerificationKey keyrole -> a
f VerificationKey ByronKey
vk
foldSomeAddressVerificationKey forall keyrole. Key keyrole => VerificationKey keyrole -> a
f (APaymentVerificationKey         VerificationKey PaymentKey
vk) = forall keyrole. Key keyrole => VerificationKey keyrole -> a
f VerificationKey PaymentKey
vk
foldSomeAddressVerificationKey forall keyrole. Key keyrole => VerificationKey keyrole -> a
f (APaymentExtendedVerificationKey VerificationKey PaymentExtendedKey
vk) = forall keyrole. Key keyrole => VerificationKey keyrole -> a
f VerificationKey PaymentExtendedKey
vk
foldSomeAddressVerificationKey forall keyrole. Key keyrole => VerificationKey keyrole -> a
f (AGenesisUTxOVerificationKey     VerificationKey GenesisUTxOKey
vk) = forall keyrole. Key keyrole => VerificationKey keyrole -> a
f VerificationKey GenesisUTxOKey
vk
foldSomeAddressVerificationKey forall keyrole. Key keyrole => VerificationKey keyrole -> a
f (AKesVerificationKey             VerificationKey KesKey
vk) = forall keyrole. Key keyrole => VerificationKey keyrole -> a
f VerificationKey KesKey
vk
foldSomeAddressVerificationKey forall keyrole. Key keyrole => VerificationKey keyrole -> a
f (AGenesisDelegateExtendedVerificationKey VerificationKey GenesisDelegateExtendedKey
vk) = forall keyrole. Key keyrole => VerificationKey keyrole -> a
f VerificationKey GenesisDelegateExtendedKey
vk
foldSomeAddressVerificationKey forall keyrole. Key keyrole => VerificationKey keyrole -> a
f (AGenesisExtendedVerificationKey VerificationKey GenesisExtendedKey
vk) = forall keyrole. Key keyrole => VerificationKey keyrole -> a
f VerificationKey GenesisExtendedKey
vk
foldSomeAddressVerificationKey forall keyrole. Key keyrole => VerificationKey keyrole -> a
f (AVrfVerificationKey             VerificationKey VrfKey
vk) = forall keyrole. Key keyrole => VerificationKey keyrole -> a
f VerificationKey VrfKey
vk
foldSomeAddressVerificationKey forall keyrole. Key keyrole => VerificationKey keyrole -> a
f (AStakeVerificationKey           VerificationKey StakeKey
vk) = forall keyrole. Key keyrole => VerificationKey keyrole -> a
f VerificationKey StakeKey
vk
foldSomeAddressVerificationKey forall keyrole. Key keyrole => VerificationKey keyrole -> a
f (AStakeExtendedVerificationKey   VerificationKey StakeExtendedKey
vk) = forall keyrole. Key keyrole => VerificationKey keyrole -> a
f VerificationKey StakeExtendedKey
vk