Properly type RpcClient::get_version() (#6919)
This commit is contained in:
parent
81acd94153
commit
86faa3f995
|
@ -67,6 +67,9 @@ echo --- Creating tarball
|
|||
echo "target: $TARGET"
|
||||
) > solana-release/version.yml
|
||||
|
||||
# Make CHANNEL available to include in the software version information
|
||||
export CHANNEL
|
||||
|
||||
source ci/rust-version.sh stable
|
||||
scripts/cargo-install-all.sh +"$rust_stable" --use-move solana-release
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ use crate::{
|
|||
};
|
||||
use clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand};
|
||||
use console::{style, Emoji};
|
||||
use serde_json::Value;
|
||||
use solana_client::{rpc_client::RpcClient, rpc_request::RpcVoteAccountInfo};
|
||||
use solana_sdk::{
|
||||
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 {
|
||||
let remote_version: Value = serde_json::from_str(&rpc_client.get_version()?)?;
|
||||
println!(
|
||||
"{} {}",
|
||||
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_cluster_version(rpc_client: &RpcClient, _config: &CliConfig) -> ProcessResult {
|
||||
let remote_version = rpc_client.get_version()?;
|
||||
Ok(remote_version.solana_core)
|
||||
}
|
||||
|
||||
pub fn process_fees(rpc_client: &RpcClient) -> ProcessResult {
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -13,7 +13,8 @@ use bincode::serialize;
|
|||
use jsonrpc_core::{Error, Metadata, Result};
|
||||
use jsonrpc_derive::rpc;
|
||||
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_ledger::{
|
||||
|
@ -342,25 +343,6 @@ pub struct 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)]
|
||||
pub trait RpcSol {
|
||||
type Metadata;
|
||||
|
|
|
@ -18,8 +18,8 @@ fn test_rpc_client() {
|
|||
let client = RpcClient::new_socket(leader_data.rpc);
|
||||
|
||||
assert_eq!(
|
||||
client.get_version().unwrap(),
|
||||
format!("{{\"solana-core\":\"{}\"}}", solana_core::version!())
|
||||
client.get_version().unwrap().solana_core,
|
||||
solana_core::version!()
|
||||
);
|
||||
|
||||
assert_eq!(client.get_balance(&bob_pubkey).unwrap(), 0);
|
||||
|
|
Loading…
Reference in New Issue