get_stored_account_meta_callback returns Option (#847)
* get_stored_account_meta_callback returns Option * Update accounts-db/src/accounts_file.rs Co-authored-by: Brooks <brooks@prumo.org> --------- Co-authored-by: Brooks <brooks@prumo.org>
This commit is contained in:
parent
97c56ac0e2
commit
63d4278cae
|
@ -137,24 +137,23 @@ impl AccountsFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// calls `callback` with the account located at the specified index offset.
|
/// calls `callback` with the account located at the specified index offset.
|
||||||
pub fn get_stored_account_meta_callback<'a>(
|
pub fn get_stored_account_meta_callback<'a, Ret>(
|
||||||
&'a self,
|
&'a self,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
callback: impl FnMut(StoredAccountMeta<'a>),
|
callback: impl FnMut(StoredAccountMeta<'a>) -> Ret,
|
||||||
) {
|
) -> Option<Ret> {
|
||||||
match self {
|
match self {
|
||||||
Self::AppendVec(av) => av.get_stored_account_meta_callback(offset, callback),
|
Self::AppendVec(av) => av.get_stored_account_meta_callback(offset, callback),
|
||||||
// Note: The conversion here is needed as the AccountsDB currently
|
// Note: The conversion here is needed as the AccountsDB currently
|
||||||
// assumes all offsets are multiple of 8 while TieredStorage uses
|
// assumes all offsets are multiple of 8 while TieredStorage uses
|
||||||
// IndexOffset that is equivalent to AccountInfo::reduced_offset.
|
// IndexOffset that is equivalent to AccountInfo::reduced_offset.
|
||||||
Self::TieredStorage(ts) => {
|
Self::TieredStorage(ts) => ts
|
||||||
if let Some(reader) = ts.reader() {
|
.reader()?
|
||||||
_ = reader.get_stored_account_meta_callback(
|
.get_stored_account_meta_callback(
|
||||||
IndexOffset(AccountInfo::get_reduced_offset(offset)),
|
IndexOffset(AccountInfo::get_reduced_offset(offset)),
|
||||||
callback,
|
callback,
|
||||||
);
|
)
|
||||||
}
|
.ok()?,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -542,14 +542,13 @@ impl AppendVec {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// calls `callback` with the account located at the specified index offset.
|
/// calls `callback` with the account located at the specified index offset.
|
||||||
pub fn get_stored_account_meta_callback<'a>(
|
pub fn get_stored_account_meta_callback<'a, Ret>(
|
||||||
&'a self,
|
&'a self,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
mut callback: impl FnMut(StoredAccountMeta<'a>),
|
mut callback: impl FnMut(StoredAccountMeta<'a>) -> Ret,
|
||||||
) {
|
) -> Option<Ret> {
|
||||||
if let Some((account, _offset)) = self.get_stored_account_meta(offset) {
|
self.get_stored_account_meta(offset)
|
||||||
callback(account)
|
.map(|(account, _offset)| callback(account))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return an `AccountSharedData` for an account at `offset`.
|
/// return an `AccountSharedData` for an account at `offset`.
|
||||||
|
|
|
@ -527,15 +527,13 @@ impl HotStorageReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// calls `callback` with the account located at the specified index offset.
|
/// calls `callback` with the account located at the specified index offset.
|
||||||
pub fn get_stored_account_meta_callback<'a>(
|
pub fn get_stored_account_meta_callback<'a, Ret>(
|
||||||
&'a self,
|
&'a self,
|
||||||
index_offset: IndexOffset,
|
index_offset: IndexOffset,
|
||||||
mut callback: impl FnMut(StoredAccountMeta<'a>),
|
mut callback: impl FnMut(StoredAccountMeta<'a>) -> Ret,
|
||||||
) -> TieredStorageResult<()> {
|
) -> TieredStorageResult<Option<Ret>> {
|
||||||
if let Some((account, _offset)) = self.get_stored_account_meta(index_offset)? {
|
let account = self.get_stored_account_meta(index_offset)?;
|
||||||
callback(account)
|
Ok(account.map(|(account, _offset)| callback(account)))
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the account located at the specified index offset.
|
/// Returns the account located at the specified index offset.
|
||||||
|
|
|
@ -86,11 +86,11 @@ impl TieredStorageReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// calls `callback` with the account located at the specified index offset.
|
/// calls `callback` with the account located at the specified index offset.
|
||||||
pub fn get_stored_account_meta_callback<'a>(
|
pub fn get_stored_account_meta_callback<'a, Ret>(
|
||||||
&'a self,
|
&'a self,
|
||||||
index_offset: IndexOffset,
|
index_offset: IndexOffset,
|
||||||
callback: impl FnMut(StoredAccountMeta<'a>),
|
callback: impl FnMut(StoredAccountMeta<'a>) -> Ret,
|
||||||
) -> TieredStorageResult<()> {
|
) -> TieredStorageResult<Option<Ret>> {
|
||||||
match self {
|
match self {
|
||||||
Self::Hot(hot) => hot.get_stored_account_meta_callback(index_offset, callback),
|
Self::Hot(hot) => hot.get_stored_account_meta_callback(index_offset, callback),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue