hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
yac_hash_provider.hpp
Go to the documentation of this file.
1 
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"
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  : vote_round{round},
36  vote_hashes{std::move(proposal), std::move(block)} {}
37 
38  YacHash() = default;
39 
44 
48  struct VoteHashes {
53 
58 
59  std::string toString() const {
61  .init("VoteHashes")
62  .append("proposal", proposal_hash)
63  .append("block", block_hash)
64  .finalize();
65  }
66  };
68 
72  std::shared_ptr<shared_model::interface::Signature> block_signature;
73 
74  bool operator==(const YacHash &obj) const {
75  return vote_round == obj.vote_round
76  and vote_hashes.proposal_hash == obj.vote_hashes.proposal_hash
77  and vote_hashes.block_hash == obj.vote_hashes.block_hash;
78  };
79 
80  bool operator!=(const YacHash &obj) const {
81  return not(*this == obj);
82  };
83 
84  std::string toString() const {
86  .init("YacHash")
87  .append("round", vote_round.toString())
88  .append("hashes", vote_hashes.toString())
89  .finalize();
90  }
91  };
92 
97  public:
101  virtual YacHash makeHash(
102  const simulator::BlockCreatorEvent &event) const = 0;
103 
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
Definition: block_creator_common.hpp:34
Definition: hash.hpp:18
PrettyStringBuilder & init(const std::string &name)
Definition: string_builder.cpp:18
std::shared_ptr< shared_model::interface::Signature > block_signature
Definition: yac_hash_provider.hpp:72
YacHash(Round round, ProposalHash proposal, BlockHash block)
Definition: yac_hash_provider.hpp:34
Definition: yac_hash_provider.hpp:30
std::string finalize()
Definition: string_builder.cpp:52
std::string ProposalHash
Definition: yac_common.hpp:22
std::string toString() const
Definition: yac_hash_provider.hpp:59
Definition: string_builder.hpp:16
Definition: block_query.hpp:16
Definition: yac_hash_provider.hpp:96
hash256_t hash(const T &pb)
Definition: pb_common.hpp:43
bool operator!=(const YacHash &obj) const
Definition: yac_hash_provider.hpp:80
std::string toString() const
Definition: yac_hash_provider.hpp:84
PrettyStringBuilder & append(const std::string &name, const std::string &value)
Definition: string_builder.cpp:36
std::string toString() const
Definition: round.cpp:41
Definition: yac_hash_provider.hpp:48
ProposalHash proposal_hash
Definition: yac_hash_provider.hpp:52
VoteHashes vote_hashes
Definition: yac_hash_provider.hpp:67
BlockHash block_hash
Definition: yac_hash_provider.hpp:57
Definition: round.hpp:31
std::string BlockHash
Definition: yac_common.hpp:24
Definition: command_executor.hpp:12
bool operator==(const YacHash &obj) const
Definition: yac_hash_provider.hpp:74
Round vote_round
Definition: yac_hash_provider.hpp:43