module Cardano.CLI.Byron.Run
  ( ByronClientCmdError
  , renderByronClientCmdError
  , runByronClientCommand
  ) where

import           Cardano.Prelude

import           Control.Monad.Trans.Except.Extra (firstExceptT, hoistEither)
import qualified Data.Text.Lazy.Builder as Builder
import qualified Data.Text.Lazy.IO as TL
import qualified Formatting as F

import qualified Cardano.Chain.Common as Common
import qualified Cardano.Chain.Delegation as Delegation
import qualified Cardano.Chain.Genesis as Genesis
import           Cardano.Chain.Slotting (EpochNumber)
import           Cardano.Chain.UTxO (TxIn, TxOut)

import qualified Cardano.Crypto.Hashing as Crypto
import qualified Cardano.Crypto.Signing as Crypto

import           Cardano.Api.Typed (NetworkId (..), toByronProtocolMagicId)
import qualified Cardano.Api.Typed as Typed

import           Cardano.CLI.Byron.Commands
import           Cardano.CLI.Byron.Delegation
import           Cardano.CLI.Byron.Genesis
import           Cardano.CLI.Byron.Key
import           Cardano.CLI.Byron.Query
import           Cardano.CLI.Byron.Tx
import           Cardano.CLI.Byron.UpdateProposal
import           Cardano.CLI.Byron.Vote

import           Cardano.CLI.Helpers
import           Cardano.CLI.Types

-- | Data type that encompasses all the possible errors of the
-- Byron client.
data ByronClientCmdError
  = ByronCmdDelegationError !ByronDelegationError
  | ByronCmdGenesisError !ByronGenesisError
  | ByronCmdHelpersError !HelpersError
  | ByronCmdKeyFailure !ByronKeyFailure
  | ByronCmdQueryError !ByronQueryError
  | ByronCmdTxError !ByronTxError
  | ByronCmdUpdateProposalError !ByronUpdateProposalError
  | ByronCmdVoteError !ByronVoteError
  deriving Int -> ByronClientCmdError -> ShowS
[ByronClientCmdError] -> ShowS
ByronClientCmdError -> String
(Int -> ByronClientCmdError -> ShowS)
-> (ByronClientCmdError -> String)
-> ([ByronClientCmdError] -> ShowS)
-> Show ByronClientCmdError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ByronClientCmdError] -> ShowS
$cshowList :: [ByronClientCmdError] -> ShowS
show :: ByronClientCmdError -> String
$cshow :: ByronClientCmdError -> String
showsPrec :: Int -> ByronClientCmdError -> ShowS
$cshowsPrec :: Int -> ByronClientCmdError -> ShowS
Show

renderByronClientCmdError :: ByronClientCmdError -> Text
renderByronClientCmdError :: ByronClientCmdError -> Text
renderByronClientCmdError ByronClientCmdError
err =
  case ByronClientCmdError
err of
    ByronCmdDelegationError ByronDelegationError
e -> ByronDelegationError -> Text
renderByronDelegationError ByronDelegationError
e
    ByronCmdGenesisError ByronGenesisError
e -> ByronGenesisError -> Text
renderByronGenesisError ByronGenesisError
e
    ByronCmdHelpersError HelpersError
e -> HelpersError -> Text
renderHelpersError HelpersError
e
    ByronCmdKeyFailure ByronKeyFailure
e -> ByronKeyFailure -> Text
renderByronKeyFailure ByronKeyFailure
e
    ByronCmdQueryError ByronQueryError
e -> ByronQueryError -> Text
renderByronQueryError ByronQueryError
e
    ByronCmdTxError ByronTxError
e -> ByronTxError -> Text
renderByronTxError ByronTxError
e
    ByronCmdUpdateProposalError ByronUpdateProposalError
e -> ByronUpdateProposalError -> Text
renderByronUpdateProposalError ByronUpdateProposalError
e
    ByronCmdVoteError ByronVoteError
e -> ByronVoteError -> Text
renderByronVoteError ByronVoteError
e

runByronClientCommand :: ByronCommand -> ExceptT ByronClientCmdError IO ()
runByronClientCommand :: ByronCommand -> ExceptT ByronClientCmdError IO ()
runByronClientCommand ByronCommand
c =
  case ByronCommand
c of
    NodeCmd NodeCmd
bc -> NodeCmd -> ExceptT ByronClientCmdError IO ()
runNodeCmd NodeCmd
bc
    Genesis NewDirectory
outDir GenesisParameters
params CardanoEra
era -> NewDirectory
-> GenesisParameters
-> CardanoEra
-> ExceptT ByronClientCmdError IO ()
runGenesisCommand NewDirectory
outDir GenesisParameters
params CardanoEra
era
    GetLocalNodeTip NetworkId
network -> (ByronQueryError -> ByronClientCmdError)
-> ExceptT ByronQueryError IO ()
-> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronQueryError -> ByronClientCmdError
ByronCmdQueryError (ExceptT ByronQueryError IO ()
 -> ExceptT ByronClientCmdError IO ())
-> ExceptT ByronQueryError IO ()
-> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ NetworkId -> ExceptT ByronQueryError IO ()
runGetLocalNodeTip NetworkId
network
    ValidateCBOR CBORObject
