Refactor slot status notification to decouple from accounts notifications (#21308)

Problem

Slot status can be used of in other scenarios in addition to account information such as transactions, blocks. The current implementation is too tightly coupled.

Summary of Changes

Decouple the slot status notification from accounts notification. Created a new slot status notification module.
This commit is contained in:
Lijun Wang
2021-11-17 17:11:38 -08:00
committed by GitHub
parent 9eb0c018dc
commit 89c45a57f8
12 changed files with 171 additions and 90 deletions

View File

@ -48,6 +48,11 @@ impl AccountsSelector {
pub fn is_account_selected(&self, account: &[u8], owner: &[u8]) -> bool {
self.select_all_accounts || self.accounts.contains(account) || self.owners.contains(owner)
}
/// Check if any account is of interested at all
pub fn is_enabled(&self) -> bool {
self.select_all_accounts || !self.accounts.is_empty() || !self.owners.is_empty()
}
}
#[cfg(test)]

View File

@ -276,6 +276,15 @@ impl AccountsDbPlugin for AccountsDbPluginPostgres {
}
Ok(())
}
/// Check if the plugin is interested in account data
/// Default is true -- if the plugin is not interested in
/// account data, please return false.
fn to_notify_account_data(&self) -> bool {
self.accounts_selector
.as_ref()
.map_or_else(|| false, |selector| selector.is_enabled())
}
}
impl AccountsDbPluginPostgres {