ledger-tool: Add print-accounts command

(cherry picked from commit 1bf2285fa2)
This commit is contained in:
Michael Vines
2020-02-14 13:24:16 -07:00
parent 1dbcd5c298
commit 370716edd3
6 changed files with 80 additions and 10 deletions

View File

@@ -381,13 +381,16 @@ impl Accounts {
pub fn load_by_program(
&self,
ancestors: &HashMap<Slot, usize>,
program_id: &Pubkey,
program_id: Option<&Pubkey>,
) -> Vec<(Pubkey, Account)> {
self.accounts_db.scan_accounts(
ancestors,
|collector: &mut Vec<(Pubkey, Account)>, option| {
if let Some(data) = option
.filter(|(_, account, _)| account.owner == *program_id && account.lamports != 0)
.filter(|(_, account, _)| {
(program_id.is_none() || Some(&account.owner) == program_id)
&& account.lamports != 0
})
.map(|(pubkey, account, _slot)| (*pubkey, account))
{
collector.push(data)