h256 represented entities

This commit is contained in:
NikVolf 2016-10-24 18:18:02 +03:00
parent ffd299f011
commit 108b4b6383
7 changed files with 20 additions and 11 deletions

View File

@ -6,6 +6,7 @@ use ser::{
};
use merkle_root::merkle_root;
use {BlockHeader, Transaction};
use super::ToH256;
#[derive(Debug, PartialEq, Clone)]
pub struct Block {
@ -38,15 +39,17 @@ impl From<&'static str> for Block {
}
}
impl ToH256 for Block {
fn hash(&self) -> H256 {
self.block_header.hash()
}
}
impl Block {
pub fn new(header: BlockHeader, transactions: Vec<Transaction>) -> Self {
Block { block_header: header, transactions: transactions }
}
pub fn hash(&self) -> H256 {
self.block_header.hash()
}
/// Returns block's merkle root.
pub fn merkle_root(&self) -> H256 {
let hashes = self.transactions.iter().map(Transaction::hash).collect::<Vec<H256>>();
@ -66,6 +69,7 @@ impl Block {
mod tests {
use hash::H256;
use super::Block;
use super::super::ToH256;
// Block 80000
// https://blockchain.info/rawblock/000000000043a8c0fd1d6f726790caa2a406010d19efd2780db27bdbbd93baf6

View File

@ -9,6 +9,10 @@ mod block_header;
mod merkle_root;
mod transaction;
pub trait ToH256 {
fn hash(&self) -> primitives::hash::H256;
}
pub use rustc_serialize::hex;
pub use primitives::{hash, bytes};

View File

@ -7,7 +7,8 @@ use byteorder::{LittleEndian, ByteOrder};
use primitives::hash::H256;
use primitives::bytes::Bytes;
use super::BlockRef;
use {chain, serialization};
use serialization;
use chain::{self, ToH256};
const COL_COUNT: u32 = 10;
const COL_META: u32 = 0;
@ -262,7 +263,7 @@ mod tests {
use super::{Storage, Store};
use devtools::RandomTempPath;
use chain::Block;
use chain::{Block, ToH256};
use super::super::BlockRef;
use test_data;

View File

@ -1,7 +1,7 @@
//! Test storage
use super::{BlockRef, Store, Error};
use chain;
use chain::{self, ToH256};
use primitives::hash::H256;
use serialization;
use chain::bytes::Bytes;

View File

@ -1,6 +1,6 @@
use std::collections::HashMap;
use std::collections::hash_map::Entry;
use chain::Block;
use chain::{Block, ToH256};
use primitives::hash::H256;
use best_block::BestBlock;

View File

@ -3,7 +3,7 @@
use std::sync::Arc;
use db::{self, BlockRef};
use chain;
use chain::{self, ToH256};
use super::{Verify, VerificationResult, Chain, Error, TransactionError};
use utils;

View File

@ -1,6 +1,6 @@
//! Blocks verification queue
use chain::Block;
use chain::{Block, ToH256};
use primitives::hash::H256;
use super::{Chain, Verify, BlockStatus};
use linked_hash_map::LinkedHashMap;
@ -119,7 +119,7 @@ impl Queue {
mod tests {
use super::Queue;
use super::super::{BlockStatus, VerificationResult, Verify, Chain, Error as VerificationError};
use chain::Block;
use chain::{Block, ToH256};
use primitives::hash::H256;
use test_data;