s/Rpc/Display
This commit is contained in:
@ -5,13 +5,13 @@ use solana_sdk::{
|
|||||||
nonce::{state::Versions, State},
|
nonce::{state::Versions, State},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn parse_nonce(data: &[u8]) -> Result<RpcNonceState, ParseAccountError> {
|
pub fn parse_nonce(data: &[u8]) -> Result<DisplayNonceState, ParseAccountError> {
|
||||||
let nonce_state: Versions = bincode::deserialize(data)
|
let nonce_state: Versions = bincode::deserialize(data)
|
||||||
.map_err(|_| ParseAccountError::from(InstructionError::InvalidAccountData))?;
|
.map_err(|_| ParseAccountError::from(InstructionError::InvalidAccountData))?;
|
||||||
let nonce_state = nonce_state.convert_to_current();
|
let nonce_state = nonce_state.convert_to_current();
|
||||||
match nonce_state {
|
match nonce_state {
|
||||||
State::Uninitialized => Ok(RpcNonceState::Uninitialized),
|
State::Uninitialized => Ok(DisplayNonceState::Uninitialized),
|
||||||
State::Initialized(data) => Ok(RpcNonceState::Initialized(RpcNonceData {
|
State::Initialized(data) => Ok(DisplayNonceState::Initialized(DisplayNonceData {
|
||||||
authority: data.authority.to_string(),
|
authority: data.authority.to_string(),
|
||||||
blockhash: data.blockhash.to_string(),
|
blockhash: data.blockhash.to_string(),
|
||||||
fee_calculator: data.fee_calculator,
|
fee_calculator: data.fee_calculator,
|
||||||
@ -21,14 +21,14 @@ pub fn parse_nonce(data: &[u8]) -> Result<RpcNonceState, ParseAccountError> {
|
|||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub enum RpcNonceState {
|
pub enum DisplayNonceState {
|
||||||
Uninitialized,
|
Uninitialized,
|
||||||
Initialized(RpcNonceData),
|
Initialized(DisplayNonceData),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct RpcNonceData {
|
pub struct DisplayNonceData {
|
||||||
pub authority: String,
|
pub authority: String,
|
||||||
pub blockhash: String,
|
pub blockhash: String,
|
||||||
pub fee_calculator: FeeCalculator,
|
pub fee_calculator: FeeCalculator,
|
||||||
|
@ -5,12 +5,12 @@ use solana_sdk::{
|
|||||||
};
|
};
|
||||||
use solana_vote_program::vote_state::{BlockTimestamp, Lockout, VoteState};
|
use solana_vote_program::vote_state::{BlockTimestamp, Lockout, VoteState};
|
||||||
|
|
||||||
pub fn parse_vote(data: &[u8]) -> Result<RpcVoteState, ParseAccountError> {
|
pub fn parse_vote(data: &[u8]) -> Result<DisplayVoteState, ParseAccountError> {
|
||||||
let mut vote_state = VoteState::deserialize(data).map_err(ParseAccountError::from)?;
|
let mut vote_state = VoteState::deserialize(data).map_err(ParseAccountError::from)?;
|
||||||
let epoch_credits = vote_state
|
let epoch_credits = vote_state
|
||||||
.epoch_credits()
|
.epoch_credits()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(epoch, credits, previous_credits)| RpcEpochCredits {
|
.map(|(epoch, credits, previous_credits)| DisplayEpochCredits {
|
||||||
epoch: *epoch,
|
epoch: *epoch,
|
||||||
credits: *credits,
|
credits: *credits,
|
||||||
previous_credits: *previous_credits,
|
previous_credits: *previous_credits,
|
||||||
@ -19,7 +19,7 @@ pub fn parse_vote(data: &[u8]) -> Result<RpcVoteState, ParseAccountError> {
|
|||||||
let votes = vote_state
|
let votes = vote_state
|
||||||
.votes
|
.votes
|
||||||
.iter()
|
.iter()
|
||||||
.map(|lockout| RpcLockout {
|
.map(|lockout| DisplayLockout {
|
||||||
slot: lockout.slot,
|
slot: lockout.slot,
|
||||||
confirmation_count: lockout.confirmation_count,
|
confirmation_count: lockout.confirmation_count,
|
||||||
})
|
})
|
||||||
@ -27,7 +27,7 @@ pub fn parse_vote(data: &[u8]) -> Result<RpcVoteState, ParseAccountError> {
|
|||||||
let authorized_voters = vote_state
|
let authorized_voters = vote_state
|
||||||
.authorized_voters()
|
.authorized_voters()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(epoch, authorized_voter)| RpcAuthorizedVoters {
|
.map(|(epoch, authorized_voter)| DisplayAuthorizedVoters {
|
||||||
epoch: *epoch,
|
epoch: *epoch,
|
||||||
authorized_voter: authorized_voter.to_string(),
|
authorized_voter: authorized_voter.to_string(),
|
||||||
})
|
})
|
||||||
@ -38,14 +38,16 @@ pub fn parse_vote(data: &[u8]) -> Result<RpcVoteState, ParseAccountError> {
|
|||||||
.iter()
|
.iter()
|
||||||
.filter(|(pubkey, _, _)| pubkey != &Pubkey::default())
|
.filter(|(pubkey, _, _)| pubkey != &Pubkey::default())
|
||||||
.map(
|
.map(
|
||||||
|(authorized_pubkey, epoch_of_last_authorized_switch, target_epoch)| RpcPriorVoters {
|
|(authorized_pubkey, epoch_of_last_authorized_switch, target_epoch)| {
|
||||||
authorized_pubkey: authorized_pubkey.to_string(),
|
DisplayPriorVoters {
|
||||||
epoch_of_last_authorized_switch: *epoch_of_last_authorized_switch,
|
authorized_pubkey: authorized_pubkey.to_string(),
|
||||||
target_epoch: *target_epoch,
|
epoch_of_last_authorized_switch: *epoch_of_last_authorized_switch,
|
||||||
|
target_epoch: *target_epoch,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.collect();
|
.collect();
|
||||||
Ok(RpcVoteState {
|
Ok(DisplayVoteState {
|
||||||
node_pubkey: vote_state.node_pubkey.to_string(),
|
node_pubkey: vote_state.node_pubkey.to_string(),
|
||||||
authorized_withdrawer: vote_state.authorized_withdrawer.to_string(),
|
authorized_withdrawer: vote_state.authorized_withdrawer.to_string(),
|
||||||
commission: vote_state.commission,
|
commission: vote_state.commission,
|
||||||
@ -61,26 +63,26 @@ pub fn parse_vote(data: &[u8]) -> Result<RpcVoteState, ParseAccountError> {
|
|||||||
/// A duplicate representation of VoteState for pretty JSON serialization
|
/// A duplicate representation of VoteState for pretty JSON serialization
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct RpcVoteState {
|
pub struct DisplayVoteState {
|
||||||
node_pubkey: String,
|
node_pubkey: String,
|
||||||
authorized_withdrawer: String,
|
authorized_withdrawer: String,
|
||||||
commission: u8,
|
commission: u8,
|
||||||
votes: Vec<RpcLockout>,
|
votes: Vec<DisplayLockout>,
|
||||||
root_slot: Option<Slot>,
|
root_slot: Option<Slot>,
|
||||||
authorized_voters: Vec<RpcAuthorizedVoters>,
|
authorized_voters: Vec<DisplayAuthorizedVoters>,
|
||||||
prior_voters: Vec<RpcPriorVoters>,
|
prior_voters: Vec<DisplayPriorVoters>,
|
||||||
epoch_credits: Vec<RpcEpochCredits>,
|
epoch_credits: Vec<DisplayEpochCredits>,
|
||||||
last_timestamp: BlockTimestamp,
|
last_timestamp: BlockTimestamp,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct RpcLockout {
|
struct DisplayLockout {
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
confirmation_count: u32,
|
confirmation_count: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&Lockout> for RpcLockout {
|
impl From<&Lockout> for DisplayLockout {
|
||||||
fn from(lockout: &Lockout) -> Self {
|
fn from(lockout: &Lockout) -> Self {
|
||||||
Self {
|
Self {
|
||||||
slot: lockout.slot,
|
slot: lockout.slot,
|
||||||
@ -91,14 +93,14 @@ impl From<&Lockout> for RpcLockout {
|
|||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct RpcAuthorizedVoters {
|
struct DisplayAuthorizedVoters {
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
authorized_voter: String,
|
authorized_voter: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct RpcPriorVoters {
|
struct DisplayPriorVoters {
|
||||||
authorized_pubkey: String,
|
authorized_pubkey: String,
|
||||||
epoch_of_last_authorized_switch: Epoch,
|
epoch_of_last_authorized_switch: Epoch,
|
||||||
target_epoch: Epoch,
|
target_epoch: Epoch,
|
||||||
@ -106,7 +108,7 @@ struct RpcPriorVoters {
|
|||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct RpcEpochCredits {
|
struct DisplayEpochCredits {
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
credits: u64,
|
credits: u64,
|
||||||
previous_credits: u64,
|
previous_credits: u64,
|
||||||
|
Reference in New Issue
Block a user