LCOV - code coverage report
Current view: top level - irohad/consensus/yac/storage/impl - yac_common.cpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 12 14 85.7 %
Date: 2018-12-05 17:11:35 Functions: 4 4 100.0 %

          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             : #include "consensus/yac/storage/yac_common.hpp"
      19             : 
      20             : #include <algorithm>
      21             : 
      22             : #include "consensus/yac/messages.hpp"
      23             : 
      24             : namespace iroha {
      25             :   namespace consensus {
      26             :     namespace yac {
      27             : 
      28             :       bool sameKeys(const std::vector<VoteMessage> &votes) {
      29        2142 :         if (votes.empty()) {
      30           0 :           return false;
      31             :         }
      32             : 
      33        2142 :         auto first = votes.at(0);
      34        2142 :         return std::all_of(
      35             :             votes.begin(), votes.end(), [&first](const auto &current) {
      36        2158 :               return first.hash.vote_round == current.hash.vote_round;
      37             :             });
      38        2142 :       }
      39             : 
      40             :       boost::optional<Round> getKey(const std::vector<VoteMessage> &votes) {
      41           2 :         if (not sameKeys(votes)) {
      42           1 :           return boost::none;
      43             :         }
      44           1 :         return votes[0].hash.vote_round;
      45           2 :       }
      46             : 
      47             :       boost::optional<YacHash> getHash(const std::vector<VoteMessage> &votes) {
      48         713 :         if (not sameKeys(votes)) {
      49           0 :           return boost::none;
      50             :         }
      51             : 
      52         713 :         return votes.at(0).hash;
      53         713 :       }
      54             :     }  // namespace yac
      55             :   }    // namespace consensus
      56             : }  // namespace iroha

Generated by: LCOV version 1.13