     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99

    use std::fmt;
    use hex::FromHex;
    use ser::{deserialize, serialize};
    use crypto::dhash256;
    use compact::Compact;
    use hash::H256;

    #[derive(PartialEq, Clone, Serializable, Deserializable)]
    pub struct BlockHeader {
    	pub version: u32,
    	pub previous_header_hash: H256,
    	pub merkle_root_hash: H256,
    	pub time: u32,
    	pub bits: Compact,
    	pub nonce: u32,
    }

    impl BlockHeader {
    	pub fn hash(&self) -> H256 {
    		dhash256(&serialize(self))
    	}
    }

    impl fmt::Debug for BlockHeader {
    	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    		f.debug_struct("BlockHeader")
    			.field("version", &self.version)
    			.field("previous_header_hash", &self.previous_header_hash.reversed())
    			.field("merkle_root_hash", &self.merkle_root_hash.reversed())
    			.field("time", &self.time)
    			.field("bits", &self.bits)
    			.field("nonce", &self.nonce)
    			.finish()
    	}
    }

    impl From<&'static str> for BlockHeader {
    	fn from(s: &'static str) -> Self {
    		deserialize(&s.from_hex::<Vec<u8>>().unwrap() as &[u8]).unwrap()
    	}
    }

    #[cfg(test)]
    mod tests {
    	use ser::{Reader, Error as ReaderError, Stream};
    	use super::BlockHeader;

    	#[test]
    	fn test_block_header_stream() {
    		let block_header = BlockHeader {
    			version: 1,
    			previous_header_hash: [2; 32].into(),
    			merkle_root_hash: [3; 32].into(),
    			time: 4,
    			bits: 5.into(),
    			nonce: 6,
    		};

    		let mut stream = Stream::default();
    		stream.append(&block_header);

    		let expected = vec![
    			1, 0, 0, 0,
    			2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
    			3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    			4, 0, 0, 0,
    			5, 0, 0, 0,
    			6, 0, 0, 0,
    		].into();

    		assert_eq!(stream.out(), expected);
    	}

    	#[test]
    	fn test_block_header_reader() {
    		let buffer = vec![
    			1, 0, 0, 0,
    			2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
    			3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    			4, 0, 0, 0,
    			5, 0, 0, 0,
    			6, 0, 0, 0,
    		];

    		let mut reader = Reader::new(&buffer);

    		let expected = BlockHeader {
    			version: 1,
    			previous_header_hash: [2; 32].into(),
    			merkle_root_hash: [3; 32].into(),
    			time: 4,
    			bits: 5.into(),
    			nonce: 6,
    		};

    		assert_eq!(expected, reader.read().unwrap());
    		assert_eq!(ReaderError::UnexpectedEnd, reader.read::<BlockHeader>().unwrap_err());
    	}
    }

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)