-- | This tool synthesizes a valid ChainDB, replicating cardano-node's UX
--
-- Usage: db-synthesizer --config FILE --db PATH
--                       [--shelley-operational-certificate FILE]
--                       [--shelley-vrf-key FILE] [--shelley-kes-key FILE]
--                       [--bulk-credentials-file FILE]
--                       ((-s|--slots NUMBER) | (-b|--blocks NUMBER) |
--                         (-e|--epochs NUMBER)) [-f | -a]
--
-- Available options:
--   --config FILE            Path to the node's config.json
--   --db PATH                Path to the Chain DB
--   --shelley-operational-certificate FILE
--                            Path to the delegation certificate
--   --shelley-vrf-key FILE   Path to the VRF signing key
--   --shelley-kes-key FILE   Path to the KES signing key
--   --bulk-credentials-file FILE
--                            Path to the bulk credentials file
--   -s,--slots NUMBER        Amount of slots to process
--   -b,--blocks NUMBER       Amount of blocks to forge
--   -e,--epochs NUMBER       Amount of epochs to process
--   -f                       Force overwrite an existing Chain DB
--   -a                       Append to an existing Chain DB
module Main (main) where

import           Cardano.Crypto.Init (cryptoInit)
import           Cardano.Tools.DBSynthesizer.Run
import           DBSynthesizer.Parsers
import           Main.Utf8 (withStdTerminalHandles)
import           System.Exit


main :: IO ()
IO ()
main = IO () -> IO ()
forall (m :: * -> *) r. (MonadIO m, MonadMask m) => m r -> m r
withStdTerminalHandles (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
    IO ()
cryptoInit
    (NodeFilePaths
paths, NodeCredentials
creds, DBSynthesizerOptions
forgeOpts) <- IO (NodeFilePaths, NodeCredentials, DBSynthesizerOptions)
parseCommandLine
    let
      genTxs :: p -> p -> p -> f [a]
genTxs p
_ p
_ p
_ = [a] -> f [a]
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
    ForgeResult
result <- NodeFilePaths
-> NodeCredentials
-> DBSynthesizerOptions
-> IO
     (Either
        String (DBSynthesizerConfig, CardanoProtocolParams StandardCrypto))
initialize NodeFilePaths
paths NodeCredentials
creds DBSynthesizerOptions
forgeOpts IO
  (Either
     String (DBSynthesizerConfig, CardanoProtocolParams StandardCrypto))
-> (Either
      String (DBSynthesizerConfig, CardanoProtocolParams StandardCrypto)
    -> IO ForgeResult)
-> IO ForgeResult
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (String -> IO ForgeResult)
-> ((DBSynthesizerConfig, CardanoProtocolParams StandardCrypto)
    -> IO ForgeResult)
-> Either
     String (DBSynthesizerConfig, CardanoProtocolParams StandardCrypto)
-> IO ForgeResult
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either String -> IO ForgeResult
forall a. String -> IO a
die ((DBSynthesizerConfig
 -> CardanoProtocolParams StandardCrypto -> IO ForgeResult)
-> (DBSynthesizerConfig, CardanoProtocolParams StandardCrypto)
-> IO ForgeResult
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((TopLevelConfig (CardanoBlock StandardCrypto)
 -> GenTxs (CardanoBlock StandardCrypto))
-> DBSynthesizerConfig
-> CardanoProtocolParams StandardCrypto
-> IO ForgeResult
synthesize TopLevelConfig (CardanoBlock StandardCrypto)
-> GenTxs (CardanoBlock StandardCrypto)
forall {f :: * -> *} {p} {p} {p} {a}.
Applicative f =>
p -> p -> p -> f [a]
genTxs))
    String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"--> done; result: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ ForgeResult -> String
forall a. Show a => a -> String
show ForgeResult
result