eth_getBlockXXX takes into account include_tx param
This commit is contained in:
		
							parent
							
								
									90f965cf53
								
							
						
					
					
						commit
						a0451a3cb5
					
				@ -23,7 +23,7 @@ use util::sha3::*;
 | 
				
			|||||||
use ethcore::client::*;
 | 
					use ethcore::client::*;
 | 
				
			||||||
use ethcore::views::*;
 | 
					use ethcore::views::*;
 | 
				
			||||||
use v1::traits::{Eth, EthFilter};
 | 
					use v1::traits::{Eth, EthFilter};
 | 
				
			||||||
use v1::types::{Block, BlockNumber, Bytes, SyncStatus};
 | 
					use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Eth rpc implementation.
 | 
					/// Eth rpc implementation.
 | 
				
			||||||
pub struct EthClient {
 | 
					pub struct EthClient {
 | 
				
			||||||
@ -125,7 +125,7 @@ impl Eth for EthClient {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	fn block(&self, params: Params) -> Result<Value, Error> {
 | 
						fn block(&self, params: Params) -> Result<Value, Error> {
 | 
				
			||||||
		match from_params::<(H256, bool)>(params) {
 | 
							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)) => {
 | 
									(Some(bytes), Some(total_difficulty)) => {
 | 
				
			||||||
					let view = HeaderView::new(&bytes);
 | 
										let view = HeaderView::new(&bytes);
 | 
				
			||||||
					let block = Block {
 | 
										let block = Block {
 | 
				
			||||||
@ -145,7 +145,14 @@ impl Eth for EthClient {
 | 
				
			|||||||
						difficulty: view.difficulty(),
 | 
											difficulty: view.difficulty(),
 | 
				
			||||||
						total_difficulty: total_difficulty,
 | 
											total_difficulty: total_difficulty,
 | 
				
			||||||
						uncles: vec![],
 | 
											uncles: vec![],
 | 
				
			||||||
						transactions: vec![]
 | 
											transactions: {
 | 
				
			||||||
 | 
												if include_txs {
 | 
				
			||||||
 | 
													BlockTransactions::Hashes(vec![])
 | 
				
			||||||
 | 
												} else {
 | 
				
			||||||
 | 
													BlockTransactions::Full(vec![])
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
 | 
											},
 | 
				
			||||||
 | 
											extra_data: Bytes::default()
 | 
				
			||||||
					};
 | 
										};
 | 
				
			||||||
					to_value(&block)
 | 
										to_value(&block)
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
 | 
				
			|||||||
@ -14,10 +14,28 @@
 | 
				
			|||||||
// You should have received a copy of the GNU General Public License
 | 
					// You should have received a copy of the GNU General Public License
 | 
				
			||||||
// along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | 
					// along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use serde::{Serialize, Serializer};
 | 
				
			||||||
use util::hash::*;
 | 
					use util::hash::*;
 | 
				
			||||||
use util::uint::*;
 | 
					use util::uint::*;
 | 
				
			||||||
 | 
					use v1::types::{Bytes, Transaction};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Default, Debug, Serialize)]
 | 
					#[derive(Debug)]
 | 
				
			||||||
 | 
					pub enum BlockTransactions {
 | 
				
			||||||
 | 
						Hashes(Vec<U256>),
 | 
				
			||||||
 | 
						Full(Vec<Transaction>)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Serialize for BlockTransactions {
 | 
				
			||||||
 | 
						fn serialize<S>(&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 struct Block {
 | 
				
			||||||
	pub hash: H256,
 | 
						pub hash: H256,
 | 
				
			||||||
	#[serde(rename="parentHash")]
 | 
						#[serde(rename="parentHash")]
 | 
				
			||||||
@ -38,9 +56,8 @@ pub struct Block {
 | 
				
			|||||||
	pub gas_used: U256,
 | 
						pub gas_used: U256,
 | 
				
			||||||
	#[serde(rename="gasLimit")]
 | 
						#[serde(rename="gasLimit")]
 | 
				
			||||||
	pub gas_limit: U256,
 | 
						pub gas_limit: U256,
 | 
				
			||||||
	// TODO: figure out how to properly serialize bytes
 | 
						#[serde(rename="extraData")]
 | 
				
			||||||
	//#[serde(rename="extraData")]
 | 
						pub extra_data: Bytes,
 | 
				
			||||||
	//extra_data: Vec<u8>,
 | 
					 | 
				
			||||||
	#[serde(rename="logsBloom")]
 | 
						#[serde(rename="logsBloom")]
 | 
				
			||||||
	pub logs_bloom: H2048,
 | 
						pub logs_bloom: H2048,
 | 
				
			||||||
	pub timestamp: U256,
 | 
						pub timestamp: U256,
 | 
				
			||||||
@ -48,5 +65,5 @@ pub struct Block {
 | 
				
			|||||||
	#[serde(rename="totalDifficulty")]
 | 
						#[serde(rename="totalDifficulty")]
 | 
				
			||||||
	pub total_difficulty: U256,
 | 
						pub total_difficulty: U256,
 | 
				
			||||||
	pub uncles: Vec<U256>,
 | 
						pub uncles: Vec<U256>,
 | 
				
			||||||
	pub transactions: Vec<U256>
 | 
						pub transactions: BlockTransactions
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -20,7 +20,7 @@ mod bytes;
 | 
				
			|||||||
mod sync;
 | 
					mod sync;
 | 
				
			||||||
mod transaction;
 | 
					mod transaction;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub use self::block::Block;
 | 
					pub use self::block::{Block, BlockTransactions};
 | 
				
			||||||
pub use self::block_number::BlockNumber;
 | 
					pub use self::block_number::BlockNumber;
 | 
				
			||||||
pub use self::bytes::Bytes;
 | 
					pub use self::bytes::Bytes;
 | 
				
			||||||
pub use self::sync::SyncStatus;
 | 
					pub use self::sync::SyncStatus;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user