Add search for TTD block

This commit is contained in:
Paul Hauner
2021-09-27 16:05:19 +10:00
parent c329fae53c
commit f9fd6ac392
3 changed files with 82 additions and 1 deletions

View File

@@ -2,7 +2,9 @@ use async_trait::async_trait;
use eth1::http::RpcError;
use serde::{Deserialize, Serialize};
pub use types::{Address, EthSpec, ExecutionPayload, Hash256};
pub const LATEST_TAG: &str = "latest";
pub use types::{Address, EthSpec, ExecutionPayload, Hash256, Uint256};
pub mod http;
@@ -37,6 +39,13 @@ impl From<serde_json::Error> for Error {
pub trait EngineApi {
async fn upcheck(&self) -> Result<(), Error>;
async fn get_block_by_number<'a>(
&self,
block_by_number: BlockByNumberQuery<'a>,
) -> Result<ExecutionBlock, Error>;
async fn get_block_by_hash<'a>(&self, block_hash: Hash256) -> Result<ExecutionBlock, Error>;
async fn prepare_payload(
&self,
parent_hash: Hash256,
@@ -82,3 +91,18 @@ pub enum ConsensusStatus {
Valid,
Invalid,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
#[serde(untagged)]
pub enum BlockByNumberQuery<'a> {
Tag(&'a str),
}
#[derive(Clone, Copy, Debug, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ExecutionBlock {
pub block_hash: Hash256,
pub block_number: u64,
pub parent_hash: Hash256,
pub total_difficulty: Uint256,
}