LCOV - code coverage report
Current view: top level - irohad/consensus/yac - yac_hash_provider.hpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 6 6 100.0 %
Date: 2018-12-05 17:11:35 Functions: 26 28 92.9 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
       3             :  * http://soramitsu.co.jp
       4             :  *
       5             :  * Licensed under the Apache License, Version 2.0 (the "License");
       6             :  * you may not use this file except in compliance with the License.
       7             :  * You may obtain a copy of the License at
       8             :  *
       9             :  *        http://www.apache.org/licenses/LICENSE-2.0
      10             :  *
      11             :  * Unless required by applicable law or agreed to in writing, software
      12             :  * distributed under the License is distributed on an "AS IS" BASIS,
      13             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14             :  * See the License for the specific language governing permissions and
      15             :  * limitations under the License.
      16             :  */
      17             : 
      18             : #ifndef IROHA_YAC_HASH_PROVIDER_HPP
      19             : #define IROHA_YAC_HASH_PROVIDER_HPP
      20             : 
      21             : #include <memory>
      22             : #include <string>
      23             : 
      24             : #include "consensus/round.hpp"
      25             : #include "consensus/yac/storage/yac_common.hpp"
      26             : #include "interfaces/common_objects/types.hpp"
      27             : #include "utils/string_builder.hpp"
      28             : 
      29             : namespace shared_model {
      30             :   namespace interface {
      31             :     class Signature;
      32             :     class Block;
      33             :   }  // namespace interface
      34             : }  // namespace shared_model
      35             : 
      36             : namespace iroha {
      37             :   namespace consensus {
      38             :     namespace yac {
      39             : 
      40             :       class YacHash {
      41             :        public:
      42             :         YacHash(Round round, ProposalHash proposal, BlockHash block)
      43        1486 :             : vote_round{round},
      44        1486 :               vote_hashes{std::move(proposal), std::move(block)} {}
      45             : 
      46             :         YacHash() = default;
      47             : 
      48             :         /**
      49             :          * Round, in which peer voted
      50             :          */
      51             :         Round vote_round;
      52             : 
      53             :         /**
      54             :          * Contains hashes of proposal and block, for which peer voted
      55             :          */
      56             :         struct VoteHashes {
      57             :           /**
      58             :            * Hash computed from proposal
      59             :            */
      60             :           ProposalHash proposal_hash;
      61             : 
      62             :           /**
      63             :            * Hash computed from block;
      64             :            */
      65             :           BlockHash block_hash;
      66             : 
      67             :           std::string toString() const {
      68             :             return shared_model::detail::PrettyStringBuilder()
      69             :                 .init("VoteHashes")
      70             :                 .append("proposal", proposal_hash)
      71             :                 .append("block", block_hash)
      72             :                 .finalize();
      73             :           }
      74             :         };
      75             :         VoteHashes vote_hashes;
      76             : 
      77             :         /**
      78             :          * Peer signature of block
      79             :          */
      80             :         std::shared_ptr<shared_model::interface::Signature> block_signature;
      81             : 
      82             :         bool operator==(const YacHash &obj) const {
      83        3389 :           return vote_round == obj.vote_round
      84        3389 :               and vote_hashes.proposal_hash == obj.vote_hashes.proposal_hash
      85        3389 :               and vote_hashes.block_hash == obj.vote_hashes.block_hash;
      86             :         };
      87             : 
      88             :         bool operator!=(const YacHash &obj) const {
      89         796 :           return not(*this == obj);
      90             :         };
      91             : 
      92             :         std::string toString() const {
      93             :           return shared_model::detail::PrettyStringBuilder()
      94             :               .init("YacHash")
      95             :               .append("round", vote_round.toString())
      96             :               .append("hashes", vote_hashes.toString())
      97             :               .finalize();
      98             :         }
      99             :       };
     100             : 
     101             :       /**
     102             :        * Provide methods related to hash operations in ya consensus
     103             :        */
     104             :       class YacHashProvider {
     105             :        public:
     106             :         /**
     107             :          * Make hash from block
     108             :          * @param block - for hashing
     109             :          * @return hashed value of block
     110             :          */
     111             :         virtual YacHash makeHash(
     112             :             const shared_model::interface::Block &block) const = 0;
     113             : 
     114             :         /**
     115             :          * Convert YacHash to model hash
     116             :          * @param hash - for converting
     117             :          * @return HashType of model hash
     118             :          */
     119             :         virtual shared_model::interface::types::HashType toModelHash(
     120             :             const YacHash &hash) const = 0;
     121             : 
     122             :         virtual ~YacHashProvider() = default;
     123             :       };
     124             :     }  // namespace yac
     125             :   }    // namespace consensus
     126             : }  // namespace iroha
     127             : 
     128             : #endif  // IROHA_YAC_HASH_PROVIDER_HPP

Generated by: LCOV version 1.13