github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/adm/src/main.rs (about)

     1  /*
     2   * Copyright 2018 Intel Corporation
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   * ------------------------------------------------------------------------------
    16   */
    17  
    18  #[macro_use]
    19  extern crate clap;
    20  extern crate libc;
    21  extern crate lmdb_zero;
    22  extern crate protobuf;
    23  extern crate sawtooth_sdk;
    24  extern crate serde;
    25  #[macro_use]
    26  extern crate serde_derive;
    27  extern crate serde_yaml;
    28  
    29  mod blockstore;
    30  mod commands;
    31  mod config;
    32  mod database;
    33  mod err;
    34  mod wrappers;
    35  
    36  use clap::ArgMatches;
    37  
    38  const VERSION: &str = env!("CARGO_PKG_VERSION");
    39  
    40  fn main() {
    41      let args = parse_args();
    42  
    43      let result = match args.subcommand() {
    44          ("blockstore", Some(args)) => commands::blockstore::run(args),
    45          ("keygen", Some(args)) => commands::keygen::run(args),
    46          ("genesis", Some(args)) => commands::genesis::run(args),
    47          _ => {
    48              println!("Invalid subcommand; Pass --help for usage.");
    49              Ok(())
    50          }
    51      };
    52  
    53      std::process::exit(match result {
    54          Ok(_) => 0,
    55          Err(err) => {
    56              eprintln!("Error: {}", err);
    57              1
    58          }
    59      });
    60  }
    61  
    62  fn parse_args<'a>() -> ArgMatches<'a> {
    63      let app = clap_app!(sawadm =>
    64          (version: VERSION)
    65          (about: "Manage a local validator keys and data files")
    66          (@subcommand blockstore =>
    67              (about: "manage the blockstore database directly")
    68              (@subcommand backup =>
    69                  (about: "backup the entire blockstore database to a file")
    70                  (@arg output: +required "the file to backup the blockstore to"))
    71              (@subcommand restore =>
    72                  (about: "restore the entire blockstore database from a file")
    73                  (@arg input: +required "the file to restore the blockstore from"))
    74              (@subcommand list =>
    75                  (about: "list blocks from the block store")
    76                  (@arg count: --count +takes_value "the number of blocks to list")
    77                  (@arg start: --start +takes_value "the first block to list"))
    78              (@subcommand show =>
    79                  (about: "inspect a block in the blockstore")
    80                  (@arg block: -b --block +takes_value conflicts_with[batch transaction height]
    81                      "show a block based on block id")
    82                  (@arg batch: -B --batch +takes_value conflicts_with[block transaction height]
    83                      "show a block based on batch id")
    84                  (@arg transaction: -T --transaction +takes_value conflicts_with[block batch height]
    85                      "show a block based on transaction id")
    86               (@arg blocknum: -n --("block-num")
    87                +takes_value conflicts_with[block batch transaction]
    88                      "show a block based on height"))
    89              (@subcommand prune =>
    90                  (about: "remove a block and all children blocks from the blockstore")
    91                  (@arg block: +required "the block to remove"))
    92              (@subcommand export =>
    93                  (about: "write a block's packed representation to file or stdout")
    94                  (@arg block: +required "the block to export")
    95                  (@arg output: -o --output +takes_value "the file to export the block to"))
    96              (@subcommand import =>
    97                  (about: "add a block to the blockstore; new block's parent must be the current chain head")
    98                  (@arg blockfile: +required "a protobuf file containing the block to add"))
    99              (@subcommand stats =>
   100                  (about: "print out database stats")
   101                  (@arg extended: -x --extended "show extended stats about the blockstore")))
   102          (@subcommand keygen =>
   103              (about: "generates keys for the validator to use when signing blocks")
   104              (@arg key_name: +takes_value "name of the key to create")
   105              (@arg force: --force "overwrite files if they exist")
   106              (@arg quiet: -q --quiet "do not display output"))
   107          (@subcommand genesis =>
   108              (about: "creates the genesis.batch file for initializing the validator")
   109           (@arg input_file:
   110            +takes_value ... "file or files containing batches to add to the resulting")
   111              (@arg output: -o --output "choose the output file for GenesisData"))
   112          (@arg verbose: -v... "increase the logging level.")
   113      );
   114      app.get_matches()
   115  }