fix warnings
This commit is contained in:
parent
567facbe29
commit
1176c62628
|
@ -609,6 +609,7 @@ dependencies = [
|
|||
"linked-hash-map 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"primitives 0.1.0",
|
||||
"script 0.1.0",
|
||||
"serialization 0.1.0",
|
||||
"test-data 0.1.0",
|
||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -14,4 +14,4 @@ linked-hash-map = "0.3"
|
|||
test-data = { path = "../test-data" }
|
||||
byteorder = "0.5"
|
||||
time = "0.1"
|
||||
|
||||
script = { path = "../script" }
|
||||
|
|
|
@ -4,8 +4,7 @@ use std::sync::Arc;
|
|||
|
||||
use db::{self, BlockRef};
|
||||
use chain;
|
||||
use super::{Verify, VerificationResult, Chain, Error};
|
||||
use primitives::hash::H256;
|
||||
use super::{Verify, VerificationResult, Chain, Error, TransactionError};
|
||||
use utils;
|
||||
|
||||
const BLOCK_MAX_FUTURE: i64 = 2 * 60 * 60; // 2 hours
|
||||
|
@ -18,6 +17,44 @@ impl ChainVerifier {
|
|||
pub fn new(store: Arc<db::Store>) -> Self {
|
||||
ChainVerifier { store: store }
|
||||
}
|
||||
|
||||
fn verify_transaction(&self, transaction: &chain::Transaction) -> Result<(), TransactionError> {
|
||||
//use script::{TransactionInputSigner, TransactionSignatureChecker, VerificationFlags, verify_script};
|
||||
|
||||
for (input_index, input) in transaction.inputs().iter().enumerate() {
|
||||
let parent_transaction = match self.store.transaction(&input.previous_output.hash) {
|
||||
Some(tx) => tx,
|
||||
None => { return Err(TransactionError::Input(input_index)); }
|
||||
};
|
||||
if parent_transaction.outputs.len() <= input.previous_output.index as usize {
|
||||
return Err(TransactionError::Input(input_index));
|
||||
}
|
||||
|
||||
|
||||
// signature verification
|
||||
|
||||
// let signer: TransactionInputSigner = transaction.clone().into();
|
||||
// let paired_output = parent_transaction.outputs[input.previous_output.index as usize];
|
||||
// let checker = TransactionSignatureChecker {
|
||||
// signer: signer,
|
||||
// input_index: input_index,
|
||||
// };
|
||||
// let input: Script = input.script_sig().into();
|
||||
// let output: Script = paired_output.script_pubkey.into();
|
||||
// let flags = VerificationFlags::default().verify_p2sh(true);
|
||||
//
|
||||
// if !verify_script(&input, &output, &flags, &checker).unwrap_or(|e| {
|
||||
// // todo: log error here
|
||||
// println!("transaction signature verification failure: {:?}", e);
|
||||
// false
|
||||
// })
|
||||
// {
|
||||
// return Err(TransactionError::Signature(input_index))
|
||||
// }
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Verify for ChainVerifier {
|
||||
|
@ -44,7 +81,12 @@ impl Verify for ChainVerifier {
|
|||
return Err(Error::Coinbase)
|
||||
}
|
||||
|
||||
let parent = match self.store.block(BlockRef::Hash(block.header().previous_header_hash.clone())) {
|
||||
// verify transactions
|
||||
for (idx, transaction) in block.transactions().iter().skip(1).enumerate() {
|
||||
try!(self.verify_transaction(transaction).map_err(|e| Error::Transaction(idx, e)));
|
||||
}
|
||||
|
||||
let _parent = match self.store.block(BlockRef::Hash(block.header().previous_header_hash.clone())) {
|
||||
Some(b) => b,
|
||||
None => { return Ok(Chain::Orphan); }
|
||||
};
|
||||
|
@ -83,11 +125,10 @@ mod tests {
|
|||
|
||||
fn with_blocks(blocks: &[chain::Block]) -> Self {
|
||||
let mut storage = TestStorage::default();
|
||||
let mut height = 0;
|
||||
for (idx, block) in blocks.iter().enumerate() {
|
||||
let hash = block.hash();
|
||||
storage.blocks.insert(hash.clone(), block.clone());
|
||||
storage.heights.insert(height, hash);
|
||||
storage.heights.insert(idx, hash);
|
||||
}
|
||||
storage
|
||||
}
|
||||
|
@ -133,7 +174,7 @@ mod tests {
|
|||
.cloned()
|
||||
}
|
||||
|
||||
fn insert_block(&self, block: &chain::Block) -> Result<(), db::Error> {
|
||||
fn insert_block(&self, _block: &chain::Block) -> Result<(), db::Error> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ extern crate parking_lot;
|
|||
extern crate linked_hash_map;
|
||||
extern crate byteorder;
|
||||
extern crate time;
|
||||
extern crate script;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate ethcore_devtools as devtools;
|
||||
|
@ -19,6 +20,7 @@ mod utils;
|
|||
mod chain_verifier;
|
||||
|
||||
pub use queue::Queue;
|
||||
pub use chain_verifier::ChainVerifier;
|
||||
|
||||
#[derive(Debug)]
|
||||
/// All possible verification errors
|
||||
|
@ -43,11 +45,11 @@ pub enum Error {
|
|||
/// Possible transactions verification errors
|
||||
pub enum TransactionError {
|
||||
/// Not found corresponding output for transaction input
|
||||
Input,
|
||||
Input(usize),
|
||||
/// Referenced coinbase output for the transaction input is not mature enough
|
||||
Maturity,
|
||||
/// Signature invalid
|
||||
Signature,
|
||||
/// Signature invalid for given input
|
||||
Signature(usize),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Verification utilities
|
||||
use primitives::hash::H256;
|
||||
use byteorder::{LittleEndian, BigEndian, ByteOrder};
|
||||
use byteorder::{BigEndian, ByteOrder};
|
||||
|
||||
pub fn check_nbits(hash: &H256, n_bits: u32) -> bool {
|
||||
let hash_bytes: &[u8] = &**hash;
|
||||
|
|
Loading…
Reference in New Issue