Adding getLatestBlockhash in rpc
This commit is contained in:
parent
d11677c3d5
commit
e20a2e4257
40
src/rpc.rs
40
src/rpc.rs
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue