Add get_confirmed_block()/get_confirmed_blocks()
This commit is contained in:
parent
fcda972cec
commit
05664d150b
|
@ -5,8 +5,8 @@ use crate::{
|
||||||
mock_rpc_client_request::MockRpcClientRequest,
|
mock_rpc_client_request::MockRpcClientRequest,
|
||||||
rpc_client_request::RpcClientRequest,
|
rpc_client_request::RpcClientRequest,
|
||||||
rpc_request::{
|
rpc_request::{
|
||||||
RpcContactInfo, RpcEpochInfo, RpcLeaderSchedule, RpcRequest, RpcVersionInfo,
|
RpcConfirmedBlock, RpcContactInfo, RpcEpochInfo, RpcLeaderSchedule, RpcRequest,
|
||||||
RpcVoteAccountStatus,
|
RpcVersionInfo, RpcVoteAccountStatus,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
|
@ -194,6 +194,52 @@ impl RpcClient {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_confirmed_block(&self, slot: Slot) -> io::Result<RpcConfirmedBlock> {
|
||||||
|
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<Slot>,
|
||||||
|
) -> io::Result<Vec<Slot>> {
|
||||||
|
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<UnixTimestamp> {
|
pub fn get_block_time(&self, slot: Slot) -> io::Result<UnixTimestamp> {
|
||||||
let response = self
|
let response = self
|
||||||
.client
|
.client
|
||||||
|
|
|
@ -35,7 +35,6 @@ impl GenericRpcClientRequest for RpcClientRequest {
|
||||||
fn send(
|
fn send(
|
||||||
&self,
|
&self,
|
||||||
request: &RpcRequest,
|
request: &RpcRequest,
|
||||||
//params: Option<serde_json::Value>,
|
|
||||||
params: serde_json::Value,
|
params: serde_json::Value,
|
||||||
mut retries: usize,
|
mut retries: usize,
|
||||||
) -> Result<serde_json::Value, ClientError> {
|
) -> Result<serde_json::Value, ClientError> {
|
||||||
|
|
|
@ -122,6 +122,8 @@ pub enum RpcRequest {
|
||||||
GetBalance,
|
GetBalance,
|
||||||
GetBlockTime,
|
GetBlockTime,
|
||||||
GetClusterNodes,
|
GetClusterNodes,
|
||||||
|
GetConfirmedBlock,
|
||||||
|
GetConfirmedBlocks,
|
||||||
GetEpochInfo,
|
GetEpochInfo,
|
||||||
GetEpochSchedule,
|
GetEpochSchedule,
|
||||||
GetGenesisHash,
|
GetGenesisHash,
|
||||||
|
@ -158,6 +160,8 @@ impl RpcRequest {
|
||||||
RpcRequest::GetBalance => "getBalance",
|
RpcRequest::GetBalance => "getBalance",
|
||||||
RpcRequest::GetBlockTime => "getBlockTime",
|
RpcRequest::GetBlockTime => "getBlockTime",
|
||||||
RpcRequest::GetClusterNodes => "getClusterNodes",
|
RpcRequest::GetClusterNodes => "getClusterNodes",
|
||||||
|
RpcRequest::GetConfirmedBlock => "getConfirmedBlock",
|
||||||
|
RpcRequest::GetConfirmedBlocks => "getConfirmedBlocks",
|
||||||
RpcRequest::GetEpochInfo => "getEpochInfo",
|
RpcRequest::GetEpochInfo => "getEpochInfo",
|
||||||
RpcRequest::GetEpochSchedule => "getEpochSchedule",
|
RpcRequest::GetEpochSchedule => "getEpochSchedule",
|
||||||
RpcRequest::GetGenesisHash => "getGenesisHash",
|
RpcRequest::GetGenesisHash => "getGenesisHash",
|
||||||
|
|
Loading…
Reference in New Issue