{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
module Cardano.CLI.Byron.Run
( ByronClientCmdError
, renderByronClientCmdError
, runByronClientCommand
)
where
import Cardano.Api hiding (GenesisParameters, UpdateProposal)
import Cardano.Api.Byron (SomeByronSigningKey (..), serializeByronTx)
import qualified Cardano.Api.Byron as Byron
import Cardano.CLI.Byron.Commands
import Cardano.CLI.Byron.Delegation
import Cardano.CLI.Byron.Genesis
import Cardano.CLI.Byron.Key
import Cardano.CLI.Byron.Tx
import Cardano.CLI.Byron.UpdateProposal
import Cardano.CLI.Byron.Vote
import Cardano.CLI.Helpers
import Cardano.CLI.Types.Common
import qualified Cardano.Crypto.Hashing as Crypto
import qualified Cardano.Crypto.Signing as Crypto
import Data.Bifunctor (Bifunctor (..))
import qualified Data.ByteString.Char8 as BS
import Data.Text (Text)
import qualified Data.Text.IO as Text
import qualified Data.Text.Lazy.Builder as Builder
import qualified Data.Text.Lazy.IO as TL
import qualified Formatting as F
data ByronClientCmdError
= ByronCmdDelegationError !ByronDelegationError
| ByronCmdGenesisError !ByronGenesisError
| ByronCmdHelpersError !HelpersError
| ByronCmdKeyFailure !ByronKeyFailure
| 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
$cshowsPrec :: Int -> ByronClientCmdError -> ShowS
showsPrec :: Int -> ByronClientCmdError -> ShowS
$cshow :: ByronClientCmdError -> String
show :: ByronClientCmdError -> String
$cshowList :: [ByronClientCmdError] -> ShowS
showList :: [ByronClientCmdError] -> ShowS
Show
renderByronClientCmdError :: ByronClientCmdError -> Doc ann
renderByronClientCmdError :: forall ann. ByronClientCmdError -> Doc ann
renderByronClientCmdError = \case
ByronCmdDelegationError ByronDelegationError
e -> ByronDelegationError -> Doc ann
forall ann. ByronDelegationError -> Doc ann
renderByronDelegationError ByronDelegationError
e
ByronCmdGenesisError ByronGenesisError
e -> ByronGenesisError -> Doc ann
forall ann. ByronGenesisError -> Doc ann
renderByronGenesisError ByronGenesisError
e
ByronCmdHelpersError HelpersError
e -> HelpersError -> Doc ann
forall ann. HelpersError -> Doc ann
renderHelpersError HelpersError
e
ByronCmdKeyFailure ByronKeyFailure
e -> ByronKeyFailure -> Doc ann
forall ann. ByronKeyFailure -> Doc ann
renderByronKeyFailure ByronKeyFailure
e
ByronCmdTxError ByronTxError
e -> ByronTxError -> Doc ann
forall ann. ByronTxError -> Doc ann
renderByronTxError ByronTxError
e
ByronCmdUpdateProposalError ByronUpdateProposalError
e -> ByronUpdateProposalError -> Doc ann
forall ann. ByronUpdateProposalError -> Doc ann
renderByronUpdateProposalError ByronUpdateProposalError
e
ByronCmdVoteError ByronVoteError
e -> ByronVoteError -> Doc ann
forall ann. ByronVoteError -> Doc ann
renderByronVoteError ByronVoteError
e
runByronClientCommand :: ByronCommand -> ExceptT ByronClientCmdError IO ()
runByronClientCommand :: ByronCommand -> ExceptT ByronClientCmdError IO ()
runByronClientCommand ByronCommand
c =
case ByronCommand
c of
NodeCmds NodeCmds
bc -> NodeCmds -> ExceptT ByronClientCmdError IO ()
runNodeCmds NodeCmds
bc
Genesis NewDirectory
outDir GenesisParameters
params -> NewDirectory
-> GenesisParameters -> ExceptT ByronClientCmdError IO ()
runGenesisCommand NewDirectory
outDir GenesisParameters
params
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 ByronKeyFormat
bKeyFormat SigningKeyFile 'In
skF -> ByronKeyFormat
-> SigningKeyFile 'In -> ExceptT ByronClientCmdError IO ()
runPrettySigningKeyPublic ByronKeyFormat
bKeyFormat SigningKeyFile 'In
skF
MigrateDelegateKeyFrom SigningKeyFile 'In
oldKey NewSigningKeyFile
nskf ->
SigningKeyFile 'In
-> NewSigningKeyFile -> ExceptT ByronClientCmdError IO ()
runMigrateDelegateKeyFrom SigningKeyFile 'In
oldKey NewSigningKeyFile
nskf
PrintGenesisHash GenesisFile
genFp -> GenesisFile -> ExceptT ByronClientCmdError IO ()
runPrintGenesisHash GenesisFile
genFp
PrintSigningKeyAddress ByronKeyFormat
bKeyFormat NetworkId
networkid SigningKeyFile 'In
skF -> ByronKeyFormat
-> NetworkId
-> SigningKeyFile 'In
-> ExceptT ByronClientCmdError IO ()
runPrintSigningKeyAddress ByronKeyFormat
bKeyFormat NetworkId
networkid SigningKeyFile 'In
skF
Keygen NewSigningKeyFile
nskf -> NewSigningKeyFile -> ExceptT ByronClientCmdError IO ()
runKeygen NewSigningKeyFile
nskf
ToVerification ByronKeyFormat
bKeyFormat SigningKeyFile 'In
skFp NewVerificationKeyFile
nvkFp -> ByronKeyFormat
-> SigningKeyFile 'In
-> NewVerificationKeyFile
-> ExceptT ByronClientCmdError IO ()
runToVerification ByronKeyFormat
bKeyFormat SigningKeyFile 'In
skFp NewVerificationKeyFile
nvkFp
SubmitTx SocketPath
socketPath NetworkId
network TxFile 'In
fp -> SocketPath
-> NetworkId -> TxFile 'In -> ExceptT ByronClientCmdError IO ()
runSubmitTx SocketPath
socketPath NetworkId
network TxFile 'In
fp
GetTxId TxFile 'In
fp -> TxFile 'In -> ExceptT ByronClientCmdError IO ()
runGetTxId TxFile 'In
fp
SpendGenesisUTxO GenesisFile
genFp NetworkId
nw ByronKeyFormat
era NewTxFile
nftx SigningKeyFile 'In
ctKey Address ByronAddr
genRichAddr [TxOut CtxTx ByronEra]
outs ->
GenesisFile
-> NetworkId
-> ByronKeyFormat
-> NewTxFile
-> SigningKeyFile 'In
-> Address ByronAddr
-> [TxOut CtxTx ByronEra]
-> ExceptT ByronClientCmdError IO ()
runSpendGenesisUTxO GenesisFile
genFp NetworkId
nw ByronKeyFormat
era NewTxFile
nftx SigningKeyFile 'In
ctKey Address ByronAddr
genRichAddr [TxOut CtxTx ByronEra]
outs
SpendUTxO NetworkId
nw ByronKeyFormat
era NewTxFile
nftx SigningKeyFile 'In
ctKey [TxIn]
ins [TxOut CtxTx ByronEra]
outs ->
NetworkId
-> ByronKeyFormat
-> NewTxFile
-> SigningKeyFile 'In
-> [TxIn]
-> [TxOut CtxTx ByronEra]
-> ExceptT ByronClientCmdError IO ()
runSpendUTxO NetworkId
nw ByronKeyFormat
era NewTxFile
nftx SigningKeyFile 'In
ctKey [TxIn]
ins [TxOut CtxTx ByronEra]
outs
runNodeCmds :: NodeCmds -> ExceptT ByronClientCmdError IO ()
runNodeCmds :: NodeCmds -> ExceptT ByronClientCmdError IO ()
runNodeCmds (CreateVote NetworkId
nw SigningKeyFile 'In
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 'In
-> String
-> Bool
-> String
-> ExceptT ByronVoteError IO ()
runVoteCreation NetworkId
nw SigningKeyFile 'In
sKey String
upPropFp Bool
voteBool String
outputFp
runNodeCmds (SubmitUpdateProposal SocketPath
nodeSocketPath NetworkId
network String
proposalFp) = do
(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
$
SocketPath
-> NetworkId -> String -> ExceptT ByronUpdateProposalError IO ()
submitByronUpdateProposal SocketPath
nodeSocketPath NetworkId
network String
proposalFp
runNodeCmds (SubmitVote SocketPath
nodeSocketPath NetworkId
network String
voteFp) = do
(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
$ SocketPath -> NetworkId -> String -> ExceptT ByronVoteError IO ()
submitByronVote SocketPath
nodeSocketPath NetworkId
network String
voteFp
runNodeCmds (UpdateProposal NetworkId
nw SigningKeyFile 'In
sKey ProtocolVersion
pVer SoftwareVersion
sVer SystemTag
sysTag InstallerHash
insHash String
outputFp ByronProtocolParametersUpdate
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 'In
-> ProtocolVersion
-> SoftwareVersion
-> SystemTag
-> InstallerHash
-> String
-> ByronProtocolParametersUpdate
-> ExceptT ByronUpdateProposalError IO ()
runProposalCreation NetworkId
nw SigningKeyFile 'In
sKey ProtocolVersion
pVer SoftwareVersion
sVer SystemTag
sysTag InstallerHash
insHash String
outputFp ByronProtocolParametersUpdate
params
runGenesisCommand :: NewDirectory -> GenesisParameters -> ExceptT ByronClientCmdError IO ()
runGenesisCommand :: NewDirectory
-> GenesisParameters -> ExceptT ByronClientCmdError IO ()
runGenesisCommand NewDirectory
outDir GenesisParameters
params = 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
$ NewDirectory
-> GenesisData
-> GeneratedSecrets
-> ExceptT ByronGenesisError IO ()
dumpGenesis NewDirectory
outDir GenesisData
genData GeneratedSecrets
genSecrets
runValidateCBOR :: CBORObject -> FilePath -> ExceptT ByronClientCmdError IO ()
runValidateCBOR :: CBORObject -> String -> ExceptT ByronClientCmdError IO ()
runValidateCBOR CBORObject
cborObject String
fp = do
ByteString
bs <- (HelpersError -> ByronClientCmdError)
-> ExceptT HelpersError IO ByteString
-> ExceptT ByronClientCmdError IO ByteString
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT HelpersError -> ByronClientCmdError
ByronCmdHelpersError (ExceptT HelpersError IO ByteString
-> ExceptT ByronClientCmdError IO ByteString)
-> ExceptT HelpersError IO ByteString
-> ExceptT ByronClientCmdError IO ByteString
forall a b. (a -> b) -> a -> b
$ String -> ExceptT HelpersError IO ByteString
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 b c a. (b -> c) -> (a -> b) -> a -> c
. (HelpersError -> ByronClientCmdError)
-> Either HelpersError Text -> Either ByronClientCmdError Text
forall a b c. (a -> b) -> Either a c -> Either b c
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 -> ByteString -> Either HelpersError Text
validateCBOR CBORObject
cborObject ByteString
bs
IO () -> ExceptT ByronClientCmdError IO ()
forall a. IO a -> ExceptT ByronClientCmdError IO a
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 ()
Text.putStrLn Text
res
runPrettyPrintCBOR :: FilePath -> ExceptT ByronClientCmdError IO ()
runPrettyPrintCBOR :: String -> ExceptT ByronClientCmdError IO ()
runPrettyPrintCBOR String
fp = do
ByteString
bs <- (HelpersError -> ByronClientCmdError)
-> ExceptT HelpersError IO ByteString
-> ExceptT ByronClientCmdError IO ByteString
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT HelpersError -> ByronClientCmdError
ByronCmdHelpersError (ExceptT HelpersError IO ByteString
-> ExceptT ByronClientCmdError IO ByteString)
-> ExceptT HelpersError IO ByteString
-> ExceptT ByronClientCmdError IO ByteString
forall a b. (a -> b) -> a -> b
$ String -> ExceptT HelpersError IO ByteString
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
$ ByteString -> ExceptT HelpersError IO ()
pPrintCBOR ByteString
bs
runPrettySigningKeyPublic
:: ByronKeyFormat -> SigningKeyFile In -> ExceptT ByronClientCmdError IO ()
runPrettySigningKeyPublic :: ByronKeyFormat
-> SigningKeyFile 'In -> ExceptT ByronClientCmdError IO ()
runPrettySigningKeyPublic ByronKeyFormat
bKeyFormat SigningKeyFile 'In
skF = do
SomeByronSigningKey
sK <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey)
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall a b. (a -> b) -> a -> b
$ ByronKeyFormat
-> SigningKeyFile 'In
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
readByronSigningKey ByronKeyFormat
bKeyFormat SigningKeyFile 'In
skF
IO () -> ExceptT ByronClientCmdError IO ()
forall a. IO a -> ExceptT ByronClientCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT ByronClientCmdError IO ())
-> (VerificationKey ByronKey -> IO ())
-> VerificationKey ByronKey
-> ExceptT ByronClientCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> IO ()
Text.putStrLn (Text -> IO ())
-> (VerificationKey ByronKey -> Text)
-> VerificationKey ByronKey
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VerificationKey ByronKey -> Text
prettyPublicKey (VerificationKey ByronKey -> ExceptT ByronClientCmdError IO ())
-> VerificationKey ByronKey -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ SomeByronSigningKey -> VerificationKey ByronKey
byronWitnessToVerKey SomeByronSigningKey
sK
runMigrateDelegateKeyFrom
:: SigningKeyFile In
-> NewSigningKeyFile
-> ExceptT ByronClientCmdError IO ()
runMigrateDelegateKeyFrom :: SigningKeyFile 'In
-> NewSigningKeyFile -> ExceptT ByronClientCmdError IO ()
runMigrateDelegateKeyFrom oldKey :: SigningKeyFile 'In
oldKey@(File String
fp) (NewSigningKeyFile String
newKey) = do
SomeByronSigningKey
sk <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey)
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall a b. (a -> b) -> a -> b
$ ByronKeyFormat
-> SigningKeyFile 'In
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
readByronSigningKey ByronKeyFormat
LegacyByronKeyFormat SigningKeyFile 'In
oldKey
SomeByronSigningKey
migratedWitness <- case SomeByronSigningKey
sk of
AByronSigningKeyLegacy (ByronSigningKeyLegacy SigningKey
sKey) ->
SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall a. a -> ExceptT ByronClientCmdError IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey)
-> (SigningKey ByronKey -> SomeByronSigningKey)
-> SigningKey ByronKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SigningKey ByronKey -> SomeByronSigningKey
AByronSigningKey (SigningKey ByronKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey)
-> SigningKey ByronKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall a b. (a -> b) -> a -> b
$ SigningKey -> SigningKey ByronKey
ByronSigningKey SigningKey
sKey
AByronSigningKey SigningKey ByronKey
_ ->
ByronClientCmdError
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall (m :: * -> *) x a. Monad m => x -> ExceptT x m a
left (ByronClientCmdError
-> ExceptT ByronClientCmdError IO SomeByronSigningKey)
-> (ByronKeyFailure -> ByronClientCmdError)
-> ByronKeyFailure
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ByronKeyFailure
-> ExceptT ByronClientCmdError IO SomeByronSigningKey)
-> ByronKeyFailure
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall a b. (a -> b) -> a -> b
$ String -> ByronKeyFailure
CannotMigrateFromNonLegacySigningKey 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 ())
-> (ByteString -> ExceptT HelpersError IO ())
-> ByteString
-> ExceptT ByronClientCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString -> ExceptT HelpersError IO ()
ensureNewFileLBS String
newKey (ByteString -> ExceptT ByronClientCmdError IO ())
-> ByteString -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ SomeByronSigningKey -> ByteString
serialiseByronWitness SomeByronSigningKey
migratedWitness
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 a. IO a -> ExceptT ByronClientCmdError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT ByronClientCmdError IO ())
-> (Text -> IO ()) -> Text -> ExceptT ByronClientCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> IO ()
Text.putStrLn (Text -> ExceptT ByronClientCmdError IO ())
-> Text -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ Config -> Text
formatter Config
genesis
where
dummyNetwork :: NetworkId
dummyNetwork :: NetworkId
dummyNetwork = NetworkId
Mainnet
formatter :: Byron.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 b c a. (b -> c) -> (a -> b) -> a -> c
. GenesisHash -> AbstractHash Blake2b_256 Raw
Byron.unGenesisHash
(GenesisHash -> AbstractHash Blake2b_256 Raw)
-> (Config -> GenesisHash)
-> Config
-> AbstractHash Blake2b_256 Raw
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Config -> GenesisHash
Byron.configGenesisHash
runPrintSigningKeyAddress
:: ByronKeyFormat
-> NetworkId
-> SigningKeyFile In
-> ExceptT ByronClientCmdError IO ()
runPrintSigningKeyAddress :: ByronKeyFormat
-> NetworkId
-> SigningKeyFile 'In
-> ExceptT ByronClientCmdError IO ()
runPrintSigningKeyAddress ByronKeyFormat
bKeyFormat NetworkId
networkid SigningKeyFile 'In
skF = do
SomeByronSigningKey
sK <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey)
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall a b. (a -> b) -> a -> b
$ ByronKeyFormat
-> SigningKeyFile 'In
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
readByronSigningKey ByronKeyFormat
bKeyFormat SigningKeyFile 'In
skF
let sKeyAddr :: Text
sKeyAddr = Address ByronAddr -> Text
prettyAddress (Address ByronAddr -> Text)
-> (VerificationKey ByronKey -> Address ByronAddr)
-> VerificationKey ByronKey
-> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NetworkId -> VerificationKey ByronKey -> Address ByronAddr
makeByronAddress NetworkId
networkid (VerificationKey ByronKey -> Text)
-> VerificationKey ByronKey -> Text
forall a b. (a -> b) -> a -> b
$ SomeByronSigningKey -> VerificationKey ByronKey
byronWitnessToVerKey SomeByronSigningKey
sK
IO () -> ExceptT ByronClientCmdError IO ()
forall a. IO a -> ExceptT ByronClientCmdError IO a
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 ()
Text.putStrLn Text
sKeyAddr
runKeygen :: NewSigningKeyFile -> ExceptT ByronClientCmdError IO ()
runKeygen :: NewSigningKeyFile -> ExceptT ByronClientCmdError IO ()
runKeygen (NewSigningKeyFile String
skF) = do
SigningKey ByronKey
sK <- AsType ByronKey
-> ExceptT ByronClientCmdError IO (SigningKey ByronKey)
forall (m :: * -> *) keyrole.
(MonadIO m, Key keyrole) =>
AsType keyrole -> m (SigningKey keyrole)
generateSigningKey AsType ByronKey
AsByronKey
(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 ())
-> (ByteString -> ExceptT HelpersError IO ())
-> ByteString
-> ExceptT ByronClientCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString -> ExceptT HelpersError IO ()
ensureNewFileLBS String
skF (ByteString -> ExceptT ByronClientCmdError IO ())
-> ByteString -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$ SigningKey ByronKey -> ByteString
forall a. SerialiseAsRawBytes a => a -> ByteString
serialiseToRawBytes SigningKey ByronKey
sK
runToVerification
:: ByronKeyFormat -> SigningKeyFile In -> NewVerificationKeyFile -> ExceptT ByronClientCmdError IO ()
runToVerification :: ByronKeyFormat
-> SigningKeyFile 'In
-> NewVerificationKeyFile
-> ExceptT ByronClientCmdError IO ()
runToVerification ByronKeyFormat
bKeyFormat SigningKeyFile 'In
skFp (NewVerificationKeyFile String
vkFp) = do
SomeByronSigningKey
sk <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey)
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall a b. (a -> b) -> a -> b
$ ByronKeyFormat
-> SigningKeyFile 'In
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
readByronSigningKey ByronKeyFormat
bKeyFormat SigningKeyFile 'In
skFp
let ByronVerificationKey VerificationKey
vK = SomeByronSigningKey -> VerificationKey ByronKey
byronWitnessToVerKey SomeByronSigningKey
sk
let vKey :: Text
vKey = Builder -> Text
Builder.toLazyText (Builder -> Text) -> Builder -> Text
forall a b. (a -> b) -> a -> b
$ VerificationKey -> Builder
Crypto.formatFullVerificationKey VerificationKey
vK
(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
runSubmitTx :: SocketPath -> NetworkId -> TxFile In -> ExceptT ByronClientCmdError IO ()
runSubmitTx :: SocketPath
-> NetworkId -> TxFile 'In -> ExceptT ByronClientCmdError IO ()
runSubmitTx SocketPath
nodeSocketPath NetworkId
network TxFile 'In
fp = do
ATxAux ByteString
tx <- (ByronTxError -> ByronClientCmdError)
-> ExceptT ByronTxError IO (ATxAux ByteString)
-> ExceptT ByronClientCmdError IO (ATxAux ByteString)
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronTxError -> ByronClientCmdError
ByronCmdTxError (ExceptT ByronTxError IO (ATxAux ByteString)
-> ExceptT ByronClientCmdError IO (ATxAux ByteString))
-> ExceptT ByronTxError IO (ATxAux ByteString)
-> ExceptT ByronClientCmdError IO (ATxAux ByteString)
forall a b. (a -> b) -> a -> b
$ TxFile 'In -> ExceptT ByronTxError IO (ATxAux ByteString)
readByronTx TxFile 'In
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
$
SocketPath
-> NetworkId -> GenTx ByronBlock -> ExceptT ByronTxError IO ()
nodeSubmitTx SocketPath
nodeSocketPath NetworkId
network (ATxAux ByteString -> GenTx ByronBlock
normalByronTxToGenTx ATxAux ByteString
tx)
runGetTxId :: TxFile In -> ExceptT ByronClientCmdError IO ()
runGetTxId :: TxFile 'In -> ExceptT ByronClientCmdError IO ()
runGetTxId TxFile 'In
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
$ do
ATxAux ByteString
tx <- TxFile 'In -> ExceptT ByronTxError IO (ATxAux ByteString)
readByronTx TxFile 'In
fp
let txId :: TxId
txId = ATxAux ByteString -> TxId
getTxIdByron ATxAux ByteString
tx
IO () -> ExceptT ByronTxError IO ()
forall a. IO a -> ExceptT ByronTxError IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ExceptT ByronTxError IO ())
-> (ByteString -> IO ())
-> ByteString
-> ExceptT ByronTxError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> IO ()
BS.putStrLn (ByteString -> ExceptT ByronTxError IO ())
-> ByteString -> ExceptT ByronTxError IO ()
forall a b. (a -> b) -> a -> b
$ TxId -> ByteString
forall a. SerialiseAsRawBytes a => a -> ByteString
serialiseToRawBytesHex TxId
txId
runSpendGenesisUTxO
:: GenesisFile
-> NetworkId
-> ByronKeyFormat
-> NewTxFile
-> SigningKeyFile In
-> Address ByronAddr
-> [TxOut CtxTx ByronEra]
-> ExceptT ByronClientCmdError IO ()
runSpendGenesisUTxO :: GenesisFile
-> NetworkId
-> ByronKeyFormat
-> NewTxFile
-> SigningKeyFile 'In
-> Address ByronAddr
-> [TxOut CtxTx ByronEra]
-> ExceptT ByronClientCmdError IO ()
runSpendGenesisUTxO GenesisFile
genesisFile NetworkId
nw ByronKeyFormat
bKeyFormat (NewTxFile String
ctTx) SigningKeyFile 'In
ctKey Address ByronAddr
genRichAddr [TxOut CtxTx ByronEra]
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
SomeByronSigningKey
sk <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey)
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall a b. (a -> b) -> a -> b
$ ByronKeyFormat
-> SigningKeyFile 'In
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
readByronSigningKey ByronKeyFormat
bKeyFormat SigningKeyFile 'In
ctKey
let tx :: ATxAux ByteString
tx = Config
-> NetworkId
-> SomeByronSigningKey
-> Address ByronAddr
-> [TxOut CtxTx ByronEra]
-> ATxAux ByteString
txSpendGenesisUTxOByronPBFT Config
genesis NetworkId
nw SomeByronSigningKey
sk Address ByronAddr
genRichAddr [TxOut CtxTx ByronEra]
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 ())
-> (ByteString -> ExceptT HelpersError IO ())
-> ByteString
-> ExceptT ByronClientCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString -> ExceptT HelpersError IO ()
ensureNewFileLBS String
ctTx (ByteString -> ExceptT ByronClientCmdError IO ())
-> ByteString -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$
TextEnvelope -> ByteString
teRawCBOR (TextEnvelope -> ByteString) -> TextEnvelope -> ByteString
forall a b. (a -> b) -> a -> b
$
ATxAux ByteString -> TextEnvelope
serializeByronTx ATxAux ByteString
tx
runSpendUTxO
:: NetworkId
-> ByronKeyFormat
-> NewTxFile
-> SigningKeyFile In
-> [TxIn]
-> [TxOut CtxTx ByronEra]
-> ExceptT ByronClientCmdError IO ()
runSpendUTxO :: NetworkId
-> ByronKeyFormat
-> NewTxFile
-> SigningKeyFile 'In
-> [TxIn]
-> [TxOut CtxTx ByronEra]
-> ExceptT ByronClientCmdError IO ()
runSpendUTxO NetworkId
nw ByronKeyFormat
bKeyFormat (NewTxFile String
ctTx) SigningKeyFile 'In
ctKey [TxIn]
ins [TxOut CtxTx ByronEra]
outs = do
SomeByronSigningKey
sk <- (ByronKeyFailure -> ByronClientCmdError)
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall (m :: * -> *) x y a.
Functor m =>
(x -> y) -> ExceptT x m a -> ExceptT y m a
firstExceptT ByronKeyFailure -> ByronClientCmdError
ByronCmdKeyFailure (ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey)
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
-> ExceptT ByronClientCmdError IO SomeByronSigningKey
forall a b. (a -> b) -> a -> b
$ ByronKeyFormat
-> SigningKeyFile 'In
-> ExceptT ByronKeyFailure IO SomeByronSigningKey
readByronSigningKey ByronKeyFormat
bKeyFormat SigningKeyFile 'In
ctKey
let gTx :: ATxAux ByteString
gTx = NetworkId
-> SomeByronSigningKey
-> [TxIn]
-> [TxOut CtxTx ByronEra]
-> ATxAux ByteString
txSpendUTxOByronPBFT NetworkId
nw SomeByronSigningKey
sk [TxIn]
ins [TxOut CtxTx ByronEra]
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 ())
-> (ByteString -> ExceptT HelpersError IO ())
-> ByteString
-> ExceptT ByronClientCmdError IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString -> ExceptT HelpersError IO ()
ensureNewFileLBS String
ctTx (ByteString -> ExceptT ByronClientCmdError IO ())
-> ByteString -> ExceptT ByronClientCmdError IO ()
forall a b. (a -> b) -> a -> b
$
TextEnvelope -> ByteString
teRawCBOR (TextEnvelope -> ByteString) -> TextEnvelope -> ByteString
forall a b. (a -> b) -> a -> b
$
ATxAux ByteString -> TextEnvelope
serializeByronTx ATxAux ByteString
gTx