Add flags to not print account contents (#21178)
It takes a long time to print the contents of all the accounts. I'll be adding more to the "accounts" subcommand and would like to skip printing the account contents.
This commit is contained in:
parent
6704fa011f
commit
2031522809
|
@ -1425,10 +1425,16 @@ fn main() {
|
||||||
.help("Include sysvars too"),
|
.help("Include sysvars too"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("exclude_account_data")
|
Arg::with_name("no_account_contents")
|
||||||
.long("exclude-account-data")
|
.long("no-account-contents")
|
||||||
.takes_value(false)
|
.takes_value(false)
|
||||||
.help("Exclude account data (useful for large number of accounts)"),
|
.help("Do not print contents of each account, which is very slow with lots of accounts."),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("no_account_data")
|
||||||
|
.long("no-account-data")
|
||||||
|
.takes_value(false)
|
||||||
|
.help("Do not print account data when printing account contents."),
|
||||||
)
|
)
|
||||||
.arg(&max_genesis_archive_unpacked_size_arg)
|
.arg(&max_genesis_archive_unpacked_size_arg)
|
||||||
).subcommand(
|
).subcommand(
|
||||||
|
@ -2471,54 +2477,50 @@ fn main() {
|
||||||
};
|
};
|
||||||
let genesis_config = open_genesis_config_by(&ledger_path, arg_matches);
|
let genesis_config = open_genesis_config_by(&ledger_path, arg_matches);
|
||||||
let include_sysvars = arg_matches.is_present("include_sysvars");
|
let include_sysvars = arg_matches.is_present("include_sysvars");
|
||||||
let exclude_account_data = arg_matches.is_present("exclude_account_data");
|
|
||||||
let blockstore = open_blockstore(
|
let blockstore = open_blockstore(
|
||||||
&ledger_path,
|
&ledger_path,
|
||||||
AccessType::TryPrimaryThenSecondary,
|
AccessType::TryPrimaryThenSecondary,
|
||||||
wal_recovery_mode,
|
wal_recovery_mode,
|
||||||
);
|
);
|
||||||
match load_bank_forks(
|
let (bank_forks, ..) = load_bank_forks(
|
||||||
arg_matches,
|
arg_matches,
|
||||||
&genesis_config,
|
&genesis_config,
|
||||||
&blockstore,
|
&blockstore,
|
||||||
process_options,
|
process_options,
|
||||||
snapshot_archive_path,
|
snapshot_archive_path,
|
||||||
) {
|
)
|
||||||
Ok((bank_forks, ..)) => {
|
.unwrap_or_else(|err| {
|
||||||
let slot = bank_forks.working_bank().slot();
|
eprintln!("Failed to load ledger: {:?}", err);
|
||||||
let bank = bank_forks.get(slot).unwrap_or_else(|| {
|
exit(1);
|
||||||
eprintln!("Error: Slot {} is not available", slot);
|
});
|
||||||
exit(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
let accounts: BTreeMap<_, _> = bank
|
let bank = bank_forks.working_bank();
|
||||||
.get_all_accounts_with_modified_slots()
|
let accounts: BTreeMap<_, _> = bank
|
||||||
.unwrap()
|
.get_all_accounts_with_modified_slots()
|
||||||
.into_iter()
|
.unwrap()
|
||||||
.filter(|(pubkey, _account, _slot)| {
|
.into_iter()
|
||||||
include_sysvars || !solana_sdk::sysvar::is_sysvar_id(pubkey)
|
.filter(|(pubkey, _account, _slot)| {
|
||||||
})
|
include_sysvars || !solana_sdk::sysvar::is_sysvar_id(pubkey)
|
||||||
.map(|(pubkey, account, slot)| (pubkey, (account, slot)))
|
})
|
||||||
.collect();
|
.map(|(pubkey, account, slot)| (pubkey, (account, slot)))
|
||||||
|
.collect();
|
||||||
|
|
||||||
println!("---");
|
let print_account_contents = !arg_matches.is_present("no_account_contents");
|
||||||
for (pubkey, (account, slot)) in accounts.into_iter() {
|
if print_account_contents {
|
||||||
let data_len = account.data().len();
|
println!("Getting accounts contents...");
|
||||||
println!("{}:", pubkey);
|
let print_account_data = !arg_matches.is_present("no_account_data");
|
||||||
println!(" - balance: {} SOL", lamports_to_sol(account.lamports()));
|
for (pubkey, (account, slot)) in accounts.into_iter() {
|
||||||
println!(" - owner: '{}'", account.owner());
|
let data_len = account.data().len();
|
||||||
println!(" - executable: {}", account.executable());
|
println!("{}:", pubkey);
|
||||||
println!(" - slot: {}", slot);
|
println!(" - balance: {} SOL", lamports_to_sol(account.lamports()));
|
||||||
println!(" - rent_epoch: {}", account.rent_epoch());
|
println!(" - owner: '{}'", account.owner());
|
||||||
if !exclude_account_data {
|
println!(" - executable: {}", account.executable());
|
||||||
println!(" - data: '{}'", bs58::encode(account.data()).into_string());
|
println!(" - slot: {}", slot);
|
||||||
}
|
println!(" - rent_epoch: {}", account.rent_epoch());
|
||||||
println!(" - data_len: {}", data_len);
|
if print_account_data {
|
||||||
|
println!(" - data: '{}'", bs58::encode(account.data()).into_string());
|
||||||
}
|
}
|
||||||
}
|
println!(" - data_len: {}", data_len);
|
||||||
Err(err) => {
|
|
||||||
eprintln!("Failed to load ledger: {:?}", err);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue