Encapsulate accounts of solana:🏦:Accounts
Make the field private and expose an account_values() method that returns the values iterator from the internal hashmap
This commit is contained in:
parent
962e8dca1d
commit
80e19e0ad7
|
@ -197,7 +197,7 @@ pub struct Accounts {
|
||||||
// TODO: implement values() or something? take this back to private
|
// TODO: implement values() or something? take this back to private
|
||||||
// from the voting/leader/finality code
|
// from the voting/leader/finality code
|
||||||
// issue #1701
|
// issue #1701
|
||||||
pub accounts: HashMap<Pubkey, Account>,
|
accounts: HashMap<Pubkey, Account>,
|
||||||
|
|
||||||
/// The number of transactions the bank has processed without error since the
|
/// The number of transactions the bank has processed without error since the
|
||||||
/// start of the ledger.
|
/// start of the ledger.
|
||||||
|
@ -208,6 +208,11 @@ pub struct Accounts {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Accounts {
|
impl Accounts {
|
||||||
|
/// Returns a read-only iterator over all known accounts
|
||||||
|
pub fn account_values(&self) -> std::collections::hash_map::Values<Pubkey, Account> {
|
||||||
|
self.accounts.values()
|
||||||
|
}
|
||||||
|
|
||||||
fn load(&self, pubkey: &Pubkey) -> Option<&Account> {
|
fn load(&self, pubkey: &Pubkey) -> Option<&Account> {
|
||||||
if let Some(account) = self.accounts.get(pubkey) {
|
if let Some(account) = self.accounts.get(pubkey) {
|
||||||
return Some(account);
|
return Some(account);
|
||||||
|
|
|
@ -43,8 +43,7 @@ impl ComputeLeaderFinalityService {
|
||||||
// process_transaction(), case VoteInstruction::RegisterAccount), this will be more accurate.
|
// process_transaction(), case VoteInstruction::RegisterAccount), this will be more accurate.
|
||||||
// See github issue 1654.
|
// See github issue 1654.
|
||||||
bank_accounts
|
bank_accounts
|
||||||
.accounts
|
.account_values()
|
||||||
.values()
|
|
||||||
.filter_map(|account| {
|
.filter_map(|account| {
|
||||||
// Filter out any accounts that don't belong to the VoteProgram
|
// Filter out any accounts that don't belong to the VoteProgram
|
||||||
// by returning None
|
// by returning None
|
||||||
|
|
|
@ -322,8 +322,7 @@ impl LeaderScheduler {
|
||||||
|
|
||||||
// TODO: iterate through checkpoints, too
|
// TODO: iterate through checkpoints, too
|
||||||
accounts
|
accounts
|
||||||
.accounts
|
.account_values()
|
||||||
.values()
|
|
||||||
.filter_map(|account| {
|
.filter_map(|account| {
|
||||||
if vote_program::check_id(&account.owner) {
|
if vote_program::check_id(&account.owner) {
|
||||||
if let Ok(vote_state) = VoteProgram::deserialize(&account.userdata) {
|
if let Ok(vote_state) = VoteProgram::deserialize(&account.userdata) {
|
||||||
|
|
Loading…
Reference in New Issue