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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 42 deletions

View File

@ -67,6 +67,9 @@ echo --- Creating tarball
echo "target: $TARGET" echo "target: $TARGET"
) > solana-release/version.yml ) > solana-release/version.yml
# Make CHANNEL available to include in the software version information
export CHANNEL
source ci/rust-version.sh stable source ci/rust-version.sh stable
scripts/cargo-install-all.sh +"$rust_stable" --use-move solana-release scripts/cargo-install-all.sh +"$rust_stable" --use-move solana-release

View File

@ -7,7 +7,6 @@ use crate::{
}; };
use clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand}; use clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand};
use console::{style, Emoji}; use console::{style, Emoji};
use serde_json::Value;
use solana_client::{rpc_client::RpcClient, rpc_request::RpcVoteAccountInfo}; use solana_client::{rpc_client::RpcClient, rpc_request::RpcVoteAccountInfo};
use solana_sdk::{ use solana_sdk::{
clock, clock,
@ -131,21 +130,9 @@ pub fn parse_show_validators(matches: &ArgMatches<'_>) -> Result<CliCommandInfo,
}) })
} }
pub fn process_cluster_version(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult { pub fn process_cluster_version(rpc_client: &RpcClient, _config: &CliConfig) -> ProcessResult {
let remote_version: Value = serde_json::from_str(&rpc_client.get_version()?)?; let remote_version = rpc_client.get_version()?;
println!( Ok(remote_version.solana_core)
"{} {}",
style("Cluster versions from:").bold(),
config.json_rpc_url
);
if let Some(versions) = remote_version.as_object() {
for (key, value) in versions.iter() {
if let Some(value_string) = value.as_str() {
println_name_value(&format!("* {}:", key), &value_string);
}
}
}
Ok("".to_string())
} }
pub fn process_fees(rpc_client: &RpcClient) -> ProcessResult { pub fn process_fees(rpc_client: &RpcClient) -> ProcessResult {

View File

@ -4,7 +4,7 @@ use crate::{
generic_rpc_client_request::GenericRpcClientRequest, generic_rpc_client_request::GenericRpcClientRequest,
mock_rpc_client_request::MockRpcClientRequest, mock_rpc_client_request::MockRpcClientRequest,
rpc_client_request::RpcClientRequest, rpc_client_request::RpcClientRequest,
rpc_request::{RpcEpochInfo, RpcRequest, RpcVoteAccountStatus}, rpc_request::{RpcEpochInfo, RpcRequest, RpcVersionInfo, RpcVoteAccountStatus},
}; };
use bincode::serialize; use bincode::serialize;
use log::*; 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 let response = self
.client .client
.send(&RpcRequest::GetVersion, None, 0, None) .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::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,
format!("GetVersion parse failure: {}", err), format!("GetVersion parse failure: {}", err),

View File

@ -4,7 +4,7 @@ use solana_sdk::{
clock::{Epoch, Slot}, clock::{Epoch, Slot},
commitment_config::CommitmentConfig, commitment_config::CommitmentConfig,
}; };
use std::{error, fmt, io}; use std::{error, fmt, io, net::SocketAddr};
pub type RpcResponseIn<T> = JsonResult<Response<T>>; pub type RpcResponseIn<T> = JsonResult<Response<T>>;
pub type RpcResponse<T> = io::Result<Response<T>>; pub type RpcResponse<T> = io::Result<Response<T>>;
@ -20,6 +20,18 @@ pub struct Response<T> {
pub value: 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)] #[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct RpcEpochInfo { pub struct RpcEpochInfo {
@ -36,6 +48,13 @@ pub struct RpcEpochInfo {
pub absolute_slot: Slot, 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)] #[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct RpcVoteAccountStatus { pub struct RpcVoteAccountStatus {

View File

@ -13,7 +13,8 @@ use bincode::serialize;
use jsonrpc_core::{Error, Metadata, Result}; use jsonrpc_core::{Error, Metadata, Result};
use jsonrpc_derive::rpc; use jsonrpc_derive::rpc;
use solana_client::rpc_request::{ use solana_client::rpc_request::{
Response, RpcEpochInfo, RpcResponseContext, RpcVoteAccountInfo, RpcVoteAccountStatus, Response, RpcContactInfo, RpcEpochInfo, RpcResponseContext, RpcVersionInfo, RpcVoteAccountInfo,
RpcVoteAccountStatus,
}; };
use solana_drone::drone::request_airdrop_transaction; use solana_drone::drone::request_airdrop_transaction;
use solana_ledger::{ use solana_ledger::{
@ -342,25 +343,6 @@ pub struct Meta {
} }
impl Metadata for Meta {} impl Metadata for Meta {}
#[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 = "kebab-case")]
pub struct RpcVersionInfo {
/// The current version of solana-core
pub solana_core: String,
}
#[rpc(server)] #[rpc(server)]
pub trait RpcSol { pub trait RpcSol {
type Metadata; type Metadata;

View File

@ -18,8 +18,8 @@ fn test_rpc_client() {
let client = RpcClient::new_socket(leader_data.rpc); let client = RpcClient::new_socket(leader_data.rpc);
assert_eq!( assert_eq!(
client.get_version().unwrap(), client.get_version().unwrap().solana_core,
format!("{{\"solana-core\":\"{}\"}}", solana_core::version!()) solana_core::version!()
); );
assert_eq!(client.get_balance(&bob_pubkey).unwrap(), 0); assert_eq!(client.get_balance(&bob_pubkey).unwrap(), 0);