Skip to content

Commit

Permalink
s/Rpc/Display
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Jun 30, 2020
1 parent 592f882 commit 6e7149f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
12 changes: 6 additions & 6 deletions account-decoder/src/parse_nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use solana_sdk::{
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)
.map_err(|_| ParseAccountError::from(InstructionError::InvalidAccountData))?;
let nonce_state = nonce_state.convert_to_current();
match nonce_state {
State::Uninitialized => Ok(RpcNonceState::Uninitialized),
State::Initialized(data) => Ok(RpcNonceState::Initialized(RpcNonceData {
State::Uninitialized => Ok(DisplayNonceState::Uninitialized),
State::Initialized(data) => Ok(DisplayNonceState::Initialized(DisplayNonceData {
authority: data.authority.to_string(),
blockhash: data.blockhash.to_string(),
fee_calculator: data.fee_calculator,
Expand All @@ -21,14 +21,14 @@ pub fn parse_nonce(data: &[u8]) -> Result<RpcNonceState, ParseAccountError> {

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum RpcNonceState {
pub enum DisplayNonceState {
Uninitialized,
Initialized(RpcNonceData),
Initialized(DisplayNonceData),
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcNonceData {
pub struct DisplayNonceData {
pub authority: String,
pub blockhash: String,
pub fee_calculator: FeeCalculator,
Expand Down
40 changes: 21 additions & 19 deletions account-decoder/src/parse_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use solana_sdk::{
};
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 epoch_credits = vote_state
.epoch_credits()
.iter()
.map(|(epoch, credits, previous_credits)| RpcEpochCredits {
.map(|(epoch, credits, previous_credits)| DisplayEpochCredits {
epoch: *epoch,
credits: *credits,
previous_credits: *previous_credits,
Expand All @@ -19,15 +19,15 @@ pub fn parse_vote(data: &[u8]) -> Result<RpcVoteState, ParseAccountError> {
let votes = vote_state
.votes
.iter()
.map(|lockout| RpcLockout {
.map(|lockout| DisplayLockout {
slot: lockout.slot,
confirmation_count: lockout.confirmation_count,
})
.collect();
let authorized_voters = vote_state
.authorized_voters()
.iter()
.map(|(epoch, authorized_voter)| RpcAuthorizedVoters {
.map(|(epoch, authorized_voter)| DisplayAuthorizedVoters {
epoch: *epoch,
authorized_voter: authorized_voter.to_string(),
})
Expand All @@ -38,14 +38,16 @@ pub fn parse_vote(data: &[u8]) -> Result<RpcVoteState, ParseAccountError> {
.iter()
.filter(|(pubkey, _, _)| pubkey != &Pubkey::default())
.map(
|(authorized_pubkey, epoch_of_last_authorized_switch, target_epoch)| RpcPriorVoters {
authorized_pubkey: authorized_pubkey.to_string(),
epoch_of_last_authorized_switch: *epoch_of_last_authorized_switch,
target_epoch: *target_epoch,
|(authorized_pubkey, epoch_of_last_authorized_switch, target_epoch)| {
DisplayPriorVoters {
authorized_pubkey: authorized_pubkey.to_string(),
epoch_of_last_authorized_switch: *epoch_of_last_authorized_switch,
target_epoch: *target_epoch,
}
},
)
.collect();
Ok(RpcVoteState {
Ok(DisplayVoteState {
node_pubkey: vote_state.node_pubkey.to_string(),
authorized_withdrawer: vote_state.authorized_withdrawer.to_string(),
commission: vote_state.commission,
Expand All @@ -61,26 +63,26 @@ pub fn parse_vote(data: &[u8]) -> Result<RpcVoteState, ParseAccountError> {
/// A duplicate representation of VoteState for pretty JSON serialization
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcVoteState {
pub struct DisplayVoteState {
node_pubkey: String,
authorized_withdrawer: String,
commission: u8,
votes: Vec<RpcLockout>,
votes: Vec<DisplayLockout>,
root_slot: Option<Slot>,
authorized_voters: Vec<RpcAuthorizedVoters>,
prior_voters: Vec<RpcPriorVoters>,
epoch_credits: Vec<RpcEpochCredits>,
authorized_voters: Vec<DisplayAuthorizedVoters>,
prior_voters: Vec<DisplayPriorVoters>,
epoch_credits: Vec<DisplayEpochCredits>,
last_timestamp: BlockTimestamp,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct RpcLockout {
struct DisplayLockout {
slot: Slot,
confirmation_count: u32,
}

impl From<&Lockout> for RpcLockout {
impl From<&Lockout> for DisplayLockout {
fn from(lockout: &Lockout) -> Self {
Self {
slot: lockout.slot,
Expand All @@ -91,22 +93,22 @@ impl From<&Lockout> for RpcLockout {

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct RpcAuthorizedVoters {
struct DisplayAuthorizedVoters {
epoch: Epoch,
authorized_voter: String,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct RpcPriorVoters {
struct DisplayPriorVoters {
authorized_pubkey: String,
epoch_of_last_authorized_switch: Epoch,
target_epoch: Epoch,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct RpcEpochCredits {
struct DisplayEpochCredits {
epoch: Epoch,
credits: u64,
previous_credits: u64,
Expand Down

0 comments on commit 6e7149f

Please sign in to comment.