github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/validator/src/journal/block_wrapper.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 18 use batch::Batch; 19 use block::Block; 20 use scheduler::TxnExecutionResult; 21 use std::fmt; 22 23 #[derive(Debug, Clone, PartialEq)] 24 pub enum BlockStatus { 25 Unknown = 0, 26 Invalid = 1, 27 Valid = 2, 28 Missing = 3, 29 } 30 31 impl Default for BlockStatus { 32 fn default() -> Self { 33 BlockStatus::Unknown 34 } 35 } 36 37 #[derive(Clone, Debug, Default)] 38 pub struct BlockWrapper { 39 pub block: Block, 40 pub status: BlockStatus, 41 pub execution_results: Vec<TxnExecutionResult>, 42 pub num_transactions: usize, 43 } 44 45 impl BlockWrapper { 46 pub fn new(block: Block) -> Self { 47 BlockWrapper { 48 block, 49 ..BlockWrapper::default() 50 } 51 } 52 53 pub fn header_signature(&self) -> &str { 54 &self.block.header_signature 55 } 56 57 pub fn previous_block_id(&self) -> &str { 58 &self.block.previous_block_id 59 } 60 61 pub fn block_num(&self) -> u64 { 62 self.block.block_num 63 } 64 65 pub fn batches(&self) -> &[Batch] { 66 &self.block.batches 67 } 68 69 pub fn state_root_hash(&self) -> &str { 70 &self.block.state_root_hash 71 } 72 } 73 74 impl fmt::Display for BlockWrapper { 75 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 76 write!(f, "{}", self.block) 77 } 78 }