Rename getBlock to getConfirmedBlock; remove getBlocksSince (#6961)

automerge
This commit is contained in:
Tyera Eulberg 2019-11-14 14:14:42 -07:00 committed by Grimes
parent 79d7090867
commit 03f7f0d18c
1 changed files with 19 additions and 33 deletions

View File

@ -17,9 +17,7 @@ use solana_client::rpc_request::{
RpcVoteAccountStatus, RpcVoteAccountStatus,
}; };
use solana_drone::drone::request_airdrop_transaction; use solana_drone::drone::request_airdrop_transaction;
use solana_ledger::{ use solana_ledger::{bank_forks::BankForks, blocktree::Blocktree};
bank_forks::BankForks, blocktree::Blocktree, rooted_slot_iterator::RootedSlotIterator,
};
use solana_runtime::bank::Bank; use solana_runtime::bank::Bank;
use solana_sdk::{ use solana_sdk::{
account::Account, account::Account,
@ -306,18 +304,14 @@ impl JsonRpcRequestProcessor {
} }
} }
pub fn get_blocks_since(&self, slot: Slot) -> Result<Vec<Slot>> { // The `get_confirmed_block` method is not fully implemented. It currenlty returns a batch of
Ok(RootedSlotIterator::new(slot, &self.blocktree) // test transaction tuples (Transaction, transaction::Result) to demonstrate message format and
.map_err(|err| Error::invalid_params(format!("Slot {:?}: {:?}", slot, err)))?
.map(|(slot, _)| slot)
.collect())
}
// The `get_block` method is not fully implemented. It currenlty returns a batch of test transaction
// tuples (Transaction, transaction::Result) to demonstrate message format and
// TransactionErrors. Transaction count == slot, and transaction keys are derived // TransactionErrors. Transaction count == slot, and transaction keys are derived
// deterministically to allow testers to track the pubkeys across slots. // deterministically to allow testers to track the pubkeys across slots.
pub fn get_block(&self, slot: Slot) -> Result<Vec<(Vec<u8>, transaction::Result<()>)>> { pub fn get_confirmed_block(
&self,
slot: Slot,
) -> Result<Vec<(Transaction, transaction::Result<()>)>> {
Ok(make_test_transactions(slot)) Ok(make_test_transactions(slot))
} }
} }
@ -523,15 +517,12 @@ pub trait RpcSol {
#[rpc(meta, name = "setLogFilter")] #[rpc(meta, name = "setLogFilter")]
fn set_log_filter(&self, _meta: Self::Metadata, filter: String) -> Result<()>; fn set_log_filter(&self, _meta: Self::Metadata, filter: String) -> Result<()>;
#[rpc(meta, name = "getBlocksSince")] #[rpc(meta, name = "getConfirmedBlock")]
fn get_blocks_since(&self, meta: Self::Metadata, slot: Slot) -> Result<Vec<Slot>>; fn get_confirmed_block(
#[rpc(meta, name = "getBlock")]
fn get_block(
&self, &self,
meta: Self::Metadata, meta: Self::Metadata,
slot: Slot, slot: Slot,
) -> Result<Vec<(Vec<u8>, transaction::Result<()>)>>; ) -> Result<Vec<(Transaction, transaction::Result<()>)>>;
} }
pub struct RpcSolImpl; pub struct RpcSolImpl;
@ -976,26 +967,22 @@ impl RpcSol for RpcSolImpl {
Ok(()) Ok(())
} }
fn get_blocks_since(&self, meta: Self::Metadata, slot: Slot) -> Result<Vec<Slot>> { fn get_confirmed_block(
meta.request_processor
.read()
.unwrap()
.get_blocks_since(slot)
}
fn get_block(
&self, &self,
meta: Self::Metadata, meta: Self::Metadata,
slot: Slot, slot: Slot,
) -> Result<Vec<(Vec<u8>, transaction::Result<()>)>> { ) -> Result<Vec<(Transaction, transaction::Result<()>)>> {
meta.request_processor.read().unwrap().get_block(slot) meta.request_processor
.read()
.unwrap()
.get_confirmed_block(slot)
} }
} }
fn make_test_transactions(count: u64) -> Vec<(Vec<u8>, transaction::Result<()>)> { fn make_test_transactions(count: u64) -> Vec<(Transaction, transaction::Result<()>)> {
let seed = [42u8; 32]; let seed = [42u8; 32];
let keys = GenKeys::new(seed).gen_n_keypairs(count + 1); let keys = GenKeys::new(seed).gen_n_keypairs(count + 1);
let mut transactions: Vec<(Vec<u8>, transaction::Result<()>)> = Vec::new(); let mut transactions: Vec<(Transaction, transaction::Result<()>)> = Vec::new();
for x in 0..count { for x in 0..count {
let tx = system_transaction::transfer( let tx = system_transaction::transfer(
&keys[x as usize], &keys[x as usize],
@ -1003,7 +990,6 @@ fn make_test_transactions(count: u64) -> Vec<(Vec<u8>, transaction::Result<()>)>
123, 123,
Hash::default(), Hash::default(),
); );
let wire_transaction = serialize(&tx).unwrap();
let status = if x % 3 == 0 { let status = if x % 3 == 0 {
Ok(()) Ok(())
} else if x % 3 == 1 { } else if x % 3 == 1 {
@ -1017,7 +1003,7 @@ fn make_test_transactions(count: u64) -> Vec<(Vec<u8>, transaction::Result<()>)>
InstructionError::CustomError(3), InstructionError::CustomError(3),
)) ))
}; };
transactions.push((wire_transaction, status)) transactions.push((tx, status))
} }
transactions transactions
} }