-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: added get_blob_by_hash #10987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: added get_blob_by_hash #10987
Changes from all commits
0113bcb
b90f428
a44a790
42a0d26
70bb473
2158622
06d4976
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ use crate::{ | |
use alloy_chains::NamedChain; | ||
use alloy_consensus::{ | ||
Account, BlockHeader, EnvKzgSettings, Header, Receipt, ReceiptWithBloom, Signed, | ||
Transaction as TransactionTrait, TxEnvelope, | ||
Transaction as TransactionTrait, TxEip4844WithSidecar, TxEnvelope, | ||
proofs::{calculate_receipt_root, calculate_transaction_root}, | ||
transaction::Recovered, | ||
}; | ||
|
@@ -2918,6 +2918,33 @@ impl Backend { | |
)) | ||
} | ||
|
||
pub fn get_blob_by_tx_hash(&self, hash: B256) -> Result<Option<TxEip4844WithSidecar>> { | ||
let tx = self.mined_transaction_by_hash(hash).unwrap(); | ||
let typed_tx = TypedTransaction::try_from(tx).unwrap(); | ||
if let Some(sidecar) = typed_tx.sidecar() { | ||
return Ok(Some(sidecar.clone())); | ||
} | ||
Ok(None) | ||
Comment on lines
+2922
to
+2927
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can fail, so we should handle this gracefully and only return the blobs Vec here |
||
} | ||
|
||
pub fn get_blob_by_versioned_hash(&self, hash: B256) -> Result<Option<TxEip4844WithSidecar>> { | ||
let storage = self.blockchain.storage.read(); | ||
for block in storage.blocks.values() { | ||
for tx in &block.transactions { | ||
let typed_tx = tx.as_ref(); | ||
if let Some(sidecar) = typed_tx.sidecar() { | ||
for blob in sidecar.sidecar.clone() { | ||
let versioned_hash = B256::from(blob.to_kzg_versioned_hash()); | ||
if versioned_hash == hash { | ||
return Ok(Some(sidecar.clone())); | ||
} | ||
} | ||
Comment on lines
+2935
to
+2941
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can simplify this a bit with: because we want to avoid cloning all sidecars for this since this is a bit expensive we also want a new helper |
||
} | ||
} | ||
} | ||
Ok(None) | ||
} | ||
|
||
/// Prove an account's existence or nonexistence in the state trie. | ||
/// | ||
/// Returns a merkle proof of the account's trie node, `account_key` == keccak(address) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be getBlobs