cborObject String
fp -> CBORObject -> String -> ExceptT ByronClientCmdError IO ()
runValidateCBOR CBORObject
cborObject String
fp
    PrettyPrintCBOR String
fp -> String -> ExceptT ByronClientCmdError IO ()
runPrettyPrintCBOR String
fp
    PrettySigningKeyPublic CardanoEra
era SigningKeyFile
skF -> CardanoEra -> SigningKeyFile -> ExceptT ByronClientCmdError IO ()
runPrettySigningKeyPublic CardanoEra
era SigningKeyFile
skF
    MigrateDelegateKeyFrom CardanoEra
oldEra SigningKeyFile
oldKey CardanoEra
newEra NewSigningKeyFile
nskf -> CardanoEra
-> SigningKeyFile
-> CardanoEra
-> NewSigningKeyFile
-> ExceptT ByronClientCmdError IO ()
runMigrateDelegateKeyFrom CardanoEra
oldEra SigningKeyFile
oldKey CardanoEra
newEra NewSigningKeyFile
nskf
    PrintGenesisHash GenesisFile
genFp -> GenesisFile -> ExceptT ByronClientCmdError IO ()
runPrintGenesisHash GenesisFile
genFp
    PrintSigningKeyAddress CardanoEra
era NetworkId
networkid SigningKeyFile
skF -> CardanoEra
-> NetworkId -> SigningKeyFile -> ExceptT ByronClientCmdError IO ()
runPrintSigningKeyAddress CardanoEra
era NetworkId
networkid SigningKeyFile
skF
    Keygen CardanoEra
era NewSigningKeyFile
nskf PasswordRequirement
passReq -> CardanoEra
-> NewSigningKeyFile
-> PasswordRequirement
-> ExceptT ByronClientCmdError IO ()
runKeygen CardanoEra
era NewSigningKeyFile
nskf PasswordRequirement
passReq
    ToVerification CardanoEra
era SigningKeyFile
skFp NewVerificationKeyFile
nvkFp -> CardanoEra
-> SigningKeyFile
-> NewVerificationKeyFile
-> ExceptT ByronClientCmdError IO ()
runToVerification CardanoEra
era SigningKeyFile
skFp NewVerificationKeyFile
nvkFp
    IssueDelegationCertificate NetworkId
nw CardanoEra
era EpochNumber
epoch SigningKeyFile
issuerSK VerificationKeyFile
delVK NewCertificateFile
cert ->
      NetworkId
-> CardanoEra
-> EpochNumber
-> SigningKeyFile
-> VerificationKeyFile
-> NewCertificateFile
-> ExceptT ByronClientCmdError IO ()
runIssueDelegationCertificate NetworkId
nw CardanoEra
era EpochNumber
epoch SigningKeyFile
issuerSK VerificationKeyFile
delVK NewCertificateFile
cert
    CheckDelegation NetworkId
nw CertificateFile
cert VerificationKeyFile
issuerVF VerificationKeyFile
delegateVF -> NetworkId
-> CertificateFile
-> VerificationKeyFile
-> VerificationKeyFile
-> ExceptT ByronClientCmdError IO ()
runCheckDelegation NetworkId
nw CertificateFile
cert VerificationKeyFile
issuerVF VerificationKeyFile
delegateVF
    SubmitTx NetworkId
network TxFile
fp -> NetworkId -> TxFile -> ExceptT ByronClientCmdError IO ()
runSubmitTx NetworkId
network TxFile
fp
    SpendGenesisUTxO GenesisFile
genFp NetworkId
nw CardanoEra
era NewTxFile
nftx SigningKeyFile
ctKey Address
genRichAddr NonEmpty TxOut
outs ->
      GenesisFile
-> NetworkId
-> CardanoEra
-> NewTxFile
-> SigningKeyFile
-> Address
-> NonEmpty TxOut
-> ExceptT ByronClientCmdError IO ()
runSpendGenesisUTxO GenesisFile
genFp NetworkId
nw CardanoEra
era NewTxFile
nftx SigningKeyFile
ctKey Address
genRichAddr NonEmpty TxOut
outs
    SpendUTxO NetworkId
nw CardanoEra
era NewTxFile
nftx SigningKeyFile
ctKey NonEmpty TxIn
ins NonEmpty TxOut
outs ->
      NetworkId
-> CardanoEra
-> NewTxFile
-> SigningKeyFile
-> NonEmpty TxIn
-> NonEmpty TxOut
-> ExceptT ByronClientCmdError IO ()
runSpendUTxO NetworkId
nw CardanoEra
era NewTxFile
nftx SigningKeyFile
ctKey NonEmpty TxIn
ins NonEmpty TxOut
outs


runNodeCmd :: NodeCmd -> ExceptT ByronClientCmdError IO ()
runNodeCmd :: NodeCmd -> ExceptT ByronClientCmdError IO ()
runNodeCmd (CreateVote NetworkId
nw SigningKeyFile
sKey String
upPropFp Bool
voteBool String
outputFp) =
  (ByronVoteError -> ByronClientCmdError)
-> ExceptT ByronVoteError IO ()
-> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronVoteError -> ByronClientCmdError
ByronCmdVoteError (ExceptT ByronVoteError IO () -> ExceptT ByronClientCmdError IO ())
-> ExceptT ByronVoteError IO ()
-> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ NetworkId
-> SigningKeyFile
-> String
-> Bool
-> String
-> ExceptT ByronVoteError IO ()
runVoteCreation NetworkId
nw SigningKeyFile
sKey String
upPropFp Bool
voteBool String
outputFp

runNodeCmd (SubmitUpdateProposal NetworkId
network String
proposalFp) =
    (ByronUpdateProposalError -> ByronClientCmdError)
-> ExceptT ByronUpdateProposalError IO ()
-> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronUpdateProposalError -> ByronClientCmdError
ByronCmdUpdateProposalError
      (ExceptT ByronUpdateProposalError IO ()
 -> ExceptT ByronClientCmdError IO ())
-> ExceptT ByronUpdateProposalError IO ()
-> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ NetworkId -> String -> ExceptT ByronUpdateProposalError IO ()
submitByronUpdateProposal NetworkId
network String
proposalFp

runNodeCmd (SubmitVote NetworkId
network String
voteFp) =
    (ByronVoteError -> ByronClientCmdError)
-> ExceptT ByronVoteError IO ()
-> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronVoteError -> ByronClientCmdError
ByronCmdVoteError (ExceptT ByronVoteError IO () -> ExceptT ByronClientCmdError IO ())
-> ExceptT ByronVoteError IO ()
-> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ NetworkId -> String -> ExceptT ByronVoteError IO ()
submitByronVote NetworkId
network String
voteFp

runNodeCmd (UpdateProposal NetworkId
nw SigningKeyFile
sKey ProtocolVersion
pVer SoftwareVersion
sVer SystemTag
sysTag InstallerHash
insHash String
outputFp [ParametersToUpdate]
params) =
  (ByronUpdateProposalError -> ByronClientCmdError)
-> ExceptT ByronUpdateProposalError IO ()
-> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronUpdateProposalError -> ByronClientCmdError
ByronCmdUpdateProposalError
    (ExceptT ByronUpdateProposalError IO ()
 -> ExceptT ByronClientCmdError IO ())
-> ExceptT ByronUpdateProposalError IO ()
-> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ NetworkId
-> SigningKeyFile
-> ProtocolVersion
-> SoftwareVersion
-> SystemTag
-> InstallerHash
-> String
-> [ParametersToUpdate]
-> ExceptT ByronUpdateProposalError IO ()
runProposalCreation NetworkId
nw SigningKeyFile
sKey ProtocolVersion
pVer SoftwareVersion
sVer SystemTag
sysTag InstallerHash
insHash String
outputFp [ParametersToUpdate]
params

runGenesisCommand :: NewDirectory -> GenesisParameters -> CardanoEra -> ExceptT ByronClientCmdError IO ()
runGenesisCommand :: NewDirectory
-> GenesisParameters
-> CardanoEra
-> ExceptT ByronClientCmdError IO ()
runGenesisCommand NewDirectory
outDir GenesisParameters
params CardanoEra
era = do
  (GenesisData
genData, GeneratedSecrets
genSecrets) <- (ByronGenesisError -> ByronClientCmdError)
-> ExceptT ByronGenesisError IO (GenesisData, GeneratedSecrets)
-> ExceptT ByronClientCmdError IO (GenesisData, GeneratedSecrets)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronGenesisError -> ByronClientCmdError
ByronCmdGenesisError (ExceptT ByronGenesisError IO (GenesisData, GeneratedSecrets)
 -> ExceptT ByronClientCmdError IO (GenesisData, GeneratedSecrets))
-> ExceptT ByronGenesisError IO (GenesisData, GeneratedSecrets)
-> ExceptT ByronClientCmdError IO (GenesisData, GeneratedSecrets)
forall a b. (a -> b) -> a -> b
$ GenesisParameters
-> ExceptT ByronGenesisError IO (GenesisData, GeneratedSecrets)
mkGenesis GenesisParameters
params
  (ByronGenesisError -> ByronClientCmdError)
-> ExceptT ByronGenesisError IO ()
-> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronGenesisError -> ByronClientCmdError
ByronCmdGenesisError (ExceptT ByronGenesisError IO ()
 -> ExceptT ByronClientCmdError IO ())
-> ExceptT ByronGenesisError IO ()
-> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ CardanoEra
-> NewDirectory
-> GenesisData
-> GeneratedSecrets
-> ExceptT ByronGenesisError IO ()
dumpGenesis CardanoEra
era NewDirectory
outDir GenesisData
genData GeneratedSecrets
genSecrets

runValidateCBOR :: CBORObject -> FilePath -> ExceptT ByronClientCmdError IO ()
runValidateCBOR :: CBORObject -> String -> ExceptT ByronClientCmdError IO ()
runValidateCBOR CBORObject
cborObject String
fp = do
  LByteString
bs <- (HelpersError -> ByronClientCmdError)
-> ExceptT HelpersError IO LByteString
-> ExceptT ByronClientCmdError IO LByteString
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT HelpersError -> ByronClientCmdError
ByronCmdHelpersError (ExceptT HelpersError IO LByteString
 -> ExceptT ByronClientCmdError IO LByteString)
-> ExceptT HelpersError IO LByteString
-> ExceptT ByronClientCmdError IO LByteString
forall a b. (a -> b) -> a -> b
$ String -> ExceptT HelpersError IO LByteString
readCBOR String
fp
  Text
res <- Either ByronClientCmdError Text
-> ExceptT ByronClientCmdError IO Text
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either ByronClientCmdError Text
 -> ExceptT ByronClientCmdError IO Text)
-> (Either HelpersError Text -> Either ByronClientCmdError Text)
-> Either HelpersError Text
-> ExceptT ByronClientCmdError IO Text
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (HelpersError -> ByronClientCmdError)
-> Either HelpersError Text -> Either ByronClientCmdError Text
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first HelpersError -> ByronClientCmdError
ByronCmdHelpersError (Either HelpersError Text -> ExceptT ByronClientCmdError IO Text)
-> Either HelpersError Text -> ExceptT ByronClientCmdError IO Text
forall a b. (a -> b) -> a -> b
$ CBORObject -> LByteString -> Either HelpersError Text
validateCBOR CBORObject
cborObject LByteString
bs
  IO () -> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT ByronClientCmdError IO ())
-> IO () -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ Text -> IO ()
putTextLn Text
res

runPrettyPrintCBOR :: FilePath -> ExceptT ByronClientCmdError IO ()
runPrettyPrintCBOR :: String -> ExceptT ByronClientCmdError IO ()
runPrettyPrintCBOR String
fp = do
  LByteString
bs <- (HelpersError -> ByronClientCmdError)
-> ExceptT HelpersError IO LByteString
-> ExceptT ByronClientCmdError IO LByteString
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT HelpersError -> ByronClientCmdError
ByronCmdHelpersError (ExceptT HelpersError IO LByteString
 -> ExceptT ByronClientCmdError IO LByteString)
-> ExceptT HelpersError IO LByteString
-> ExceptT ByronClientCmdError IO LByteString
forall a b. (a -> b) -> a -> b
$ String -> ExceptT HelpersError IO LByteString
readCBOR String
fp
  (HelpersError -> ByronClientCmdError)
-> ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT HelpersError -> ByronClientCmdError
ByronCmdHelpersError (ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ())
-> ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ LByteString -> ExceptT HelpersError IO ()
pPrintCBOR LByteString
bs

runPrettySigningKeyPublic :: CardanoEra -> SigningKeyFile -> ExceptT ByronClientCmdError IO ()
runPrettySigningKeyPublic :: CardanoEra -> SigningKeyFile -> ExceptT ByronClientCmdError IO ()
runPrettySigningKeyPublic CardanoEra
era SigningKeyFile
skF = do
  SigningKey
sK <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO SigningKey
-> ExceptT ByronClientCmdError IO SigningKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO SigningKey
 -> ExceptT ByronClientCmdError IO SigningKey)
-> ExceptT ByronKeyFailure IO SigningKey
-> ExceptT ByronClientCmdError IO SigningKey
forall a b. (a -> b) -> a -> b
$ CardanoEra
-> SigningKeyFile -> ExceptT ByronKeyFailure IO SigningKey
readEraSigningKey CardanoEra
era SigningKeyFile
skF
  IO () -> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT ByronClientCmdError IO ())
-> (VerificationKey -> IO ())
-> VerificationKey
-> ExceptT ByronClientCmdError IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Text -> IO ()
putTextLn (Text -> IO ())
-> (VerificationKey -> Text) -> VerificationKey -> IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. VerificationKey -> Text
prettyPublicKey (VerificationKey -> ExceptT ByronClientCmdError IO ())
-> VerificationKey -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ SigningKey -> VerificationKey
Crypto.toVerification SigningKey
sK

runMigrateDelegateKeyFrom
        :: CardanoEra -> SigningKeyFile -> CardanoEra -> NewSigningKeyFile
        -> ExceptT ByronClientCmdError IO ()
runMigrateDelegateKeyFrom :: CardanoEra
-> SigningKeyFile
-> CardanoEra
-> NewSigningKeyFile
-> ExceptT ByronClientCmdError IO ()
runMigrateDelegateKeyFrom CardanoEra
oldEra SigningKeyFile
oldKey CardanoEra
newEra (NewSigningKeyFile String
newKey) = do
  SigningKey
sk <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO SigningKey
-> ExceptT ByronClientCmdError IO SigningKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO SigningKey
 -> ExceptT ByronClientCmdError IO SigningKey)
-> ExceptT ByronKeyFailure IO SigningKey
-> ExceptT ByronClientCmdError IO SigningKey
forall a b. (a -> b) -> a -> b
$ CardanoEra
-> SigningKeyFile -> ExceptT ByronKeyFailure IO SigningKey
readEraSigningKey CardanoEra
oldEra SigningKeyFile
oldKey
  LByteString
sDk <- Either ByronClientCmdError LByteString
-> ExceptT ByronClientCmdError IO LByteString
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either ByronClientCmdError LByteString
 -> ExceptT ByronClientCmdError IO LByteString)
-> (Either ByronDelegationError LByteString
    -> Either ByronClientCmdError LByteString)
