Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #652 from ethcore/tx_queue_rpc
Browse files Browse the repository at this point in the history
Transaction queue exposed via JSON rpc.
  • Loading branch information
debris committed Mar 11, 2016
2 parents 8d6ea3a + cc47c80 commit eb2171e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
13 changes: 12 additions & 1 deletion rpc/src/v1/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,25 @@ impl<C, S> Eth for EthClient<C, S> where C: BlockChainClient + 'static, S: SyncP
}
}

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()),
None => Ok(Value::Null)
})
}

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)) {
Expand Down
13 changes: 8 additions & 5 deletions rpc/src/v1/traits/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ pub trait Eth: Sized + Send + Sync + 'static {

/// Returns block with given number.
fn block_by_number(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }

/// 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!() }
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions sync/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,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)]
Expand Down Expand Up @@ -256,6 +258,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()
Expand Down

0 comments on commit eb2171e

Please sign in to comment.