2019-01-07 11:33:07 +01:00
|
|
|
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of Parity Ethereum.
|
2016-02-05 13:40:41 +01:00
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is free software: you can redistribute it and/or modify
|
2016-02-05 13:40:41 +01:00
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is distributed in the hope that it will be useful,
|
2016-02-05 13:40:41 +01:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2019-01-07 11:33:07 +01:00
|
|
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2016-02-05 13:40:41 +01:00
|
|
|
|
2016-11-04 17:35:02 +01:00
|
|
|
use std::ops::Deref;
|
|
|
|
use std::collections::BTreeMap;
|
2017-05-23 12:26:39 +02:00
|
|
|
|
2019-02-25 14:27:28 +01:00
|
|
|
use ethereum_types::{H160, H256, U256, Bloom as H2048};
|
2017-02-13 16:38:47 +01:00
|
|
|
use serde::ser::Error;
|
2019-01-04 14:05:46 +01:00
|
|
|
use serde::{Serialize, Serializer};
|
|
|
|
use types::encoded::Header as EthHeader;
|
2019-02-25 14:27:28 +01:00
|
|
|
use v1::types::{Bytes, Transaction};
|
2016-01-26 11:37:24 +01:00
|
|
|
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Block Transactions
|
2016-02-08 12:13:05 +01:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum BlockTransactions {
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Only hashes
|
2016-02-08 14:02:47 +01:00
|
|
|
Hashes(Vec<H256>),
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Full transactions
|
2016-02-08 12:13:05 +01:00
|
|
|
Full(Vec<Transaction>)
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Serialize for BlockTransactions {
|
2017-02-13 16:38:47 +01:00
|
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
2016-02-08 12:13:05 +01:00
|
|
|
where S: Serializer {
|
|
|
|
match *self {
|
|
|
|
BlockTransactions::Hashes(ref hashes) => hashes.serialize(serializer),
|
|
|
|
BlockTransactions::Full(ref ts) => ts.serialize(serializer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Block representation
|
2016-02-08 12:13:05 +01:00
|
|
|
#[derive(Debug, Serialize)]
|
2018-10-29 16:49:04 +01:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2016-01-26 11:37:24 +01:00
|
|
|
pub struct Block {
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Hash of the block
|
2016-07-06 11:23:29 +02:00
|
|
|
pub hash: Option<H256>,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Hash of the parent
|
2016-01-27 12:31:54 +01:00
|
|
|
pub parent_hash: H256,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Hash of the uncles
|
2018-10-29 16:49:04 +01:00
|
|
|
#[serde(rename = "sha3Uncles")]
|
2016-01-27 12:31:54 +01:00
|
|
|
pub uncles_hash: H256,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Authors address
|
2016-07-06 11:23:29 +02:00
|
|
|
pub author: H160,
|
2018-04-16 20:14:42 +02:00
|
|
|
/// Alias of `author`
|
2016-07-06 11:23:29 +02:00
|
|
|
pub miner: H160,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// State root hash
|
2016-01-27 12:31:54 +01:00
|
|
|
pub state_root: H256,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Transactions root hash
|
2016-01-27 12:31:54 +01:00
|
|
|
pub transactions_root: H256,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Transactions receipts root hash
|
2016-01-27 12:31:54 +01:00
|
|
|
pub receipts_root: H256,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Block number
|
2016-07-06 11:23:29 +02:00
|
|
|
pub number: Option<U256>,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Gas Used
|
2016-01-27 12:31:54 +01:00
|
|
|
pub gas_used: U256,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Gas Limit
|
2016-01-27 12:31:54 +01:00
|
|
|
pub gas_limit: U256,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Extra data
|
2016-02-08 12:13:05 +01:00
|
|
|
pub extra_data: Bytes,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Logs bloom
|
2018-04-02 11:04:14 +02:00
|
|
|
pub logs_bloom: Option<H2048>,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Timestamp
|
2016-01-27 12:31:54 +01:00
|
|
|
pub timestamp: U256,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Difficulty
|
2016-01-27 12:31:54 +01:00
|
|
|
pub difficulty: U256,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Total difficulty
|
2017-02-06 15:28:16 +01:00
|
|
|
pub total_difficulty: Option<U256>,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Seal fields
|
2016-04-25 16:06:08 +02:00
|
|
|
pub seal_fields: Vec<Bytes>,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Uncles' hashes
|
2016-03-19 12:23:48 +01:00
|
|
|
pub uncles: Vec<H256>,
|
2016-05-28 19:30:31 +02:00
|
|
|
/// Transactions
|
2016-07-19 20:40:18 +02:00
|
|
|
pub transactions: BlockTransactions,
|
|
|
|
/// Size in bytes
|
2016-08-17 19:25:02 +02:00
|
|
|
pub size: Option<U256>,
|
2016-01-26 11:37:24 +01:00
|
|
|
}
|
2016-02-08 14:02:47 +01:00
|
|
|
|
2017-04-03 11:37:07 +02:00
|
|
|
/// Block header representation.
|
2017-06-28 12:21:13 +02:00
|
|
|
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
|
2018-10-29 16:49:04 +01:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2017-04-03 11:37:07 +02:00
|
|
|
pub struct Header {
|
|
|
|
/// Hash of the block
|
|
|
|
pub hash: Option<H256>,
|
|
|
|
/// Hash of the parent
|
|
|
|
pub parent_hash: H256,
|
|
|
|
/// Hash of the uncles
|
2018-10-29 16:49:04 +01:00
|
|
|
#[serde(rename = "sha3Uncles")]
|
2017-04-03 11:37:07 +02:00
|
|
|
pub uncles_hash: H256,
|
|
|
|
/// Authors address
|
|
|
|
pub author: H160,
|
2018-04-25 10:00:58 +02:00
|
|
|
/// Alias of `author`
|
2017-04-03 11:37:07 +02:00
|
|
|
pub miner: H160,
|
|
|
|
/// State root hash
|
|
|
|
pub state_root: H256,
|
|
|
|
/// Transactions root hash
|
|
|
|
pub transactions_root: H256,
|
|
|
|
/// Transactions receipts root hash
|
|
|
|
pub receipts_root: H256,
|
|
|
|
/// Block number
|
|
|
|
pub number: Option<U256>,
|
|
|
|
/// Gas Used
|
|
|
|
pub gas_used: U256,
|
|
|
|
/// Gas Limit
|
|
|
|
pub gas_limit: U256,
|
|
|
|
/// Extra data
|
|
|
|
pub extra_data: Bytes,
|
|
|
|
/// Logs bloom
|
|
|
|
pub logs_bloom: H2048,
|
|
|
|
/// Timestamp
|
|
|
|
pub timestamp: U256,
|
|
|
|
/// Difficulty
|
|
|
|
pub difficulty: U256,
|
|
|
|
/// Seal fields
|
|
|
|
pub seal_fields: Vec<Bytes>,
|
|
|
|
/// Size in bytes
|
|
|
|
pub size: Option<U256>,
|
|
|
|
}
|
|
|
|
|
2017-05-23 12:26:39 +02:00
|
|
|
impl From<EthHeader> for Header {
|
|
|
|
fn from(h: EthHeader) -> Self {
|
|
|
|
(&h).into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> From<&'a EthHeader> for Header {
|
|
|
|
fn from(h: &'a EthHeader) -> Self {
|
|
|
|
Header {
|
|
|
|
hash: Some(h.hash().into()),
|
|
|
|
size: Some(h.rlp().as_raw().len().into()),
|
|
|
|
parent_hash: h.parent_hash().into(),
|
|
|
|
uncles_hash: h.uncles_hash().into(),
|
|
|
|
author: h.author().into(),
|
|
|
|
miner: h.author().into(),
|
|
|
|
state_root: h.state_root().into(),
|
|
|
|
transactions_root: h.transactions_root().into(),
|
|
|
|
receipts_root: h.receipts_root().into(),
|
|
|
|
number: Some(h.number().into()),
|
|
|
|
gas_used: h.gas_used().into(),
|
|
|
|
gas_limit: h.gas_limit().into(),
|
|
|
|
logs_bloom: h.log_bloom().into(),
|
|
|
|
timestamp: h.timestamp().into(),
|
|
|
|
difficulty: h.difficulty().into(),
|
|
|
|
extra_data: h.extra_data().into(),
|
2017-11-01 11:29:03 +01:00
|
|
|
seal_fields: h.view().decode_seal()
|
|
|
|
.expect("Client/Miner returns only valid headers. We only serialize headers from Client/Miner; qed")
|
|
|
|
.into_iter().map(Into::into).collect(),
|
2017-05-23 12:26:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-03 11:37:07 +02:00
|
|
|
/// Block representation with additional info.
|
|
|
|
pub type RichBlock = Rich<Block>;
|
|
|
|
|
|
|
|
/// Header representation with additional info.
|
|
|
|
pub type RichHeader = Rich<Header>;
|
|
|
|
|
|
|
|
/// Value representation with additional info
|
2017-06-28 12:21:13 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
2017-04-03 11:37:07 +02:00
|
|
|
pub struct Rich<T> {
|
|
|
|
/// Standard value.
|
|
|
|
pub inner: T,
|
2016-11-04 17:35:02 +01:00
|
|
|
/// Engine-specific fields with additional description.
|
|
|
|
/// Should be included directly to serialized block object.
|
2017-02-13 16:38:47 +01:00
|
|
|
// TODO [ToDr] #[serde(skip_serializing)]
|
2016-11-04 17:35:02 +01:00
|
|
|
pub extra_info: BTreeMap<String, String>,
|
|
|
|
}
|
|
|
|
|
2017-04-03 11:37:07 +02:00
|
|
|
impl<T> Deref for Rich<T> {
|
|
|
|
type Target = T;
|
2016-11-04 17:35:02 +01:00
|
|
|
fn deref(&self) -> &Self::Target {
|
2017-04-03 11:37:07 +02:00
|
|
|
&self.inner
|
2016-11-04 17:35:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-03 11:37:07 +02:00
|
|
|
impl<T: Serialize> Serialize for Rich<T> {
|
2017-02-13 16:38:47 +01:00
|
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
2016-11-04 17:35:02 +01:00
|
|
|
use serde_json::{to_value, Value};
|
|
|
|
|
2017-04-03 11:37:07 +02:00
|
|
|
let serialized = (to_value(&self.inner), to_value(&self.extra_info));
|
|
|
|
if let (Ok(Value::Object(mut value)), Ok(Value::Object(extras))) = serialized {
|
2016-11-04 17:35:02 +01:00
|
|
|
// join two objects
|
2017-04-03 11:37:07 +02:00
|
|
|
value.extend(extras);
|
2016-11-04 17:35:02 +01:00
|
|
|
// and serialize
|
2017-04-03 11:37:07 +02:00
|
|
|
value.serialize(serializer)
|
2017-02-13 16:38:47 +01:00
|
|
|
} else {
|
2017-08-20 06:13:00 +02:00
|
|
|
Err(S::Error::custom("Unserializable structures: expected objects"))
|
2016-11-04 17:35:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-08 14:02:47 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2016-11-04 17:35:02 +01:00
|
|
|
use std::collections::BTreeMap;
|
2019-02-25 14:27:28 +01:00
|
|
|
use ethereum_types::{H64, H160, H256, U256, Bloom as H2048};
|
2016-02-08 14:02:47 +01:00
|
|
|
use serde_json;
|
2019-02-25 14:27:28 +01:00
|
|
|
use v1::types::{Transaction, Bytes};
|
2017-04-03 11:37:07 +02:00
|
|
|
use super::{Block, RichBlock, BlockTransactions, Header, RichHeader};
|
2016-02-08 14:02:47 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_serialize_block_transactions() {
|
|
|
|
let t = BlockTransactions::Full(vec![Transaction::default()]);
|
|
|
|
let serialized = serde_json::to_string(&t).unwrap();
|
2017-08-21 13:46:58 +02:00
|
|
|
assert_eq!(serialized, r#"[{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x0","gasPrice":"0x0","gas":"0x0","input":"0x","creates":null,"raw":"0x","publicKey":null,"chainId":null,"standardV":"0x0","v":"0x0","r":"0x0","s":"0x0","condition":null}]"#);
|
2016-02-08 14:02:47 +01:00
|
|
|
|
2016-07-06 11:23:29 +02:00
|
|
|
let t = BlockTransactions::Hashes(vec![H256::default().into()]);
|
2016-02-08 14:02:47 +01:00
|
|
|
let serialized = serde_json::to_string(&t).unwrap();
|
|
|
|
assert_eq!(serialized, r#"["0x0000000000000000000000000000000000000000000000000000000000000000"]"#);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_serialize_block() {
|
|
|
|
let block = Block {
|
2016-07-06 11:23:29 +02:00
|
|
|
hash: Some(H256::default()),
|
2016-02-08 14:02:47 +01:00
|
|
|
parent_hash: H256::default(),
|
|
|
|
uncles_hash: H256::default(),
|
2016-07-06 11:23:29 +02:00
|
|
|
author: H160::default(),
|
|
|
|
miner: H160::default(),
|
2016-02-08 14:02:47 +01:00
|
|
|
state_root: H256::default(),
|
|
|
|
transactions_root: H256::default(),
|
|
|
|
receipts_root: H256::default(),
|
2016-07-06 11:23:29 +02:00
|
|
|
number: Some(U256::default()),
|
2016-02-08 14:02:47 +01:00
|
|
|
gas_used: U256::default(),
|
|
|
|
gas_limit: U256::default(),
|
|
|
|
extra_data: Bytes::default(),
|
2018-04-02 11:04:14 +02:00
|
|
|
logs_bloom: Some(H2048::default()),
|
2016-02-08 14:02:47 +01:00
|
|
|
timestamp: U256::default(),
|
|
|
|
difficulty: U256::default(),
|
2017-02-08 15:36:53 +01:00
|
|
|
total_difficulty: Some(U256::default()),
|
2016-04-25 16:06:08 +02:00
|
|
|
seal_fields: vec![Bytes::default(), Bytes::default()],
|
2016-02-08 14:02:47 +01:00
|
|
|
uncles: vec![],
|
2016-07-19 20:40:18 +02:00
|
|
|
transactions: BlockTransactions::Hashes(vec![].into()),
|
2016-08-17 19:25:02 +02:00
|
|
|
size: Some(69.into()),
|
2016-02-08 14:02:47 +01:00
|
|
|
};
|
2016-11-04 17:35:02 +01:00
|
|
|
let serialized_block = serde_json::to_string(&block).unwrap();
|
|
|
|
let rich_block = RichBlock {
|
2017-04-03 11:37:07 +02:00
|
|
|
inner: block,
|
2016-11-04 17:35:02 +01:00
|
|
|
extra_info: map![
|
2019-02-25 14:27:28 +01:00
|
|
|
"mixHash".into() => format!("{:?}", H256::default()),
|
|
|
|
"nonce".into() => format!("{:?}", H64::default())
|
2016-11-04 17:35:02 +01:00
|
|
|
],
|
|
|
|
};
|
|
|
|
let serialized_rich_block = serde_json::to_string(&rich_block).unwrap();
|
2016-02-08 14:02:47 +01:00
|
|
|
|
2016-11-04 17:35:02 +01:00
|
|
|
assert_eq!(serialized_block, r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","sha3Uncles":"0x0000000000000000000000000000000000000000000000000000000000000000","author":"0x0000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","number":"0x0","gasUsed":"0x0","gasLimit":"0x0","extraData":"0x","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x0","difficulty":"0x0","totalDifficulty":"0x0","sealFields":["0x","0x"],"uncles":[],"transactions":[],"size":"0x45"}"#);
|
|
|
|
assert_eq!(serialized_rich_block, r#"{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x0","extraData":"0x","gasLimit":"0x0","gasUsed":"0x0","hash":"0x0000000000000000000000000000000000000000000000000000000000000000","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","number":"0x0","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","sealFields":["0x","0x"],"sha3Uncles":"0x0000000000000000000000000000000000000000000000000000000000000000","size":"0x45","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x0","totalDifficulty":"0x0","transactions":[],"transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","uncles":[]}"#);
|
2016-02-08 14:02:47 +01:00
|
|
|
}
|
2017-03-02 12:29:18 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn none_size_null() {
|
|
|
|
let block = Block {
|
|
|
|
hash: Some(H256::default()),
|
|
|
|
parent_hash: H256::default(),
|
|
|
|
uncles_hash: H256::default(),
|
|
|
|
author: H160::default(),
|
|
|
|
miner: H160::default(),
|
|
|
|
state_root: H256::default(),
|
|
|
|
transactions_root: H256::default(),
|
|
|
|
receipts_root: H256::default(),
|
|
|
|
number: Some(U256::default()),
|
|
|
|
gas_used: U256::default(),
|
|
|
|
gas_limit: U256::default(),
|
|
|
|
extra_data: Bytes::default(),
|
2018-04-02 11:04:14 +02:00
|
|
|
logs_bloom: Some(H2048::default()),
|
2017-03-02 12:29:18 +01:00
|
|
|
timestamp: U256::default(),
|
|
|
|
difficulty: U256::default(),
|
|
|
|
total_difficulty: Some(U256::default()),
|
|
|
|
seal_fields: vec![Bytes::default(), Bytes::default()],
|
|
|
|
uncles: vec![],
|
|
|
|
transactions: BlockTransactions::Hashes(vec![].into()),
|
|
|
|
size: None,
|
|
|
|
};
|
|
|
|
let serialized_block = serde_json::to_string(&block).unwrap();
|
|
|
|
let rich_block = RichBlock {
|
2017-04-03 11:37:07 +02:00
|
|
|
inner: block,
|
2017-03-02 12:29:18 +01:00
|
|
|
extra_info: map![
|
2019-02-25 14:27:28 +01:00
|
|
|
"mixHash".into() => format!("{:?}", H256::default()),
|
|
|
|
"nonce".into() => format!("{:?}", H64::default())
|
2017-03-02 12:29:18 +01:00
|
|
|
],
|
|
|
|
};
|
|
|
|
let serialized_rich_block = serde_json::to_string(&rich_block).unwrap();
|
|
|
|
|
|
|
|
assert_eq!(serialized_block, r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","sha3Uncles":"0x0000000000000000000000000000000000000000000000000000000000000000","author":"0x0000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","number":"0x0","gasUsed":"0x0","gasLimit":"0x0","extraData":"0x","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x0","difficulty":"0x0","totalDifficulty":"0x0","sealFields":["0x","0x"],"uncles":[],"transactions":[],"size":null}"#);
|
|
|
|
assert_eq!(serialized_rich_block, r#"{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x0","extraData":"0x","gasLimit":"0x0","gasUsed":"0x0","hash":"0x0000000000000000000000000000000000000000000000000000000000000000","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","number":"0x0","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","sealFields":["0x","0x"],"sha3Uncles":"0x0000000000000000000000000000000000000000000000000000000000000000","size":null,"stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x0","totalDifficulty":"0x0","transactions":[],"transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","uncles":[]}"#);
|
|
|
|
}
|
2017-04-03 11:37:07 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_serialize_header() {
|
|
|
|
let header = Header {
|
|
|
|
hash: Some(H256::default()),
|
|
|
|
parent_hash: H256::default(),
|
|
|
|
uncles_hash: H256::default(),
|
|
|
|
author: H160::default(),
|
|
|
|
miner: H160::default(),
|
|
|
|
state_root: H256::default(),
|
|
|
|
transactions_root: H256::default(),
|
|
|
|
receipts_root: H256::default(),
|
|
|
|
number: Some(U256::default()),
|
|
|
|
gas_used: U256::default(),
|
|
|
|
gas_limit: U256::default(),
|
|
|
|
extra_data: Bytes::default(),
|
|
|
|
logs_bloom: H2048::default(),
|
|
|
|
timestamp: U256::default(),
|
|
|
|
difficulty: U256::default(),
|
|
|
|
seal_fields: vec![Bytes::default(), Bytes::default()],
|
|
|
|
size: Some(69.into()),
|
|
|
|
};
|
|
|
|
let serialized_header = serde_json::to_string(&header).unwrap();
|
|
|
|
let rich_header = RichHeader {
|
|
|
|
inner: header,
|
|
|
|
extra_info: map![
|
2019-02-25 14:27:28 +01:00
|
|
|
"mixHash".into() => format!("{:?}", H256::default()),
|
|
|
|
"nonce".into() => format!("{:?}", H64::default())
|
2017-04-03 11:37:07 +02:00
|
|
|
],
|
|
|
|
};
|
|
|
|
let serialized_rich_header = serde_json::to_string(&rich_header).unwrap();
|
|
|
|
|
|
|
|
assert_eq!(serialized_header, r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","sha3Uncles":"0x0000000000000000000000000000000000000000000000000000000000000000","author":"0x0000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","number":"0x0","gasUsed":"0x0","gasLimit":"0x0","extraData":"0x","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x0","difficulty":"0x0","sealFields":["0x","0x"],"size":"0x45"}"#);
|
|
|
|
assert_eq!(serialized_rich_header, r#"{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x0","extraData":"0x","gasLimit":"0x0","gasUsed":"0x0","hash":"0x0000000000000000000000000000000000000000000000000000000000000000","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","number":"0x0","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","sealFields":["0x","0x"],"sha3Uncles":"0x0000000000000000000000000000000000000000000000000000000000000000","size":"0x45","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x0","transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000"}"#);
|
|
|
|
}
|
2016-02-08 14:02:47 +01:00
|
|
|
}
|