-> Either ByronDelegationError LByteString
-> ExceptT ByronClientCmdError IO LByteString
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (ByronDelegationError -> ByronClientCmdError)
-> Either ByronDelegationError LByteString
-> Either ByronClientCmdError LByteString
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ByronDelegationError -> ByronClientCmdError
ByronCmdDelegationError (Either ByronDelegationError LByteString
 -> ExceptT ByronClientCmdError IO LByteString)
-> Either ByronDelegationError LByteString
-> ExceptT ByronClientCmdError IO LByteString
forall a b. (a -> b) -> a -> b
$ CardanoEra -> SigningKey -> Either ByronDelegationError LByteString
serialiseDelegateKey CardanoEra
newEra SigningKey
sk
  (HelpersError -> ByronClientCmdError)
-> ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT HelpersError -> ByronClientCmdError
ByronCmdHelpersError (ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ())
-> ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ String -> LByteString -> ExceptT HelpersError IO ()
ensureNewFileLBS String
newKey LByteString
sDk

runPrintGenesisHash :: GenesisFile -> ExceptT ByronClientCmdError IO ()
runPrintGenesisHash :: GenesisFile -> ExceptT ByronClientCmdError IO ()
runPrintGenesisHash GenesisFile
genFp = do
    Config
genesis <- (ByronGenesisError -> ByronClientCmdError)
-> ExceptT ByronGenesisError IO Config
-> ExceptT ByronClientCmdError IO Config
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronGenesisError -> ByronClientCmdError
ByronCmdGenesisError (ExceptT ByronGenesisError IO Config
 -> ExceptT ByronClientCmdError IO Config)
-> ExceptT ByronGenesisError IO Config
-> ExceptT ByronClientCmdError IO Config
forall a b. (a -> b) -> a -> b
$
                 GenesisFile -> NetworkId -> ExceptT ByronGenesisError IO Config
readGenesis GenesisFile
genFp NetworkId
dummyNetwork
    IO () -> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT ByronClientCmdError IO ())
-> (Text -> IO ()) -> Text -> ExceptT ByronClientCmdError IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Text -> IO ()
putTextLn (Text -> ExceptT ByronClientCmdError IO ())
-> Text -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ Config -> Text
formatter Config
genesis
  where
    -- For this purpose of getting the hash, it does not matter what network
    -- value we use here.
    dummyNetwork :: NetworkId
    dummyNetwork :: NetworkId
dummyNetwork = NetworkId
Mainnet

    formatter :: Genesis.Config -> Text
    formatter :: Config -> Text
formatter = Format Text (AbstractHash Blake2b_256 Raw -> Text)
-> AbstractHash Blake2b_256 Raw -> Text
forall a. Format Text a -> a
F.sformat Format Text (AbstractHash Blake2b_256 Raw -> Text)
forall r algo a. Format r (AbstractHash algo a -> r)
Crypto.hashHexF
              (AbstractHash Blake2b_256 Raw -> Text)
-> (Config -> AbstractHash Blake2b_256 Raw) -> Config -> Text
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. GenesisHash -> AbstractHash Blake2b_256 Raw
Genesis.unGenesisHash
              (GenesisHash -> AbstractHash Blake2b_256 Raw)
-> (Config -> GenesisHash)
-> Config
-> AbstractHash Blake2b_256 Raw
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Config -> GenesisHash
Genesis.configGenesisHash

runPrintSigningKeyAddress :: CardanoEra -> NetworkId -> SigningKeyFile -> ExceptT ByronClientCmdError IO ()
runPrintSigningKeyAddress :: CardanoEra
-> NetworkId -> SigningKeyFile -> ExceptT ByronClientCmdError IO ()
runPrintSigningKeyAddress CardanoEra
era NetworkId
networkid SigningKeyFile
skF = do
  SigningKey
sK <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO SigningKey
-> ExceptT ByronClientCmdError IO SigningKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO SigningKey
 -> ExceptT ByronClientCmdError IO SigningKey)
-> ExceptT ByronKeyFailure IO SigningKey
-> ExceptT ByronClientCmdError IO SigningKey
forall a b. (a -> b) -> a -> b
$ CardanoEra
-> SigningKeyFile -> ExceptT ByronKeyFailure IO SigningKey
readEraSigningKey CardanoEra
era SigningKeyFile
skF
  let sKeyAddress :: Text
sKeyAddress = Address -> Text
prettyAddress
                  (Address -> Text) -> (SigningKey -> Address) -> SigningKey -> Text
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. NetworkMagic -> VerificationKey -> Address
Common.makeVerKeyAddress (NetworkId -> NetworkMagic
Typed.toByronNetworkMagic NetworkId
networkid)
                  (VerificationKey -> Address)
-> (SigningKey -> VerificationKey) -> SigningKey -> Address
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. SigningKey -> VerificationKey
Crypto.toVerification
                  (SigningKey -> Text) -> SigningKey -> Text
forall a b. (a -> b) -> a -> b
$ SigningKey
sK
  IO () -> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT ByronClientCmdError IO ())
-> IO () -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ Text -> IO ()
putTextLn Text
sKeyAddress

runKeygen :: CardanoEra -> NewSigningKeyFile -> PasswordRequirement -> ExceptT ByronClientCmdError IO ()
runKeygen :: CardanoEra
-> NewSigningKeyFile
-> PasswordRequirement
-> ExceptT ByronClientCmdError IO ()
runKeygen CardanoEra
era (NewSigningKeyFile String
skF) PasswordRequirement
passReq = do
  PassPhrase
