|
| 1 | +module DBSynthesizer.Parsers (parseCommandLine) where |
| 2 | + |
| 3 | +import Cardano.Node.Types (KESSource (..), ProtocolFilepaths (..)) |
| 4 | +import Cardano.Tools.DBSynthesizer.Types |
| 5 | +import Data.Word (Word64) |
| 6 | +import Options.Applicative as Opt |
| 7 | +import Ouroboros.Consensus.Block.Abstract (SlotNo (..)) |
| 8 | + |
| 9 | +parseCommandLine :: IO (FilePath, FilePath, ProtocolFilepaths, DBSynthesizerOptions) |
| 10 | +parseCommandLine = |
| 11 | + Opt.customExecParser p opts |
| 12 | + where |
| 13 | + p = Opt.prefs Opt.showHelpOnEmpty |
| 14 | + opts = Opt.info parserCommandLine mempty |
| 15 | + |
| 16 | +parserCommandLine :: Parser (FilePath, FilePath, ProtocolFilepaths, DBSynthesizerOptions) |
| 17 | +parserCommandLine = |
| 18 | + (,,,) |
| 19 | + <$> parseNodeConfigFilePath |
| 20 | + <*> parseChainDBFilePath |
| 21 | + <*> parseProtocolFilepaths |
| 22 | + <*> parseDBSynthesizerOptions |
| 23 | + |
| 24 | +-- | The forging credentials, as file paths. Byron delegation credentials are |
| 25 | +-- not wired up (the synthesizer forges Shelley-based blocks); the KES key path, |
| 26 | +-- when given, is interpreted as a key file (not a KES agent socket). |
| 27 | +parseProtocolFilepaths :: Parser ProtocolFilepaths |
| 28 | +parseProtocolFilepaths = |
| 29 | + mkFilepaths |
| 30 | + <$> optional parseKesKeyFilePath |
| 31 | + <*> optional parseVrfKeyFilePath |
| 32 | + <*> optional parseOperationalCertFilePath |
| 33 | + <*> optional parseBulkFilePath |
| 34 | + where |
| 35 | + mkFilepaths mKes mVrf mCert mBulk = |
| 36 | + ProtocolFilepaths |
| 37 | + { byronCertFile = Nothing |
| 38 | + , byronKeyFile = Nothing |
| 39 | + , shelleyKESSource = KESKeyFilePath <$> mKes |
| 40 | + , shelleyVRFFile = mVrf |
| 41 | + , shelleyCertFile = mCert |
| 42 | + , shelleyBulkCredsFile = mBulk |
| 43 | + } |
| 44 | + |
| 45 | +parseDBSynthesizerOptions :: Parser DBSynthesizerOptions |
| 46 | +parseDBSynthesizerOptions = |
| 47 | + DBSynthesizerOptions |
| 48 | + <$> parseForgeOptions |
| 49 | + <*> parseOpenMode |
| 50 | + |
| 51 | +parseForgeOptions :: Parser ForgeLimit |
| 52 | +parseForgeOptions = |
| 53 | + ForgeLimitSlot <$> parseSlotLimit |
| 54 | + <|> ForgeLimitBlock <$> parseBlockLimit |
| 55 | + <|> ForgeLimitEpoch <$> parseEpochLimit |
| 56 | + |
| 57 | +parseChainDBFilePath :: Parser FilePath |
| 58 | +parseChainDBFilePath = |
| 59 | + strOption |
| 60 | + ( long "db" |
| 61 | + <> metavar "PATH" |
| 62 | + <> help "Path to the Chain DB" |
| 63 | + <> completer (bashCompleter "directory") |
| 64 | + ) |
| 65 | + |
| 66 | +parseNodeConfigFilePath :: Parser FilePath |
| 67 | +parseNodeConfigFilePath = |
| 68 | + strOption |
| 69 | + ( long "config" |
| 70 | + <> metavar "FILE" |
| 71 | + <> help "Path to the node's config.json" |
| 72 | + <> completer (bashCompleter "file") |
| 73 | + ) |
| 74 | + |
| 75 | +parseOperationalCertFilePath :: Parser FilePath |
| 76 | +parseOperationalCertFilePath = |
| 77 | + strOption |
| 78 | + ( long "shelley-operational-certificate" |
| 79 | + <> metavar "FILE" |
| 80 | + <> help "Path to the delegation certificate (in JSON TextEnvelope format)" |
| 81 | + <> completer (bashCompleter "file") |
| 82 | + ) |
| 83 | + |
| 84 | +parseKesKeyFilePath :: Parser FilePath |
| 85 | +parseKesKeyFilePath = |
| 86 | + strOption |
| 87 | + ( long "shelley-kes-key" |
| 88 | + <> metavar "FILE" |
| 89 | + <> help "Path to the KES signing key (in JSON TextEnvelope format)" |
| 90 | + <> completer (bashCompleter "file") |
| 91 | + ) |
| 92 | + |
| 93 | +parseVrfKeyFilePath :: Parser FilePath |
| 94 | +parseVrfKeyFilePath = |
| 95 | + strOption |
| 96 | + ( long "shelley-vrf-key" |
| 97 | + <> metavar "FILE" |
| 98 | + <> help "Path to the VRF signing key (in JSON TextEnvelope format)" |
| 99 | + <> completer (bashCompleter "file") |
| 100 | + ) |
| 101 | + |
| 102 | +parseBulkFilePath :: Parser FilePath |
| 103 | +parseBulkFilePath = |
| 104 | + strOption |
| 105 | + ( long "bulk-credentials-file" |
| 106 | + <> metavar "FILE" |
| 107 | + <> help |
| 108 | + "Path to the bulk credentials file (a JSON file containing an array of arrays containing 3 TextEnvelope objects for the opcert, VRF Signing key, KES signing key)" |
| 109 | + <> completer (bashCompleter "file") |
| 110 | + ) |
| 111 | + |
| 112 | +parseSlotLimit :: Parser SlotNo |
| 113 | +parseSlotLimit = |
| 114 | + SlotNo |
| 115 | + <$> option |
| 116 | + auto |
| 117 | + ( short 's' |
| 118 | + <> long "slots" |
| 119 | + <> metavar "NUMBER" |
| 120 | + <> help "Amount of slots to process" |
| 121 | + ) |
| 122 | + |
| 123 | +parseBlockLimit :: Parser Word64 |
| 124 | +parseBlockLimit = |
| 125 | + option |
| 126 | + auto |
| 127 | + ( short 'b' |
| 128 | + <> long "blocks" |
| 129 | + <> metavar "NUMBER" |
| 130 | + <> help "Amount of blocks to forge" |
| 131 | + ) |
| 132 | + |
| 133 | +parseEpochLimit :: Parser Word64 |
| 134 | +parseEpochLimit = |
| 135 | + option |
| 136 | + auto |
| 137 | + ( short 'e' |
| 138 | + <> long "epochs" |
| 139 | + <> metavar "NUMBER" |
| 140 | + <> help "Amount of epochs to process" |
| 141 | + ) |
| 142 | + |
| 143 | +parseForce :: Parser Bool |
| 144 | +parseForce = |
| 145 | + switch |
| 146 | + ( short 'f' |
| 147 | + <> help "Force overwrite an existing Chain DB" |
| 148 | + ) |
| 149 | + |
| 150 | +parseAppend :: Parser Bool |
| 151 | +parseAppend = |
| 152 | + switch |
| 153 | + ( short 'a' |
| 154 | + <> help "Append to an existing Chain DB" |
| 155 | + ) |
| 156 | + |
| 157 | +parseOpenMode :: Parser DBSynthesizerOpenMode |
| 158 | +parseOpenMode = |
| 159 | + (parseForce *> pure OpenCreateForce) |
| 160 | + <|> (parseAppend *> pure OpenAppend) |
| 161 | + <|> pure OpenCreate |
0 commit comments