LCOV - code coverage report
Current view: top level - irohad/consensus/yac - yac_hash_provider.hpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 6 6 100.0 %
Date: 2019-03-07 14:46:43 Functions: 26 28 92.9 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #ifndef IROHA_YAC_HASH_PROVIDER_HPP
       7             : #define IROHA_YAC_HASH_PROVIDER_HPP
       8             : 
       9             : #include <ciso646>
      10             : #include <memory>
      11             : #include <string>
      12             : 
      13             : #include "consensus/round.hpp"
      14             : #include "consensus/yac/storage/yac_common.hpp"
      15             : #include "interfaces/common_objects/types.hpp"
      16             : #include "simulator/block_creator_common.hpp"
      17             : #include "utils/string_builder.hpp"
      18             : 
      19             : namespace shared_model {
      20             :   namespace interface {
      21             :     class Signature;
      22             :     class Block;
      23             :   }  // namespace interface
      24             : }  // namespace shared_model
      25             : 
      26             : namespace iroha {
      27             :   namespace consensus {
      28             :     namespace yac {
      29             : 
      30             :       class YacHash {
      31             :        public:
      32             :         // TODO: 2019-02-08 @muratovv IR-288 refactor YacHash: default ctor,
      33             :         // block signature param, code in the header.
      34             :         YacHash(Round round, ProposalHash proposal, BlockHash block)
      35        3925 :             : vote_round{round},
      36        3925 :               vote_hashes{std::move(proposal), std::move(block)} {}
      37             : 
      38             :         YacHash() = default;
      39             : 
      40             :         /**
      41             :          * Round, in which peer voted
      42             :          */
      43             :         Round vote_round;
      44             : 
      45             :         /**
      46             :          * Contains hashes of proposal and block, for which peer voted
      47             :          */
      48             :         struct VoteHashes {
      49             :           /**
      50             :            * Hash computed from proposal
      51             :            */
      52             :           ProposalHash proposal_hash;
      53             : 
      54             :           /**
      55             :            * Hash computed from block;
      56             :            */
      57             :           BlockHash block_hash;
      58             : 
      59             :           std::string toString() const {
      60             :             return shared_model::detail::PrettyStringBuilder()
      61             :                 .init("VoteHashes")
      62             :                 .append("proposal", proposal_hash)
      63             :                 .append("block", block_hash)
      64             :                 .finalize();
      65             :           }
      66             :         };
      67             :         VoteHashes vote_hashes;
      68             : 
      69             :         /**
      70             :          * Peer signature of block
      71             :          */
      72             :         std::shared_ptr<shared_model::interface::Signature> block_signature;
      73             : 
      74             :         bool operator==(const YacHash &obj) const {
      75       20065 :           return vote_round == obj.vote_round
      76       20065 :               and vote_hashes.proposal_hash == obj.vote_hashes.proposal_hash
      77       20065 :               and vote_hashes.block_hash == obj.vote_hashes.block_hash;
      78             :         };
      79             : 
      80             :         bool operator!=(const YacHash &obj) const {
      81        4071 :           return not(*this == obj);
      82             :         };
      83             : 
      84             :         std::string toString() const {
      85             :           return shared_model::detail::PrettyStringBuilder()
      86             :               .init("YacHash")
      87             :               .append("round", vote_round.toString())
      88             :               .append("hashes", vote_hashes.toString())
      89             :               .finalize();
      90             :         }
      91             :       };
      92             : 
      93             :       /**
      94             :        * Provide methods related to hash operations in ya consensus
      95             :        */
      96             :       class YacHashProvider {
      97             :        public:
      98             :         /**
      99             :          * Make hash from block creator event
     100             :          */
     101             :         virtual YacHash makeHash(
     102             :             const simulator::BlockCreatorEvent &event) const = 0;
     103             : 
     104             :         /**
     105             :          * Convert YacHash to model hash
     106             :          * @param hash - for converting
     107             :          * @return HashType of model hash
     108             :          */
     109             :         virtual shared_model::interface::types::HashType toModelHash(
     110             :             const YacHash &hash) const = 0;
     111             : 
     112             :         virtual ~YacHashProvider() = default;
     113             :       };
     114             :     }  // namespace yac
     115             :   }    // namespace consensus
     116             : }  // namespace iroha
     117             : 
     118             : #endif  // IROHA_YAC_HASH_PROVIDER_HPP

Generated by: LCOV version 1.13