diff --git a/client/src/rpc_client.rs b/client/src/rpc_client.rs index 3ed5055b3..6be99c2b8 100644 --- a/client/src/rpc_client.rs +++ b/client/src/rpc_client.rs @@ -2,7 +2,7 @@ use crate::client_error::ClientError; use crate::generic_rpc_client_request::GenericRpcClientRequest; use crate::mock_rpc_client_request::MockRpcClientRequest; use crate::rpc_client_request::RpcClientRequest; -use crate::rpc_request::{RpcEpochInfo, RpcRequest}; +use crate::rpc_request::{RpcEpochInfo, RpcRequest, RpcVoteAccountStatus}; use bincode::serialize; use log::*; use serde_json::{json, Value}; @@ -100,6 +100,25 @@ impl RpcClient { }) } + pub fn get_vote_accounts(&self) -> io::Result { + let response = self + .client + .send(&RpcRequest::GetVoteAccounts, None, 0) + .map_err(|err| { + io::Error::new( + io::ErrorKind::Other, + format!("GetVoteAccounts request failure: {:?}", err), + ) + })?; + + serde_json::from_value(response).map_err(|err| { + io::Error::new( + io::ErrorKind::Other, + format!("GetVoteAccounts parse failure: {}", err), + ) + }) + } + pub fn get_epoch_info(&self) -> io::Result { let response = self .client diff --git a/client/src/rpc_request.rs b/client/src/rpc_request.rs index 032f6e28b..3a3b04d19 100644 --- a/client/src/rpc_request.rs +++ b/client/src/rpc_request.rs @@ -17,6 +17,38 @@ pub struct RpcEpochInfo { pub absolute_slot: u64, } +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(rename_all = "camelCase")] +pub struct RpcVoteAccountStatus { + pub current: Vec, + pub delinquent: Vec, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(rename_all = "camelCase")] +pub struct RpcVoteAccountInfo { + /// Vote account pubkey as base-58 encoded string + pub vote_pubkey: String, + + /// The pubkey of the node that votes using this account + pub node_pubkey: String, + + /// The current stake, in lamports, delegated to this vote account + pub activated_stake: u64, + + /// An 8-bit integer used as a fraction (commission/MAX_U8) for rewards payout + pub commission: u8, + + /// Whether this account is staked for the current epoch + pub epoch_vote_account: bool, + + /// Most recent slot voted on by this vote account (0 if no votes exist) + pub last_vote: u64, + + /// Current root slot for this vote account (0 if not root slot exists) + pub root_slot: u64, +} + #[derive(Debug, PartialEq)] pub enum RpcRequest { ConfirmTransaction, diff --git a/core/src/rpc.rs b/core/src/rpc.rs index dbe70ef0c..c05794479 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -13,7 +13,7 @@ use crate::{ use bincode::{deserialize, serialize}; use jsonrpc_core::{Error, Metadata, Result}; use jsonrpc_derive::rpc; -use solana_client::rpc_request::RpcEpochInfo; +use solana_client::rpc_request::{RpcEpochInfo, RpcVoteAccountInfo, RpcVoteAccountStatus}; use solana_drone::drone::request_airdrop_transaction; use solana_runtime::bank::Bank; use solana_sdk::{ @@ -262,37 +262,6 @@ pub struct RpcContactInfo { /// JSON RPC port pub rpc: Option, } -#[derive(Serialize, Deserialize, Clone, Debug)] -#[serde(rename_all = "camelCase")] -pub struct RpcVoteAccountStatus { - pub current: Vec, - pub delinquent: Vec, -} - -#[derive(Serialize, Deserialize, Clone, Debug)] -#[serde(rename_all = "camelCase")] -pub struct RpcVoteAccountInfo { - /// Vote account pubkey as base-58 encoded string - pub vote_pubkey: String, - - /// The pubkey of the node that votes using this account - pub node_pubkey: String, - - /// The current stake, in lamports, delegated to this vote account - pub activated_stake: u64, - - /// An 8-bit integer used as a fraction (commission/MAX_U8) for rewards payout - pub commission: u8, - - /// Whether this account is staked for the current epoch - pub epoch_vote_account: bool, - - /// Most recent slot voted on by this vote account (0 if no votes exist) - pub last_vote: u64, - - /// Current root slot for this vote account (0 if not root slot exists) - pub root_slot: u64, -} #[derive(Serialize, Deserialize, Clone, Debug)] #[serde(rename_all = "kebab-case")]