feat: get epoch schedule rpc, update cli (#6500)

This commit is contained in:
Sunny Gleason
2019-10-22 16:41:18 -04:00
committed by GitHub
parent 4f25013954
commit 0b2d4f32fa
4 changed files with 66 additions and 20 deletions

View File

@ -18,6 +18,7 @@ use solana_ledger::bank_forks::BankForks;
use solana_runtime::bank::Bank;
use solana_sdk::{
account::Account,
epoch_schedule::EpochSchedule,
fee_calculator::FeeCalculator,
hash::Hash,
inflation::Inflation,
@ -101,6 +102,10 @@ impl JsonRpcRequestProcessor {
Ok(self.bank().inflation())
}
pub fn get_epoch_schedule(&self) -> Result<EpochSchedule> {
Ok(*self.bank().epoch_schedule())
}
pub fn get_balance(&self, pubkey: &Pubkey) -> u64 {
self.bank().get_balance(&pubkey)
}
@ -289,6 +294,9 @@ pub trait RpcSol {
#[rpc(meta, name = "getInflation")]
fn get_inflation(&self, _: Self::Metadata) -> Result<Inflation>;
#[rpc(meta, name = "getEpochSchedule")]
fn get_epoch_schedule(&self, _: Self::Metadata) -> Result<EpochSchedule>;
#[rpc(meta, name = "getBalance")]
fn get_balance(&self, _: Self::Metadata, _: String) -> Result<u64>;
@ -439,6 +447,16 @@ impl RpcSol for RpcSolImpl {
.unwrap())
}
fn get_epoch_schedule(&self, meta: Self::Metadata) -> Result<EpochSchedule> {
debug!("get_epoch_schedule rpc request received");
Ok(meta
.request_processor
.read()
.unwrap()
.get_epoch_schedule()
.unwrap())
}
fn get_balance(&self, meta: Self::Metadata, id: String) -> Result<u64> {
debug!("get_balance rpc request received: {:?}", id);
let pubkey = verify_pubkey(id)?;
@ -991,6 +1009,28 @@ pub mod tests {
assert_eq!(inflation, bank.inflation());
}
#[test]
fn test_rpc_get_epoch_schedule() {
let bob_pubkey = Pubkey::new_rand();
let RpcHandler { io, meta, bank, .. } = start_rpc_handler_with_tx(&bob_pubkey);
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getEpochSchedule"}}"#);
let rep = io.handle_request_sync(&req, meta);
let res: Response = serde_json::from_str(&rep.expect("actual response"))
.expect("actual response deserialization");
let epoch_schedule: EpochSchedule = if let Response::Single(res) = res {
if let Output::Success(res) = res {
serde_json::from_value(res.result).unwrap()
} else {
panic!("Expected success");
}
} else {
panic!("Expected single response");
};
assert_eq!(epoch_schedule, *bank.epoch_schedule());
}
#[test]
fn test_rpc_get_account_info() {
let bob_pubkey = Pubkey::new_rand();