From 05664d150b2f5f8973596061928cb6ef19cae307 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Wed, 18 Dec 2019 22:31:38 -0700 Subject: [PATCH] Add get_confirmed_block()/get_confirmed_blocks() --- client/src/rpc_client.rs | 50 ++++++++++++++++++++++++++++++-- client/src/rpc_client_request.rs | 1 - client/src/rpc_request.rs | 4 +++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/client/src/rpc_client.rs b/client/src/rpc_client.rs index 06e9e075b..56ac69b26 100644 --- a/client/src/rpc_client.rs +++ b/client/src/rpc_client.rs @@ -5,8 +5,8 @@ use crate::{ mock_rpc_client_request::MockRpcClientRequest, rpc_client_request::RpcClientRequest, rpc_request::{ - RpcContactInfo, RpcEpochInfo, RpcLeaderSchedule, RpcRequest, RpcVersionInfo, - RpcVoteAccountStatus, + RpcConfirmedBlock, RpcContactInfo, RpcEpochInfo, RpcLeaderSchedule, RpcRequest, + RpcVersionInfo, RpcVoteAccountStatus, }, }; use bincode::serialize; @@ -194,6 +194,52 @@ impl RpcClient { }) } + pub fn get_confirmed_block(&self, slot: Slot) -> io::Result { + let response = self + .client + .send(&RpcRequest::GetConfirmedBlock, json!([slot]), 0) + .map_err(|err| { + io::Error::new( + io::ErrorKind::Other, + format!("GetConfirmedBlock request failure: {:?}", err), + ) + })?; + + serde_json::from_value(response).map_err(|err| { + io::Error::new( + io::ErrorKind::Other, + format!("GetConfirmedBlock parse failure: {}", err), + ) + }) + } + + pub fn get_confirmed_blocks( + &self, + start_slot: Slot, + end_slot: Option, + ) -> io::Result> { + let response = self + .client + .send( + &RpcRequest::GetConfirmedBlocks, + json!([start_slot, end_slot]), + 0, + ) + .map_err(|err| { + io::Error::new( + io::ErrorKind::Other, + format!("GetConfirmedBlocks request failure: {:?}", err), + ) + })?; + + serde_json::from_value(response).map_err(|err| { + io::Error::new( + io::ErrorKind::Other, + format!("GetConfirmedBlocks parse failure: {}", err), + ) + }) + } + pub fn get_block_time(&self, slot: Slot) -> io::Result { let response = self .client diff --git a/client/src/rpc_client_request.rs b/client/src/rpc_client_request.rs index ab3bf1347..df5f24eb1 100644 --- a/client/src/rpc_client_request.rs +++ b/client/src/rpc_client_request.rs @@ -35,7 +35,6 @@ impl GenericRpcClientRequest for RpcClientRequest { fn send( &self, request: &RpcRequest, - //params: Option, params: serde_json::Value, mut retries: usize, ) -> Result { diff --git a/client/src/rpc_request.rs b/client/src/rpc_request.rs index 86addd6d3..da60f4942 100644 --- a/client/src/rpc_request.rs +++ b/client/src/rpc_request.rs @@ -122,6 +122,8 @@ pub enum RpcRequest { GetBalance, GetBlockTime, GetClusterNodes, + GetConfirmedBlock, + GetConfirmedBlocks, GetEpochInfo, GetEpochSchedule, GetGenesisHash, @@ -158,6 +160,8 @@ impl RpcRequest { RpcRequest::GetBalance => "getBalance", RpcRequest::GetBlockTime => "getBlockTime", RpcRequest::GetClusterNodes => "getClusterNodes", + RpcRequest::GetConfirmedBlock => "getConfirmedBlock", + RpcRequest::GetConfirmedBlocks => "getConfirmedBlocks", RpcRequest::GetEpochInfo => "getEpochInfo", RpcRequest::GetEpochSchedule => "getEpochSchedule", RpcRequest::GetGenesisHash => "getGenesisHash",