pPhrase <- IO PassPhrase -> ExceptT ByronClientCmdError IO PassPhrase
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO PassPhrase -> ExceptT ByronClientCmdError IO PassPhrase)
-> IO PassPhrase -> ExceptT ByronClientCmdError IO PassPhrase
forall a b. (a -> b) -> a -> b
$ String -> PasswordRequirement -> IO PassPhrase
getPassphrase (String
"Enter password to encrypt '" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
skF String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"': ") PasswordRequirement
passReq
  SigningKey
sK <- IO SigningKey -> ExceptT ByronClientCmdError IO SigningKey
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO SigningKey -> ExceptT ByronClientCmdError IO SigningKey)
-> IO SigningKey -> ExceptT ByronClientCmdError IO SigningKey
forall a b. (a -> b) -> a -> b
$ PassPhrase -> IO SigningKey
keygen PassPhrase
pPhrase
  LByteString
serDk <- Either ByronClientCmdError LByteString
-> ExceptT ByronClientCmdError IO LByteString
forall (m :: * -> *) x a. Monad m => Either x a -> ExceptT x m a
hoistEither (Either ByronClientCmdError LByteString
 -> ExceptT ByronClientCmdError IO LByteString)
-> (Either ByronDelegationError LByteString
    -> Either ByronClientCmdError LByteString)
-> Either ByronDelegationError LByteString
-> ExceptT ByronClientCmdError IO LByteString
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (ByronDelegationError -> ByronClientCmdError)
-> Either ByronDelegationError LByteString
-> Either ByronClientCmdError LByteString
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ByronDelegationError -> ByronClientCmdError
ByronCmdDelegationError (Either ByronDelegationError LByteString
 -> ExceptT ByronClientCmdError IO LByteString)
-> Either ByronDelegationError LByteString
-> ExceptT ByronClientCmdError IO LByteString
forall a b. (a -> b) -> a -> b
$ CardanoEra -> SigningKey -> Either ByronDelegationError LByteString
serialiseDelegateKey CardanoEra
era SigningKey
sK
  (HelpersError -> ByronClientCmdError)
-> ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT HelpersError -> ByronClientCmdError
ByronCmdHelpersError (ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ())
-> ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ String -> LByteString -> ExceptT HelpersError IO ()
ensureNewFileLBS String
skF LByteString
serDk

runToVerification :: CardanoEra -> SigningKeyFile -> NewVerificationKeyFile -> ExceptT ByronClientCmdError IO ()
runToVerification :: CardanoEra
-> SigningKeyFile
-> NewVerificationKeyFile
-> ExceptT ByronClientCmdError IO ()
runToVerification CardanoEra
era SigningKeyFile
skFp (NewVerificationKeyFile String
vkFp) = do
  SigningKey
sk <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO SigningKey
-> ExceptT ByronClientCmdError IO SigningKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO SigningKey
 -> ExceptT ByronClientCmdError IO SigningKey)
-> ExceptT ByronKeyFailure IO SigningKey
-> ExceptT ByronClientCmdError IO SigningKey
forall a b. (a -> b) -> a -> b
$ CardanoEra
-> SigningKeyFile -> ExceptT ByronKeyFailure IO SigningKey
readEraSigningKey CardanoEra
era SigningKeyFile
skFp
  let vKey :: Text
vKey = Builder -> Text
Builder.toLazyText (Builder -> Text)
-> (VerificationKey -> Builder) -> VerificationKey -> Text
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. VerificationKey -> Builder
Crypto.formatFullVerificationKey (VerificationKey -> Text) -> VerificationKey -> Text
forall a b. (a -> b) -> a -> b
$ SigningKey -> VerificationKey
Crypto.toVerification SigningKey
sk
  (HelpersError -> ByronClientCmdError)
-> ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT HelpersError -> ByronClientCmdError
ByronCmdHelpersError (ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ())
-> ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ (String -> Text -> IO ())
-> String -> Text -> ExceptT HelpersError IO ()
forall a.
(String -> a -> IO ()) -> String -> a -> ExceptT HelpersError IO ()
ensureNewFile String -> Text -> IO ()
TL.writeFile String
vkFp Text
vKey

runIssueDelegationCertificate
  :: NetworkId
  -> CardanoEra
  -> EpochNumber
  -> SigningKeyFile
  -> VerificationKeyFile
  -> NewCertificateFile
  -> ExceptT ByronClientCmdError IO ()
runIssueDelegationCertificate :: NetworkId
-> CardanoEra
-> EpochNumber
-> SigningKeyFile
-> VerificationKeyFile
-> NewCertificateFile
-> ExceptT ByronClientCmdError IO ()
runIssueDelegationCertificate NetworkId
nw CardanoEra
era EpochNumber
epoch SigningKeyFile
issuerSK VerificationKeyFile
delegateVK NewCertificateFile
cert = do
  VerificationKey
vk <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO VerificationKey
-> ExceptT ByronClientCmdError IO VerificationKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO VerificationKey
 -> ExceptT ByronClientCmdError IO VerificationKey)
-> ExceptT ByronKeyFailure IO VerificationKey
-> ExceptT ByronClientCmdError IO VerificationKey
forall a b. (a -> b) -> a -> b
$ VerificationKeyFile -> ExceptT ByronKeyFailure IO VerificationKey
readPaymentVerificationKey VerificationKeyFile
delegateVK
  SigningKey
sk <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO SigningKey
-> ExceptT ByronClientCmdError IO SigningKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO SigningKey
 -> ExceptT ByronClientCmdError IO SigningKey)
-> ExceptT ByronKeyFailure IO SigningKey
-> ExceptT ByronClientCmdError IO SigningKey
forall a b. (a -> b) -> a -> b
$ CardanoEra
-> SigningKeyFile -> ExceptT ByronKeyFailure IO SigningKey
readEraSigningKey CardanoEra
era SigningKeyFile
issuerSK
  let byGenDelCert :: Delegation.Certificate
      byGenDelCert :: Certificate
byGenDelCert = ProtocolMagicId
-> EpochNumber -> SigningKey -> VerificationKey -> Certificate
issueByronGenesisDelegation (NetworkId -> ProtocolMagicId
toByronProtocolMagicId NetworkId
nw) EpochNumber
epoch SigningKey
sk VerificationKey
vk
      sCert :: LByteString
sCert        = Certificate -> LByteString
serialiseDelegationCert Certificate
byGenDelCert
  (HelpersError -> ByronClientCmdError)
-> ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT HelpersError -> ByronClientCmdError
ByronCmdHelpersError (ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ())
-> ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ String -> LByteString -> ExceptT HelpersError IO ()
ensureNewFileLBS (NewCertificateFile -> String
nFp NewCertificateFile
cert) LByteString
sCert


runCheckDelegation
  :: NetworkId
  -> CertificateFile
  -> VerificationKeyFile
  -> VerificationKeyFile
  -> ExceptT ByronClientCmdError IO ()
runCheckDelegation :: NetworkId
-> CertificateFile
-> VerificationKeyFile
-> VerificationKeyFile
-> ExceptT ByronClientCmdError IO ()
runCheckDelegation NetworkId
nw CertificateFile
cert VerificationKeyFile
issuerVF VerificationKeyFile
delegateVF = do
  VerificationKey
issuerVK <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO VerificationKey
-> ExceptT ByronClientCmdError IO VerificationKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO VerificationKey
 -> ExceptT ByronClientCmdError IO VerificationKey)
-> ExceptT ByronKeyFailure IO VerificationKey
-> ExceptT ByronClientCmdError IO VerificationKey
forall a b. (a -> b) -> a -> b
$ VerificationKeyFile -> ExceptT ByronKeyFailure IO VerificationKey
readPaymentVerificationKey VerificationKeyFile
issuerVF
  VerificationKey
delegateVK <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO VerificationKey
-> ExceptT ByronClientCmdError IO VerificationKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO VerificationKey
 -> ExceptT ByronClientCmdError IO VerificationKey)
-> ExceptT ByronKeyFailure IO VerificationKey
-> ExceptT ByronClientCmdError IO VerificationKey
forall a b. (a -> b) -> a -> b
$ VerificationKeyFile -> ExceptT ByronKeyFailure IO VerificationKey
readPaymentVerificationKey VerificationKeyFile
delegateVF
  (ByronDelegationError -> ByronClientCmdError)
-> ExceptT ByronDelegationError IO ()
-> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronDelegationError -> ByronClientCmdError
ByronCmdDelegationError (ExceptT ByronDelegationError IO ()
 -> ExceptT ByronClientCmdError IO ())
-> ExceptT ByronDelegationError IO ()
-> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$
    CertificateFile
-> ProtocolMagicId
-> VerificationKey
-> VerificationKey
-> ExceptT ByronDelegationError IO ()
checkByronGenesisDelegation CertificateFile
cert (NetworkId -> ProtocolMagicId
toByronProtocolMagicId NetworkId
nw)
                                VerificationKey
issuerVK VerificationKey
delegateVK

runSubmitTx :: NetworkId -> TxFile -> ExceptT ByronClientCmdError IO ()
runSubmitTx :: NetworkId -> TxFile -> ExceptT ByronClientCmdError IO ()
runSubmitTx NetworkId
network TxFile
fp = do
    GenTx ByronBlock
tx <- (ByronTxError -> ByronClientCmdError)
-> ExceptT ByronTxError IO (GenTx ByronBlock)
-> ExceptT ByronClientCmdError IO (GenTx ByronBlock)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronTxError -> ByronClientCmdError
ByronCmdTxError (ExceptT ByronTxError IO (GenTx ByronBlock)
 -> ExceptT ByronClientCmdError IO (GenTx ByronBlock))
-> ExceptT ByronTxError IO (GenTx ByronBlock)
-> ExceptT ByronClientCmdError IO (GenTx ByronBlock)
forall a b. (a -> b) -> a -> b
$ TxFile -> ExceptT ByronTxError IO (GenTx ByronBlock)
readByronTx TxFile
fp
    (ByronTxError -> ByronClientCmdError)
-> ExceptT ByronTxError IO () -> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronTxError -> ByronClientCmdError
ByronCmdTxError (ExceptT ByronTxError IO () -> ExceptT ByronClientCmdError IO ())
-> ExceptT ByronTxError IO () -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ NetworkId -> GenTx ByronBlock -> ExceptT ByronTxError IO ()
nodeSubmitTx NetworkId
network GenTx ByronBlock
tx


runSpendGenesisUTxO
  :: GenesisFile
  -> NetworkId
  -> CardanoEra
  -> NewTxFile
  -> SigningKeyFile
  -> Common.Address
  -> NonEmpty TxOut
  -> ExceptT ByronClientCmdError IO ()
runSpendGenesisUTxO :: GenesisFile
-> NetworkId
-> CardanoEra
-> NewTxFile
-> SigningKeyFile
-> Address
-> NonEmpty TxOut
-> ExceptT ByronClientCmdError IO ()
runSpendGenesisUTxO GenesisFile
genesisFile NetworkId
nw CardanoEra
era (NewTxFile String
ctTx) SigningKeyFile
ctKey Address
genRichAddr NonEmpty TxOut
outs = do
    Config
genesis <- (ByronGenesisError -> ByronClientCmdError)
-> ExceptT ByronGenesisError IO Config
-> ExceptT ByronClientCmdError IO Config
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronGenesisError -> ByronClientCmdError
ByronCmdGenesisError (ExceptT ByronGenesisError IO Config
 -> ExceptT ByronClientCmdError IO Config)
-> ExceptT ByronGenesisError IO Config
-> ExceptT ByronClientCmdError IO Config
forall a b. (a -> b) -> a -> b
$ GenesisFile -> NetworkId -> ExceptT ByronGenesisError IO Config
readGenesis GenesisFile
genesisFile NetworkId
nw
    SigningKey
sk <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO SigningKey
-> ExceptT ByronClientCmdError IO SigningKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO SigningKey
 -> ExceptT ByronClientCmdError IO SigningKey)
-> ExceptT ByronKeyFailure IO SigningKey
-> ExceptT ByronClientCmdError IO SigningKey
forall a b. (a -> b) -> a -> b
$ CardanoEra
-> SigningKeyFile -> ExceptT ByronKeyFailure IO SigningKey
readEraSigningKey CardanoEra
era SigningKeyFile
ctKey

    let tx :: ATxAux ByteString
tx = Config
-> NetworkId
-> SigningKey
-> Address
-> NonEmpty TxOut
-> ATxAux ByteString
txSpendGenesisUTxOByronPBFT Config
genesis NetworkId
nw SigningKey
sk Address
genRichAddr NonEmpty TxOut
outs
    (HelpersError -> ByronClientCmdError)
-> ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT HelpersError -> ByronClientCmdError
ByronCmdHelpersError (ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ())
-> ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ String -> LByteString -> ExceptT HelpersError IO ()
ensureNewFileLBS String
ctTx (LByteString -> ExceptT HelpersError IO ())
-> LByteString -> ExceptT HelpersError IO ()
forall a b. (a -> b) -> a -> b
$ ATxAux ByteString -> LByteString
toCborTxAux ATxAux ByteString
tx

runSpendUTxO
  :: NetworkId
  -> CardanoEra
  -> NewTxFile
  -> SigningKeyFile
  -> NonEmpty TxIn
  -> NonEmpty TxOut
  -> ExceptT ByronClientCmdError IO ()
runSpendUTxO :: NetworkId
-> CardanoEra
-> NewTxFile
-> SigningKeyFile
-> NonEmpty TxIn
-> NonEmpty TxOut
-> ExceptT ByronClientCmdError IO ()
runSpendUTxO NetworkId
nw CardanoEra
era (NewTxFile String
ctTx) SigningKeyFile
ctKey NonEmpty TxIn
ins NonEmpty TxOut
outs = do
    SigningKey
sk <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO SigningKey
-> ExceptT ByronClientCmdError IO SigningKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO SigningKey
 -> ExceptT ByronClientCmdError IO SigningKey)
-> ExceptT ByronKeyFailure IO SigningKey
-> ExceptT ByronClientCmdError IO SigningKey
forall a b. (a -> b) -> a -> b
$ CardanoEra
-> SigningKeyFile -> ExceptT ByronKeyFailure IO SigningKey
readEraSigningKey CardanoEra
era SigningKeyFile
ctKey

    let gTx :: ATxAux ByteString
gTx = NetworkId
-> SigningKey
-> NonEmpty TxIn
-> NonEmpty TxOut
-> ATxAux ByteString
txSpendUTxOByronPBFT NetworkId
nw SigningKey
sk NonEmpty TxIn
ins NonEmpty TxOut
outs
    (HelpersError -> ByronClientCmdError)
-> ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ()
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT HelpersError -> ByronClientCmdError
ByronCmdHelpersError (ExceptT HelpersError IO () -> ExceptT ByronClientCmdError IO ())
-> (LByteString -> ExceptT HelpersError IO ())
-> LByteString
-> ExceptT ByronClientCmdError IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. String -> LByteString -> ExceptT HelpersError IO ()
ensureNewFileLBS String
ctTx (LByteString -> ExceptT ByronClientCmdError IO ())
-> LByteString -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ ATxAux ByteString -> LByteString
toCborTxAux ATxAux ByteString
gTx