From 861c8d0701779254ec2b65a9a2ae4f89803de89d Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 19 Jul 2016 20:40:18 +0200 Subject: [PATCH] Size for blocks (#1668) * Add size field for blocks. * Ignore invalid test. --- rpc/src/v1/impls/eth.rs | 11 +++++------ rpc/src/v1/tests/mocked/eth.rs | 9 +++++---- rpc/src/v1/types/block.rs | 9 ++++++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 0bece9cd4..a72b243a6 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -91,6 +91,7 @@ impl EthClient where let view = block_view.header_view(); let block = Block { hash: Some(view.sha3().into()), + size: Some(bytes.len()), parent_hash: view.parent_hash().into(), uncles_hash: view.uncles_hash().into(), author: view.author().into(), @@ -107,12 +108,9 @@ impl EthClient where total_difficulty: total_difficulty.into(), seal_fields: view.seal().into_iter().map(|f| decode(&f)).map(Bytes::new).collect(), uncles: block_view.uncle_hashes().into_iter().map(Into::into).collect(), - transactions: { - if include_txs { - BlockTransactions::Full(block_view.localized_transactions().into_iter().map(Into::into).collect()) - } else { - BlockTransactions::Hashes(block_view.transaction_hashes().into_iter().map(Into::into).collect()) - } + transactions: match include_txs { + true => BlockTransactions::Full(block_view.localized_transactions().into_iter().map(Into::into).collect()), + false => BlockTransactions::Hashes(block_view.transaction_hashes().into_iter().map(Into::into).collect()), }, extra_data: Bytes::new(view.extra_data()) }; @@ -142,6 +140,7 @@ impl EthClient where let block = Block { hash: Some(uncle.hash().into()), + size: None, parent_hash: uncle.parent_hash.into(), uncles_hash: uncle.uncles_hash.into(), author: uncle.author.into(), diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index 39e22ebac..9e7331f00 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -699,6 +699,11 @@ fn rpc_eth_transaction_receipt_null() { assert_eq!(tester.io.handle_request(request), Some(response.to_owned())); } +// These tests are incorrect: their output is undefined as long as eth_getCompilers is []. +// Will ignore for now, but should probably be replaced by more substantial tests which check +// the output of eth_getCompilers to determine whether to test. CI systems can then be preinstalled +// with solc/serpent/lllc and they'll be proper again. +#[ignore] #[test] fn rpc_eth_compilers() { let request = r#"{"jsonrpc": "2.0", "method": "eth_getCompilers", "params": [], "id": 1}"#; @@ -707,10 +712,6 @@ fn rpc_eth_compilers() { assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned())); } -// These tests are incorrect: their output is undefined as long as eth_getCompilers is []. -// Will ignore for now, but should probably be replaced by more substantial tests which check -// the output of eth_getCompilers to determine whether to test. CI systems can then be preinstalled -// with solc/serpent/lllc and they'll be proper again. #[ignore] #[test] fn rpc_eth_compile_lll() { diff --git a/rpc/src/v1/types/block.rs b/rpc/src/v1/types/block.rs index 63f596d4a..c1de9a276 100644 --- a/rpc/src/v1/types/block.rs +++ b/rpc/src/v1/types/block.rs @@ -88,7 +88,9 @@ pub struct Block { /// Uncles' hashes pub uncles: Vec, /// Transactions - pub transactions: BlockTransactions + pub transactions: BlockTransactions, + /// Size in bytes + pub size: Option, } #[cfg(test)] @@ -129,10 +131,11 @@ mod tests { total_difficulty: U256::default(), seal_fields: vec![Bytes::default(), Bytes::default()], uncles: vec![], - transactions: BlockTransactions::Hashes(vec![].into()) + transactions: BlockTransactions::Hashes(vec![].into()), + size: Some(69usize), }; let serialized = serde_json::to_string(&block).unwrap(); - assert_eq!(serialized, r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","sha3Uncles":"0x0000000000000000000000000000000000000000000000000000000000000000","author":"0x0000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","number":"0x00","gasUsed":"0x00","gasLimit":"0x00","extraData":"0x","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x00","difficulty":"0x00","totalDifficulty":"0x00","sealFields":["0x","0x"],"uncles":[],"transactions":[]}"#); + assert_eq!(serialized, r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","sha3Uncles":"0x0000000000000000000000000000000000000000000000000000000000000000","author":"0x0000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","number":"0x00","gasUsed":"0x00","gasLimit":"0x00","extraData":"0x","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x00","difficulty":"0x00","totalDifficulty":"0x00","sealFields":["0x","0x"],"uncles":[],"transactions":[],"size":69}"#); } }