Exposing transaction queue pending in RPC
This commit is contained in:
parent
c6934431d1
commit
c889d9b3eb
@ -152,7 +152,7 @@ impl Eth for EthClient {
|
||||
}
|
||||
}
|
||||
|
||||
fn block_transaction_count(&self, params: Params) -> Result<Value, Error> {
|
||||
fn block_transaction_count_by_hash(&self, params: Params) -> Result<Value, Error> {
|
||||
from_params::<(H256,)>(params)
|
||||
.and_then(|(hash,)| match take_weak!(self.client).block(BlockId::Hash(hash)) {
|
||||
Some(bytes) => to_value(&BlockView::new(&bytes).transactions_count()),
|
||||
@ -160,6 +160,17 @@ impl Eth for EthClient {
|
||||
})
|
||||
}
|
||||
|
||||
fn block_transaction_count_by_number(&self, params: Params) -> Result<Value, Error> {
|
||||
from_params::<(BlockNumber,)>(params)
|
||||
.and_then(|(block_number,)| match block_number {
|
||||
BlockNumber::Pending => to_value(&take_weak!(self.sync).status().transaction_queue_pending),
|
||||
_ => match take_weak!(self.client).block(block_number.into()) {
|
||||
Some(bytes) => to_value(&BlockView::new(&bytes).transactions_count()),
|
||||
None => Ok(Value::Null)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn block_uncles_count(&self, params: Params) -> Result<Value, Error> {
|
||||
from_params::<(H256,)>(params)
|
||||
.and_then(|(hash,)| match take_weak!(self.client).block(BlockId::Hash(hash)) {
|
||||
|
@ -59,8 +59,11 @@ pub trait Eth: Sized + Send + Sync + 'static {
|
||||
/// Returns the number of transactions sent from given address at given time (block number).
|
||||
fn transaction_count(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
|
||||
|
||||
/// Returns the number of transactions in a block.
|
||||
fn block_transaction_count(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
|
||||
/// Returns the number of transactions in a block given block hash.
|
||||
fn block_transaction_count_by_hash(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
|
||||
|
||||
/// Returns the number of transactions in a block given block number.
|
||||
fn block_transaction_count_by_number(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
|
||||
|
||||
/// Returns the number of uncles in a given block.
|
||||
fn block_uncles_count(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
|
||||
@ -130,8 +133,8 @@ pub trait Eth: Sized + Send + Sync + 'static {
|
||||
delegate.add_method("eth_balance", Eth::balance);
|
||||
delegate.add_method("eth_getStorageAt", Eth::storage_at);
|
||||
delegate.add_method("eth_getTransactionCount", Eth::transaction_count);
|
||||
delegate.add_method("eth_getBlockTransactionCountByHash", Eth::block_transaction_count);
|
||||
delegate.add_method("eth_getBlockTransactionCountByNumber", Eth::block_transaction_count);
|
||||
delegate.add_method("eth_getBlockTransactionCountByHash", Eth::block_transaction_count_by_hash);
|
||||
delegate.add_method("eth_getBlockTransactionCountByNumber", Eth::block_transaction_count_by_number);
|
||||
delegate.add_method("eth_getUncleCountByBlockHash", Eth::block_uncles_count);
|
||||
delegate.add_method("eth_getUncleCountByBlockNumber", Eth::block_uncles_count);
|
||||
delegate.add_method("eth_code", Eth::code_at);
|
||||
|
@ -140,6 +140,8 @@ pub struct SyncStatus {
|
||||
pub num_active_peers: usize,
|
||||
/// Heap memory used in bytes
|
||||
pub mem_used: usize,
|
||||
/// Number of pending transactions in queue
|
||||
pub transaction_queue_pending: usize,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
@ -255,6 +257,7 @@ impl ChainSync {
|
||||
blocks_total: match self.highest_block { Some(x) if x > self.starting_block => x - self.starting_block, _ => 0 },
|
||||
num_peers: self.peers.len(),
|
||||
num_active_peers: self.peers.values().filter(|p| p.asking != PeerAsking::Nothing).count(),
|
||||
transaction_queue_pending: self.transaction_queue.lock().unwrap().status().pending,
|
||||
mem_used:
|
||||
// TODO: https://github.com/servo/heapsize/pull/50
|
||||
// self.downloading_hashes.heap_size_of_children()
|
||||
|
Loading…
Reference in New Issue
Block a user