Add store-tool (#13254)

This commit is contained in:
sakridge
2020-11-01 09:41:28 -08:00
committed by GitHub
parent af9a3f004e
commit 55b0428ff7
5 changed files with 94 additions and 2 deletions

View File

@ -0,0 +1,22 @@
[package]
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
edition = "2018"
name = "solana-store-tool"
description = "Tool to inspect append vecs"
version = "1.5.0"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
publish = false
[dependencies]
log = { version = "0.4.8" }
solana-logger = { path = "../../logger", version = "1.5.0" }
solana-version = { path = "../../version", version = "1.5.0" }
solana-measure = { path = "../../measure", version = "1.5.0" }
solana-runtime = { path = "..", version = "1.5.0" }
solana-sdk = { path = "../../sdk", version = "1.5.0" }
clap = "2.33.1"
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

View File

@ -0,0 +1,47 @@
use clap::{crate_description, crate_name, value_t_or_exit, App, Arg};
use log::*;
use solana_runtime::append_vec::AppendVec;
fn main() {
solana_logger::setup_with_default("solana=info");
let matches = App::new(crate_name!())
.about(crate_description!())
.version(solana_version::version!())
.arg(
Arg::with_name("file")
.long("file")
.takes_value(true)
.value_name("<PATH>")
.help("store to open"),
)
.arg(
Arg::with_name("len")
.long("len")
.takes_value(true)
.value_name("LEN")
.help("len of store to open"),
)
.get_matches();
let file = value_t_or_exit!(matches, "file", String);
let len = value_t_or_exit!(matches, "len", usize);
let mut store = AppendVec::new_empty_map(len);
store.set_no_remove_on_drop();
store.set_file(file).expect("set_file failed");
let accounts = store.accounts(0);
info!(
"store: len: {} capacity: {} accounts: {}",
store.len(),
store.capacity(),
accounts.len()
);
for account in store.accounts(0) {
info!(
" account: {:?} version: {} data: {} hash: {:?}",
account.meta.pubkey, account.meta.write_version, account.meta.data_len, account.hash
);
}
}
#[cfg(test)]
pub mod test {}