hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
proto_proposal_factory.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_PROTO_PROPOSAL_FACTORY_HPP
7 #define IROHA_PROTO_PROPOSAL_FACTORY_HPP
8 
11 
14 #include "proposal.pb.h"
15 
16 namespace shared_model {
17  namespace proto {
18  template <typename Validator>
21  public:
26 
30  TransactionsCollectionType transactions) override {
31  return createProposal(
32  createProtoProposal(height, created_time, transactions));
33  }
34 
35  std::unique_ptr<interface::Proposal> unsafeCreateProposal(
38  UnsafeTransactionsCollectionType transactions) override {
39  return std::make_unique<Proposal>(
40  createProtoProposal(height, created_time, transactions));
41  }
42 
47  const iroha::protocol::Proposal &proposal) {
48  return validate(std::make_unique<Proposal>(proposal));
49  }
50 
51  private:
52  iroha::protocol::Proposal createProtoProposal(
55  UnsafeTransactionsCollectionType transactions) {
56  iroha::protocol::Proposal proposal;
57 
58  proposal.set_height(height);
59  proposal.set_created_time(created_time);
60 
61  for (const auto &tx : transactions) {
62  *proposal.add_transactions() =
63  static_cast<const shared_model::proto::Transaction &>(tx)
64  .getTransport();
65  }
66 
67  return proposal;
68  }
69 
71  std::unique_ptr<Proposal> proposal) {
72  auto errors = validator_.validate(*proposal);
73 
74  if (errors) {
75  return iroha::expected::makeError(errors.reason());
76  }
77 
78  return iroha::expected::makeValue<std::unique_ptr<interface::Proposal>>(
79  std::move(proposal));
80  }
81 
82  Validator validator_;
83  };
84  } // namespace proto
85 } // namespace shared_model
86 
87 #endif // IROHA_PROTO_PROPOSAL_FACTORY_HPP
uint64_t HeightType
Type of height (for Block, Proposal etc)
Definition: types.hpp:41
Definition: unsafe_proposal_factory.hpp:22
boost::any_range< Transaction, boost::forward_traversal_tag, const Transaction & > TransactionsCollectionType
Definition: unsafe_proposal_factory.hpp:27
std::unique_ptr< interface::Proposal > unsafeCreateProposal(interface::types::HeightType height, interface::types::TimestampType created_time, UnsafeTransactionsCollectionType transactions) override
Definition: proto_proposal_factory.hpp:35
Definition: proto_proposal_factory.hpp:19
interface::UnsafeProposalFactory::TransactionsCollectionType UnsafeTransactionsCollectionType
Definition: proto_proposal_factory.hpp:25
FactoryResult< std::unique_ptr< interface::Proposal > > createProposal(interface::types::HeightType height, interface::types::TimestampType created_time, TransactionsCollectionType transactions) override
Definition: proto_proposal_factory.hpp:27
boost::any_range< Transaction, boost::forward_traversal_tag, const Transaction & > TransactionsCollectionType
Definition: proposal_factory.hpp:30
Definition: proposal_factory.hpp:22
FactoryResult< std::unique_ptr< interface::Proposal > > createProposal(const iroha::protocol::Proposal &proposal)
Definition: proto_proposal_factory.hpp:46
Definition: command_executor.hpp:12
interface::ProposalFactory::TransactionsCollectionType TransactionsCollectionType
Definition: proto_proposal_factory.hpp:23
iroha::expected::Result< T, std::string > FactoryResult
Definition: proposal_factory.hpp:25
uint64_t TimestampType
Type of timestamp.
Definition: types.hpp:61