message: [storage] add list-accounts option for LibraDB storage inspector
  Closes:
  Approved by: thefallentree
diff: @@ -10,7 +10,9 @@ use std::path::PathBuf;
  use storage_interface::DbReader;
  use transaction_builder::get_transaction_name;
  -use libra_types::{account_address::AccountAddress, account_config::AccountResource};
  +use libra_types::{
  + account_address::AccountAddress, account_config::AccountResource, account_state::AccountState,
  +};
  use std::convert::TryFrom;
  use structopt::StructOpt;
  @@ -34,6 +36,8 @@ enum Command {
  #[structopt(parse(try_from_str))]
  address: AccountAddress,
  },
  + #[structopt(name = "list-accounts")]
  + ListAccounts,
  }
  /// Print out latest information stored in the DB.
  @@ -120,6 +124,36 @@ fn list_txns(db: &LibraDB) {
  }
  }
  +fn list_accounts(db: &LibraDB) {
  + let version = db
  + .get_latest_version()
  + .expect("Unable to get latest version");
  + let backup = db.get_backup_handler();
  + let iter = backup
  + .get_account_iter(version)
  + .expect("Unagle to get account iter");
  + let mut num_account = 0;
  + for res in iter {
  + match res {
  + Ok((_, blob)) => {
  + let accs = AccountState::try_from(&blob).expect("Failed to read AccountState");
  + let addr = accs
  + .get_account_address()
  + .expect("Could not get address from state");
  + match addr {
  + Some(x) => {
  + num_account += 1;
  + println!("Address: {:?}", x);
  + }
  + None => println!("Skipping: No address for AccountState: {:?}", accs),
  + }
  + }
  + Err(x) => println!("Got err iterating through AccountStateBlobs {:?}", x),
  + }
  + }
  + info!("Total Accounts: {}", num_account);
  +}
  +
  fn main() {
  ::libra_logger::Logger::new().init();
  @@ -149,6 +183,9 @@ fn main() {
  Command::PrintAccount { address } => {
  print_account(&db, address);
  }
  + Command::ListAccounts => {
  + list_accounts(&db);
  + }
  }
  } else {
  print_head(&db).expect("Unable to read information from DB");
  