kora_rpc/method/
get_blockhash.rs1use kora_lib::error::KoraError;
2use nonblocking::rpc_client::RpcClient;
3use serde::Serialize;
4use solana_client::nonblocking;
5use solana_sdk::commitment_config::CommitmentConfig;
6use utoipa::ToSchema;
7
8#[derive(Debug, Serialize, ToSchema)]
9pub struct GetBlockhashResponse {
10 pub blockhash: String,
11}
12
13pub async fn get_blockhash(rpc_client: &RpcClient) -> Result<GetBlockhashResponse, KoraError> {
14 let blockhash = rpc_client
15 .get_latest_blockhash_with_commitment(CommitmentConfig::confirmed())
16 .await
17 .map_err(|e| KoraError::RpcError(e.to_string()))?;
18 Ok(GetBlockhashResponse { blockhash: blockhash.0.to_string() })
19}