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

Add RPC method moon_getEthSyncBlockRange #2922

Merged
merged 13 commits into from
Sep 10, 2024
52 changes: 26 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 15 additions & 8 deletions client/rpc/finality/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ pub trait MoonbeamFinalityApi {
#[method(name = "moon_isTxFinalized")]
async fn is_tx_finalized(&self, tx_hash: H256) -> RpcResult<bool>;

/// Gets the latest block hash that is fully indexed in frontier's backend.
#[method(name = "moon_getLatestBlockHash")]
async fn get_latest_block_hash(&self) -> RpcResult<H256>;
/// Gets the range of blocks that are fully indexed in frontier's backend.
#[method(name = "moon_getFrontierSyncBlockRange")]
async fn get_frontier_sync_block_range(&self) -> RpcResult<(H256, H256)>;
}

pub struct MoonbeamFinality<B: Block, C> {
Expand Down Expand Up @@ -88,11 +88,18 @@ where
}
}

async fn get_latest_block_hash(&self) -> RpcResult<H256> {
let res = self.backend.deref().latest_block_hash().await;
match res {
Ok(val) => Ok(val),
Err(e) => Err(ErrorObject::owned(
async fn get_frontier_sync_block_range(&self) -> RpcResult<(H256, H256)> {
match (
self.backend.deref().first_block_hash().await,
self.backend.deref().latest_block_hash().await,
) {
(Ok(first), Ok(last)) => Ok((first, last)),
(Err(e), _) => Err(ErrorObject::owned(
jsonrpsee::types::error::UNKNOWN_ERROR_CODE,
"No synced block",
Some(e),
)),
(_, Err(e)) => Err(ErrorObject::owned(
jsonrpsee::types::error::UNKNOWN_ERROR_CODE,
"No synced block",
Some(e),
Expand Down
Loading