From 302a43653ffb67dc780404ea230ce1fb2dab4378 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sun, 16 Nov 2025 11:51:30 -0500 Subject: [PATCH] Add helper to get `TemporalSerai` as of the latest finalized block --- substrate/client/serai/src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/substrate/client/serai/src/lib.rs b/substrate/client/serai/src/lib.rs index badf22a7..9c925e67 100644 --- a/substrate/client/serai/src/lib.rs +++ b/substrate/client/serai/src/lib.rs @@ -175,6 +175,22 @@ impl Serai { Ok(TemporalSerai { serai: self, block, events: Arc::new(RwLock::new(None)) }) } + /// Scope this RPC client to the state as of the latest finalized block. + pub async fn as_of_latest_finalized_block<'a>( + &'a self, + block: BlockHash, + ) -> Result, RpcError> { + let block = self + .block_by_number(self.latest_finalized_block_number().await?) + .await? + .ok_or_else(|| RpcError::InvalidNode("couldn't fetch latest finalized block".to_string()))?; + Ok(TemporalSerai { + serai: self, + block: block.header.hash(), + events: Arc::new(RwLock::new(None)), + }) + } + /// Return the P2P addresses for the validators of the specified network. pub async fn p2p_validators(&self, network: ExternalNetworkId) -> Result, RpcError> { self