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::interface {
20  class Signature;
21  class Block;
22 } // namespace shared_model::interface
23 
24 namespace iroha::consensus::yac {
25  class YacHash {
26  public:
27  // TODO: 2019-02-08 @muratovv IR-288 refactor YacHash: default ctor,
28  // block signature param, code in the header.
29  YacHash(Round round, ProposalHash proposal, BlockHash block)
30  : vote_round{round},
31  vote_hashes{std::move(proposal), std::move(block)} {}
32 
33  YacHash() = default;
34 
39 
43  struct VoteHashes {
48 
53 
54  std::string toString() const {
56  .init("VoteHashes")
57  .appendNamed("proposal", proposal_hash)
58  .appendNamed("block", block_hash)
59  .finalize();
60  }
61  };
63 
67  std::shared_ptr<shared_model::interface::Signature> block_signature;
68 
69  bool operator==(const YacHash &obj) const {
70  return vote_round == obj.vote_round
71  and vote_hashes.proposal_hash == obj.vote_hashes.proposal_hash
72  and vote_hashes.block_hash == obj.vote_hashes.block_hash;
73  };
74 
75  bool operator!=(const YacHash &obj) const {
76  return not(*this == obj);
77  };
78 
79  std::string toString() const {
81  .init("YacHash")
82  .appendNamed("round", vote_round)
83  .appendNamed("hashes", vote_hashes)
84  .finalize();
85  }
86  };
87 
92  public:
96  virtual YacHash makeHash(
97  const simulator::BlockCreatorEvent &event) const = 0;
98 
104  virtual shared_model::interface::types::HashType toModelHash(
105  const YacHash &hash) const = 0;
106 
107  virtual ~YacHashProvider() = default;
108  };
109 } // namespace iroha::consensus::yac
110 
111 #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:67
std::string toString() const
Definition: yac_hash_provider.hpp:79
bool operator==(const YacHash &obj) const
Definition: yac_hash_provider.hpp:69
YacHash(Round round, ProposalHash proposal, BlockHash block)
Definition: yac_hash_provider.hpp:29
Definition: yac_hash_provider.hpp:25
std::string finalize()
Definition: string_builder.cpp:44
std::string ProposalHash
Definition: yac_common.hpp:19
bool operator!=(const YacHash &obj) const
Definition: yac_hash_provider.hpp:75
Definition: string_builder.hpp:18
Definition: yac_hash_provider.hpp:91
hash256_t hash(const T &pb)
Definition: pb_common.hpp:43
std::string toString() const
Definition: yac_hash_provider.hpp:54
Definition: command_executor.hpp:14
Definition: yac_hash_provider.hpp:43
ProposalHash proposal_hash
Definition: yac_hash_provider.hpp:47
VoteHashes vote_hashes
Definition: yac_hash_provider.hpp:62
BlockHash block_hash
Definition: yac_hash_provider.hpp:52
Definition: round.hpp:31
std::string BlockHash
Definition: yac_common.hpp:21
Round vote_round
Definition: yac_hash_provider.hpp:38
PrettyStringBuilder & appendNamed(const Name &name, const Value &value)
----—— Augmented appending functions. ----—— ///
Definition: string_builder.hpp:53
Definition: cluster_order.hpp:16