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

Size for blocks #1668

Merged
merged 2 commits into from
Jul 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions rpc/src/v1/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl<C, S: ?Sized, M, EM> EthClient<C, S, M, EM> 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(),
Expand All @@ -107,12 +108,9 @@ impl<C, S: ?Sized, M, EM> EthClient<C, S, M, EM> 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())
};
Expand Down Expand Up @@ -142,6 +140,7 @@ impl<C, S: ?Sized, M, EM> EthClient<C, S, M, EM> 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(),
Expand Down
9 changes: 5 additions & 4 deletions rpc/src/v1/tests/mocked/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"#;
Expand All @@ -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() {
Expand Down
9 changes: 6 additions & 3 deletions rpc/src/v1/types/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ pub struct Block {
/// Uncles' hashes
pub uncles: Vec<H256>,
/// Transactions
pub transactions: BlockTransactions
pub transactions: BlockTransactions,
/// Size in bytes
pub size: Option<usize>,
}

#[cfg(test)]
Expand Down Expand Up @@ -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}"#);
}
}