Skip to content
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

feat(rpc): add getHeader by number+hash #2701

Merged
merged 1 commit into from
Feb 12, 2024
Merged

Conversation

alrevuelta
Copy link
Contributor

Add support for eth_getHeaderByNumber and eth_getHeaderByHash endpoints. To be used as follows:

use ethers_core::types::{BlockId, BlockNumber};
use ethers_providers::Middleware;
use ethers_providers::{Http, Provider};

async fn mytest() {
    let provider = Provider::<Http>::try_from("http://localhost:8545").unwrap();
    let by_num = BlockId::Number(BlockNumber::Number(18826806u64.into()));
    let by_hash = BlockId::Hash(
        "0xac45643453aba125a85a779163e7cfa40e4f8898639f1d5249de1c1481817510".parse().unwrap(),
    );
    // Use by_num or by_hash
    let block = provider.get_header(by_hash).await.unwrap();
    println!("block: {:?}", block);
}

Note that the same type Block is used, but non-header fields are left empty.

async fn get_header<T: Into<BlockId> + Send + Sync>(
&self,
block_hash_or_number: T,
) -> Result<Option<Block<Transaction>>, Self::Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while this is not quite right, because this returns a header, this will still succeed because the transactions will be empty.

since we don't have a header type I'm okay with this

@mattsse mattsse merged commit b249da3 into gakonst:master Feb 12, 2024
17 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants