LCOV - code coverage report
Current view: top level - shared_model/backend/protobuf - batch_meta.hpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 15 16 93.8 %
Date: 2019-03-07 14:46:43 Functions: 8 13 61.5 %

          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_PROTO_BATCH_META_HPP
       7             : #define IROHA_PROTO_BATCH_META_HPP
       8             : 
       9             : #include <boost/range/numeric.hpp>
      10             : #include "backend/protobuf/common_objects/trivial_proto.hpp"
      11             : #include "cryptography/hash.hpp"
      12             : #include "interfaces/common_objects/types.hpp"
      13             : #include "interfaces/iroha_internal/batch_meta.hpp"
      14             : #include "transaction.pb.h"
      15             : 
      16             : namespace shared_model {
      17             :   namespace proto {
      18             :     class BatchMeta final
      19             :         : public CopyableProto<interface::BatchMeta,
      20             :                                iroha::protocol::Transaction::Payload::BatchMeta,
      21             :                                BatchMeta> {
      22             :      public:
      23             :       template <typename BatchMetaType>
      24             :       explicit BatchMeta(BatchMetaType &&batch_meta)
      25         483 :           : CopyableProto(std::forward<BatchMetaType>(batch_meta)),
      26             :             type_{[this] {
      27         485 :               unsigned which = proto_->GetDescriptor()
      28         482 :                                    ->FindFieldByName("type")
      29         484 :                                    ->enum_type()
      30         483 :                                    ->FindValueByNumber(proto_->type())
      31         484 :                                    ->index();
      32         485 :               return static_cast<interface::types::BatchType>(which);
      33           0 :             }()},
      34         486 :             reduced_hashes_{boost::accumulate(
      35         484 :                 proto_->reduced_hashes(),
      36         485 :                 ReducedHashesType{},
      37             :                 [](auto &&acc, const auto &hash) {
      38        1602 :                   acc.emplace_back(crypto::Hash::fromHexString(hash));
      39        1602 :                   return std::forward<decltype(acc)>(acc);
      40         486 :                 })} {}
      41             : 
      42             :       BatchMeta(const BatchMeta &o) : BatchMeta(o.proto_) {}
      43             : 
      44             :       BatchMeta(BatchMeta &&o) noexcept : BatchMeta(std::move(o.proto_)) {}
      45             : 
      46             :       interface::types::BatchType type() const override {
      47         226 :         return type_;
      48             :       };
      49             :       const ReducedHashesType &reducedHashes() const override {
      50         334 :         return reduced_hashes_;
      51             :       };
      52             : 
      53             :      private:
      54             :       interface::types::BatchType type_;
      55             : 
      56             :       const ReducedHashesType reduced_hashes_;
      57             :     };
      58             :   }  // namespace proto
      59             : }  // namespace shared_model
      60             : #endif  // IROHA_PROTO_AMOUNT_HPP

Generated by: LCOV version 1.13