Skip to content

Commit

Permalink
Add blockhash-queue-length to solana fees
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed May 21, 2020
1 parent deb1259 commit 468e06b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
seed,
program_id,
} => process_create_address_with_seed(config, from_pubkey.as_ref(), &seed, &program_id),
CliCommand::Fees => process_fees(&rpc_client),
CliCommand::Fees => process_fees(&rpc_client, config),
CliCommand::GetBlockTime { slot } => process_get_block_time(&rpc_client, config, *slot),
CliCommand::GetGenesisHash => process_get_genesis_hash(&rpc_client),
CliCommand::GetEpochInfo { commitment_config } => {
Expand Down
33 changes: 32 additions & 1 deletion cli/src/cli_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use inflector::cases::titlecase::to_title_case;
use serde::Serialize;
use serde_json::{Map, Value};
use solana_client::rpc_response::{
RpcAccountBalance, RpcKeyedAccount, RpcSupply, RpcVoteAccountInfo,
RpcAccountBalance, RpcBlockhashQueueLength, RpcKeyedAccount, RpcSupply, RpcVoteAccountInfo,
};
use solana_sdk::{
clock::{self, Epoch, Slot, UnixTimestamp},
Expand Down Expand Up @@ -981,3 +981,34 @@ impl fmt::Display for CliSupply {
Ok(())
}
}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CliFees {
pub slot: Slot,
pub blockhash: String,
pub lamports_per_signature: u64,
pub blockhash_queue_length: RpcBlockhashQueueLength,
}

impl fmt::Display for CliFees {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln_name_value(f, "Blockhash:", &self.blockhash)?;
writeln_name_value(
f,
"Lamports per signature:",
&self.lamports_per_signature.to_string(),
)?;
writeln_name_value(f, "Slot:", &self.slot.to_string())?;
writeln_name_value(
f,
"Blockhash queue length:",
&format!(
"{} (epoch {})",
&self.blockhash_queue_length.blockhash_queue_length,
&self.blockhash_queue_length.epoch
),
)?;
Ok(())
}
}
18 changes: 11 additions & 7 deletions cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,17 @@ pub fn process_cluster_version(rpc_client: &RpcClient) -> ProcessResult {
Ok(remote_version.solana_core)
}

pub fn process_fees(rpc_client: &RpcClient) -> ProcessResult {
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;

Ok(format!(
"blockhash: {}\nlamports per signature: {}",
recent_blockhash, fee_calculator.lamports_per_signature
))
pub fn process_fees(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult {
let result = rpc_client.get_recent_blockhash_with_commitment(CommitmentConfig::default())?;
let (recent_blockhash, fee_calculator) = result.value;
let blockhash_queue_length = rpc_client.get_blockhash_queue_length()?;
let fees = CliFees {
slot: result.context.slot,
blockhash: recent_blockhash.to_string(),
lamports_per_signature: fee_calculator.lamports_per_signature,
blockhash_queue_length: blockhash_queue_length.value,
};
Ok(config.output_format.formatted_string(&fees))
}

pub fn process_leader_schedule(rpc_client: &RpcClient) -> ProcessResult {
Expand Down

0 comments on commit 468e06b

Please sign in to comment.