Adding getLatestBlockhash in rpc

This commit is contained in:
Godmode Galactus 2022-12-06 20:21:52 +01:00
parent d11677c3d5
commit e20a2e4257
No known key found for this signature in database
GPG Key ID: A04142C71ABB0DEA
1 changed files with 39 additions and 1 deletions

View File

@ -316,6 +316,13 @@ pub mod lite_rpc {
&self,
meta: Self::Metadata,
) -> Result<RpcPerformanceCounterResults>;
#[rpc(meta, name = "getLatestBlockhash")]
fn get_latest_blockhash(
&self,
meta: Self::Metadata,
config: Option<RpcContextConfig>,
) -> Result<RpcResponse<RpcBlockhash>>;
}
pub struct LightRpc;
impl Lite for LightRpc {
@ -355,7 +362,7 @@ pub mod lite_rpc {
) -> Result<RpcResponse<RpcBlockhashFeeCalculator>> {
let commitment = match commitment {
Some(x) => x.commitment,
None => CommitmentLevel::Confirmed,
None => CommitmentLevel::Finalized,
};
let (block_hash, slot) = match commitment {
CommitmentLevel::Finalized => {
@ -387,6 +394,37 @@ pub mod lite_rpc {
})
}
fn get_latest_blockhash(
&self,
meta: Self::Metadata,
config: Option<RpcContextConfig>,
) -> Result<RpcResponse<RpcBlockhash>> {
let commitment = match config {
Some(x) => match x.commitment {
Some(x) => x.commitment,
None => CommitmentLevel::Finalized,
},
None => CommitmentLevel::Finalized,
};
let block_info = match commitment {
CommitmentLevel::Finalized => &meta.context.finalized_block_info,
_ => &meta.context.confirmed_block_info,
};
let slot = block_info.slot.load(Ordering::Relaxed);
let last_valid_block_height = block_info.block_height.load(Ordering::Relaxed);
let blockhash = block_info.block_hash.read().unwrap().clone();
Ok(RpcResponse {
context: RpcResponseContext::new(slot),
value: RpcBlockhash {
blockhash,
last_valid_block_height,
},
})
}
fn confirm_transaction(
&self,
meta: Self::Metadata,