hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
unsigned_proto.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_UNSIGNED_PROTO_HPP
7 #define IROHA_UNSIGNED_PROTO_HPP
8 
12 #include "cryptography/keypair.hpp"
14 
15 namespace shared_model {
16  namespace proto {
24  template <typename T>
26  public:
27  using ModelType = T;
28 
33  explicit UnsignedWrapper(const T &o) : object_(o) {}
34 
35  explicit UnsignedWrapper(T &&o) : object_(std::move(o)) {}
36 
38  : object_(std::move(w.object_)),
39  object_finalized_(w.object_finalized_) {
40  w.object_finalized_ = true;
41  }
42 
44  object_ = std::move(w.object_);
45  object_finalized_ = w.object_finalized_;
46  w.object_finalized_ = true;
47 
48  return *this;
49  }
50 
51  UnsignedWrapper(const UnsignedWrapper<T> &o) = default;
52  UnsignedWrapper<T> &operator=(const UnsignedWrapper<T> &w) = default;
53 
61  shared_model::crypto::Blob(object_.payload()), keypair);
62  if (object_finalized_) {
63  throw std::runtime_error("object has already been finalized");
64  }
65  object_.addSignature(signedBlob, keypair.publicKey());
66  // TODO: 05.12.2017 luckychess think about false case
67  return *this;
68  }
69 
74  T finish() {
75  if (boost::size(object_.signatures()) == 0) {
76  throw std::invalid_argument("Cannot get object without signatures");
77  }
78  if (object_finalized_) {
79  throw std::runtime_error("object has already been finalized");
80  }
81 
82  object_finalized_ = true;
83  return std::move(object_);
84  }
85 
87  return object_.hash();
88  }
89 
90  template <typename U = T>
91  std::enable_if_t<
92  std::is_base_of<shared_model::interface::Transaction, U>::value,
94  reducedHash() const {
95  return object_.reducedHash();
96  }
97 
98  private:
99  T object_;
100  bool object_finalized_{false};
101  };
102  } // namespace proto
103 } // namespace shared_model
104 
105 #endif // IROHA_UNSIGNED_PROTO_HPP
UnsignedWrapper(T &&o)
Definition: unsigned_proto.hpp:35
Definition: hash.hpp:18
Definition: blob.hpp:24
T ModelType
Definition: unsigned_proto.hpp:27
Definition: keypair.hpp:19
Definition: peer.hpp:48
static Signed sign(const Blob &blob, const Keypair &keypair)
Definition: crypto_signer.hpp:30
UnsignedWrapper< T > & operator=(UnsignedWrapper< T > &&w)
Definition: unsigned_proto.hpp:43
UnsignedWrapper(const T &o)
Definition: unsigned_proto.hpp:33
Definition: unsigned_proto.hpp:25
UnsignedWrapper(UnsignedWrapper< T > &&w)
Definition: unsigned_proto.hpp:37
interface::types::HashType hash()
Definition: unsigned_proto.hpp:86
Definition: command_executor.hpp:12
std::enable_if_t< std::is_base_of< shared_model::interface::Transaction, U >::value, interface::types::HashType > reducedHash() const
Definition: unsigned_proto.hpp:94
T finish()
Definition: unsigned_proto.hpp:74
#define DEPRECATED
Definition: swig_keyword_hider.hpp:15
const PublicKeyType & publicKey() const
Definition: keypair.cpp:13
UnsignedWrapper & signAndAddSignature(const crypto::Keypair &keypair)
Definition: unsigned_proto.hpp:59