Properly type RpcClient::get_version() (#6919)

This commit is contained in:
Michael Vines
2019-11-12 22:01:04 -07:00
committed by GitHub
parent 81acd94153
commit 86faa3f995
6 changed files with 33 additions and 42 deletions

View File

@ -4,7 +4,7 @@ use crate::{
generic_rpc_client_request::GenericRpcClientRequest,
mock_rpc_client_request::MockRpcClientRequest,
rpc_client_request::RpcClientRequest,
rpc_request::{RpcEpochInfo, RpcRequest, RpcVoteAccountStatus},
rpc_request::{RpcEpochInfo, RpcRequest, RpcVersionInfo, RpcVoteAccountStatus},
};
use bincode::serialize;
use log::*;
@ -234,7 +234,7 @@ impl RpcClient {
})
}
pub fn get_version(&self) -> io::Result<String> {
pub fn get_version(&self) -> io::Result<RpcVersionInfo> {
let response = self
.client
.send(&RpcRequest::GetVersion, None, 0, None)
@ -245,7 +245,7 @@ impl RpcClient {
)
})?;
serde_json::to_string(&response).map_err(|err| {
serde_json::from_value(response).map_err(|err| {
io::Error::new(
io::ErrorKind::Other,
format!("GetVersion parse failure: {}", err),

View File

@ -4,7 +4,7 @@ use solana_sdk::{
clock::{Epoch, Slot},
commitment_config::CommitmentConfig,
};
use std::{error, fmt, io};
use std::{error, fmt, io, net::SocketAddr};
pub type RpcResponseIn<T> = JsonResult<Response<T>>;
pub type RpcResponse<T> = io::Result<Response<T>>;
@ -20,6 +20,18 @@ pub struct Response<T> {
pub value: T,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct RpcContactInfo {
/// Pubkey of the node as a base-58 string
pub pubkey: String,
/// Gossip port
pub gossip: Option<SocketAddr>,
/// Tpu port
pub tpu: Option<SocketAddr>,
/// JSON RPC port
pub rpc: Option<SocketAddr>,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RpcEpochInfo {
@ -36,6 +48,13 @@ pub struct RpcEpochInfo {
pub absolute_slot: Slot,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")]
pub struct RpcVersionInfo {
/// The current version of solana-core
pub solana_core: String,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RpcVoteAccountStatus {