hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
batch_meta.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_PROTO_BATCH_META_HPP
7 #define IROHA_PROTO_BATCH_META_HPP
8 
9 #include <boost/range/numeric.hpp>
11 #include "cryptography/hash.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  : CopyableProto(std::forward<BatchMetaType>(batch_meta)),
26  type_{[this] {
27  unsigned which = proto_->GetDescriptor()
28  ->FindFieldByName("type")
29  ->enum_type()
30  ->FindValueByNumber(proto_->type())
31  ->index();
32  return static_cast<interface::types::BatchType>(which);
33  }()},
34  reduced_hashes_{boost::accumulate(
35  proto_->reduced_hashes(),
37  [](auto &&acc, const auto &hash) {
38  acc.emplace_back(crypto::Hash::fromHexString(hash));
39  return std::forward<decltype(acc)>(acc);
40  })} {}
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  return type_;
48  };
49  const ReducedHashesType &reducedHashes() const override {
50  return reduced_hashes_;
51  };
52 
53  private:
55 
56  const ReducedHashesType reduced_hashes_;
57  };
58  } // namespace proto
59 } // namespace shared_model
60 #endif // IROHA_PROTO_AMOUNT_HPP
detail::ReferenceHolder< iroha::protocol::Transaction::Payload::BatchMeta > proto_
Definition: trivial_proto.hpp:65
BatchMeta(BatchMetaType &&batch_meta)
Definition: batch_meta.hpp:24
const ReducedHashesType & reducedHashes() const override
Definition: batch_meta.hpp:49
Definition: peer.hpp:48
BatchMeta(const BatchMeta &o)
Definition: batch_meta.hpp:42
interface::types::BatchType type() const override
Definition: batch_meta.hpp:46
BatchMeta(BatchMeta &&o) noexcept
Definition: batch_meta.hpp:44
hash256_t hash(const T &pb)
Definition: pb_common.hpp:43
std::vector< interface::types::HashType > ReducedHashesType
type of hashes collection
Definition: batch_meta.hpp:32
BatchType
Definition: types.hpp:81
Definition: command_executor.hpp:12
Definition: trivial_proto.hpp:45
Definition: batch_meta.hpp:18
static Hash fromHexString(const std::string &hex)
Definition: hash.cpp:20