github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/validator/src/journal/block_validator.rs (about) 1 /* 2 * Copyright 2018 Intel Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * ------------------------------------------------------------------------------ 16 */ 17 use std::sync::mpsc::Sender; 18 19 use batch::Batch; 20 use journal::block_wrapper::BlockWrapper; 21 22 /// Holds the results of Block Validation. 23 pub struct BlockValidationResult { 24 pub chain_head: BlockWrapper, 25 pub block: BlockWrapper, 26 27 pub transaction_count: usize, 28 29 pub new_chain: Vec<BlockWrapper>, 30 pub current_chain: Vec<BlockWrapper>, 31 32 pub committed_batches: Vec<Batch>, 33 pub uncommitted_batches: Vec<Batch>, 34 } 35 36 #[derive(Debug)] 37 pub enum ValidationError { 38 BlockValidationFailure(String), 39 } 40 41 pub trait BlockValidator: Send + Sync { 42 fn in_process(&self, block_id: &str) -> bool; 43 fn in_pending(&self, block_id: &str) -> bool; 44 fn validate_block(&self, block: BlockWrapper) -> Result<(), ValidationError>; 45 46 fn submit_blocks_for_verification( 47 &self, 48 blocks: &[BlockWrapper], 49 response_sender: Sender<(bool, BlockValidationResult)>, 50 ); 51 }