Returning number of transactions pending in block not queue
This commit is contained in:
parent
ecfcc4f3b6
commit
884f2dd873
@ -108,4 +108,6 @@ pub struct MinerStatus {
|
|||||||
pub transaction_queue_pending: usize,
|
pub transaction_queue_pending: usize,
|
||||||
/// Number of transactions in queue with state `future` (not yet ready to be included in block)
|
/// Number of transactions in queue with state `future` (not yet ready to be included in block)
|
||||||
pub transaction_queue_future: usize,
|
pub transaction_queue_future: usize,
|
||||||
|
/// Number of transactions included in currently mined block
|
||||||
|
pub block_pending: usize,
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ use std::sync::atomic::AtomicBool;
|
|||||||
use util::{H256, U256, Address, Bytes, Uint};
|
use util::{H256, U256, Address, Bytes, Uint};
|
||||||
use ethcore::views::{BlockView};
|
use ethcore::views::{BlockView};
|
||||||
use ethcore::client::{BlockChainClient, BlockId};
|
use ethcore::client::{BlockChainClient, BlockId};
|
||||||
use ethcore::block::{ClosedBlock};
|
use ethcore::block::{ClosedBlock, IsBlock};
|
||||||
use ethcore::error::{Error};
|
use ethcore::error::{Error};
|
||||||
use ethcore::transaction::SignedTransaction;
|
use ethcore::transaction::SignedTransaction;
|
||||||
use super::{MinerService, MinerStatus, TransactionQueue};
|
use super::{MinerService, MinerStatus, TransactionQueue};
|
||||||
@ -104,9 +104,11 @@ impl MinerService for Miner {
|
|||||||
|
|
||||||
fn status(&self) -> MinerStatus {
|
fn status(&self) -> MinerStatus {
|
||||||
let status = self.transaction_queue.lock().unwrap().status();
|
let status = self.transaction_queue.lock().unwrap().status();
|
||||||
|
let block = self.sealing_block.lock().unwrap();
|
||||||
MinerStatus {
|
MinerStatus {
|
||||||
transaction_queue_pending: status.pending,
|
transaction_queue_pending: status.pending,
|
||||||
transaction_queue_future: status.future,
|
transaction_queue_future: status.future,
|
||||||
|
block_pending: block.as_ref().map_or(0, |b| b.transactions().len()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
|
|||||||
fn block_transaction_count_by_number(&self, params: Params) -> Result<Value, Error> {
|
fn block_transaction_count_by_number(&self, params: Params) -> Result<Value, Error> {
|
||||||
from_params::<(BlockNumber,)>(params)
|
from_params::<(BlockNumber,)>(params)
|
||||||
.and_then(|(block_number,)| match block_number {
|
.and_then(|(block_number,)| match block_number {
|
||||||
BlockNumber::Pending => to_value(&U256::from(take_weak!(self.miner).status().transaction_queue_pending)),
|
BlockNumber::Pending => to_value(&U256::from(take_weak!(self.miner).status().block_pending)),
|
||||||
_ => to_value(&take_weak!(self.client).block(block_number.into())
|
_ => to_value(&take_weak!(self.client).block(block_number.into())
|
||||||
.map_or_else(U256::zero, |bytes| U256::from(BlockView::new(&bytes).transactions_count())))
|
.map_or_else(U256::zero, |bytes| U256::from(BlockView::new(&bytes).transactions_count())))
|
||||||
})
|
})
|
||||||
|
@ -242,6 +242,20 @@ fn rpc_eth_transaction_count_by_number() {
|
|||||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rpc_eth_transaction_count_by_number_pending() {
|
||||||
|
let request = r#"{
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": "eth_getBlockTransactionCountByNumber",
|
||||||
|
"params": ["pending"],
|
||||||
|
"id": 1
|
||||||
|
}"#;
|
||||||
|
let response = r#"{"jsonrpc":"2.0","result":"0x01","id":1}"#;
|
||||||
|
|
||||||
|
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rpc_eth_uncle_count_by_block_hash() {
|
fn rpc_eth_uncle_count_by_block_hash() {
|
||||||
let request = r#"{
|
let request = r#"{
|
||||||
|
@ -27,7 +27,13 @@ pub struct TestMinerService;
|
|||||||
impl MinerService for TestMinerService {
|
impl MinerService for TestMinerService {
|
||||||
|
|
||||||
/// Returns miner's status.
|
/// Returns miner's status.
|
||||||
fn status(&self) -> MinerStatus { unimplemented!(); }
|
fn status(&self) -> MinerStatus {
|
||||||
|
MinerStatus {
|
||||||
|
transaction_queue_pending: 0,
|
||||||
|
transaction_queue_future: 0,
|
||||||
|
block_pending: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Imports transactions to transaction queue.
|
/// Imports transactions to transaction queue.
|
||||||
fn import_transactions<T>(&self, _transactions: Vec<SignedTransaction>, _fetch_nonce: T) -> Result<(), Error> where T: Fn(&Address) -> U256 { unimplemented!(); }
|
fn import_transactions<T>(&self, _transactions: Vec<SignedTransaction>, _fetch_nonce: T) -> Result<(), Error> where T: Fn(&Address) -> U256 { unimplemented!(); }
|
||||||
|
Loading…
Reference in New Issue
Block a user