mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
refactor(txpool): small refactor for InMemoryBlobStore impl (#11886)
This commit is contained in:
@ -76,42 +76,26 @@ impl BlobStore for InMemoryBlobStore {
|
|||||||
|
|
||||||
// Retrieves the decoded blob data for the given transaction hash.
|
// Retrieves the decoded blob data for the given transaction hash.
|
||||||
fn get(&self, tx: B256) -> Result<Option<BlobTransactionSidecar>, BlobStoreError> {
|
fn get(&self, tx: B256) -> Result<Option<BlobTransactionSidecar>, BlobStoreError> {
|
||||||
let store = self.inner.store.read();
|
Ok(self.inner.store.read().get(&tx).cloned())
|
||||||
Ok(store.get(&tx).cloned())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn contains(&self, tx: B256) -> Result<bool, BlobStoreError> {
|
fn contains(&self, tx: B256) -> Result<bool, BlobStoreError> {
|
||||||
let store = self.inner.store.read();
|
Ok(self.inner.store.read().contains_key(&tx))
|
||||||
Ok(store.contains_key(&tx))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_all(
|
fn get_all(
|
||||||
&self,
|
&self,
|
||||||
txs: Vec<B256>,
|
txs: Vec<B256>,
|
||||||
) -> Result<Vec<(B256, BlobTransactionSidecar)>, BlobStoreError> {
|
) -> Result<Vec<(B256, BlobTransactionSidecar)>, BlobStoreError> {
|
||||||
let mut items = Vec::with_capacity(txs.len());
|
|
||||||
let store = self.inner.store.read();
|
let store = self.inner.store.read();
|
||||||
for tx in txs {
|
Ok(txs.into_iter().filter_map(|tx| store.get(&tx).map(|item| (tx, item.clone()))).collect())
|
||||||
if let Some(item) = store.get(&tx) {
|
|
||||||
items.push((tx, item.clone()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(items)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_exact(&self, txs: Vec<B256>) -> Result<Vec<BlobTransactionSidecar>, BlobStoreError> {
|
fn get_exact(&self, txs: Vec<B256>) -> Result<Vec<BlobTransactionSidecar>, BlobStoreError> {
|
||||||
let mut items = Vec::with_capacity(txs.len());
|
|
||||||
let store = self.inner.store.read();
|
let store = self.inner.store.read();
|
||||||
for tx in txs {
|
txs.into_iter()
|
||||||
if let Some(item) = store.get(&tx) {
|
.map(|tx| store.get(&tx).cloned().ok_or_else(|| BlobStoreError::MissingSidecar(tx)))
|
||||||
items.push(item.clone());
|
.collect()
|
||||||
} else {
|
|
||||||
return Err(BlobStoreError::MissingSidecar(tx))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(items)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_by_versioned_hashes(
|
fn get_by_versioned_hashes(
|
||||||
|
|||||||
Reference in New Issue
Block a user