From a0451a3cb5a360af459ecc8afa498b6181695e31 Mon Sep 17 00:00:00 2001 From: debris Date: Mon, 8 Feb 2016 12:13:05 +0100 Subject: [PATCH] eth_getBlockXXX takes into account include_tx param --- rpc/src/v1/impls/eth.rs | 13 ++++++++++--- rpc/src/v1/types/block.rs | 27 ++++++++++++++++++++++----- rpc/src/v1/types/mod.rs | 2 +- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index f90995ffe..606a1ba6d 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -23,7 +23,7 @@ use util::sha3::*; use ethcore::client::*; use ethcore::views::*; use v1::traits::{Eth, EthFilter}; -use v1::types::{Block, BlockNumber, Bytes, SyncStatus}; +use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus}; /// Eth rpc implementation. pub struct EthClient { @@ -125,7 +125,7 @@ impl Eth for EthClient { fn block(&self, params: Params) -> Result { match from_params::<(H256, bool)>(params) { - Ok((hash, _include_txs)) => match (self.client.block_header(&hash), self.client.block_total_difficulty(&hash)) { + Ok((hash, include_txs)) => match (self.client.block_header(&hash), self.client.block_total_difficulty(&hash)) { (Some(bytes), Some(total_difficulty)) => { let view = HeaderView::new(&bytes); let block = Block { @@ -145,7 +145,14 @@ impl Eth for EthClient { difficulty: view.difficulty(), total_difficulty: total_difficulty, uncles: vec![], - transactions: vec![] + transactions: { + if include_txs { + BlockTransactions::Hashes(vec![]) + } else { + BlockTransactions::Full(vec![]) + } + }, + extra_data: Bytes::default() }; to_value(&block) }, diff --git a/rpc/src/v1/types/block.rs b/rpc/src/v1/types/block.rs index 92ff5c8a6..ae5e59fbd 100644 --- a/rpc/src/v1/types/block.rs +++ b/rpc/src/v1/types/block.rs @@ -14,10 +14,28 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use serde::{Serialize, Serializer}; use util::hash::*; use util::uint::*; +use v1::types::{Bytes, Transaction}; -#[derive(Default, Debug, Serialize)] +#[derive(Debug)] +pub enum BlockTransactions { + Hashes(Vec), + Full(Vec) +} + +impl Serialize for BlockTransactions { + fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> + where S: Serializer { + match *self { + BlockTransactions::Hashes(ref hashes) => hashes.serialize(serializer), + BlockTransactions::Full(ref ts) => ts.serialize(serializer) + } + } +} + +#[derive(Debug, Serialize)] pub struct Block { pub hash: H256, #[serde(rename="parentHash")] @@ -38,9 +56,8 @@ pub struct Block { pub gas_used: U256, #[serde(rename="gasLimit")] pub gas_limit: U256, - // TODO: figure out how to properly serialize bytes - //#[serde(rename="extraData")] - //extra_data: Vec, + #[serde(rename="extraData")] + pub extra_data: Bytes, #[serde(rename="logsBloom")] pub logs_bloom: H2048, pub timestamp: U256, @@ -48,5 +65,5 @@ pub struct Block { #[serde(rename="totalDifficulty")] pub total_difficulty: U256, pub uncles: Vec, - pub transactions: Vec + pub transactions: BlockTransactions } diff --git a/rpc/src/v1/types/mod.rs b/rpc/src/v1/types/mod.rs index 226e7e9a6..2286c69a1 100644 --- a/rpc/src/v1/types/mod.rs +++ b/rpc/src/v1/types/mod.rs @@ -20,7 +20,7 @@ mod bytes; mod sync; mod transaction; -pub use self::block::Block; +pub use self::block::{Block, BlockTransactions}; pub use self::block_number::BlockNumber; pub use self::bytes::Bytes; pub use self::sync::SyncStatus;