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 "interfaces/iroha_internal/batch_meta.hpp"
10 :
11 : #include <numeric>
12 :
13 : #include <boost/range/numeric.hpp>
14 : #include "backend/protobuf/common_objects/trivial_proto.hpp"
15 : #include "backend/protobuf/util.hpp"
16 : #include "interfaces/common_objects/amount.hpp"
17 : #include "interfaces/common_objects/types.hpp"
18 : #include "transaction.pb.h"
19 : #include "utils/lazy_initializer.hpp"
20 :
21 : namespace shared_model {
22 : namespace proto {
23 : class BatchMeta final
24 : : public CopyableProto<interface::BatchMeta,
25 : iroha::protocol::Transaction::Payload::BatchMeta,
26 : BatchMeta> {
27 : public:
28 : template <typename BatchMetaType>
29 : explicit BatchMeta(BatchMetaType &&batch_meta)
30 6462 : : CopyableProto(std::forward<BatchMetaType>(batch_meta)),
31 : type_{[this] {
32 113 : unsigned which = proto_->GetDescriptor()
33 113 : ->FindFieldByName("type")
34 113 : ->enum_type()
35 113 : ->FindValueByNumber(proto_->type())
36 113 : ->index();
37 113 : return static_cast<interface::types::BatchType>(which);
38 0 : }},
39 : reduced_hashes_{[this] {
40 2200 : return boost::accumulate(
41 2200 : proto_->reduced_hashes(),
42 2200 : ReducedHashesType{},
43 : [](auto &&acc, const auto &hash) {
44 2541 : acc.emplace_back(hash);
45 2541 : return std::forward<decltype(acc)>(acc);
46 : });
47 6485 : }} {}
48 :
49 : BatchMeta(const BatchMeta &o) : BatchMeta(o.proto_) {}
50 :
51 : BatchMeta(BatchMeta &&o) noexcept : BatchMeta(std::move(o.proto_)) {}
52 :
53 : interface::types::BatchType type() const override {
54 155 : return *type_;
55 : };
56 : const ReducedHashesType &reducedHashes() const override {
57 2268 : return *reduced_hashes_;
58 : };
59 :
60 : private:
61 : template <typename T>
62 : using Lazy = detail::LazyInitializer<T>;
63 :
64 : Lazy<interface::types::BatchType> type_;
65 :
66 : const Lazy<ReducedHashesType> reduced_hashes_;
67 : }; // namespace proto
68 : } // namespace proto
69 : } // namespace shared_model
70 : #endif // IROHA_PROTO_AMOUNT_HPP
|