6 #ifndef IROHA_PROTO_COMMON_OBJECTS_FACTORY_HPP 7 #define IROHA_PROTO_COMMON_OBJECTS_FACTORY_HPP 19 #include "primitive.pb.h" 31 template <
typename Val
idator>
35 std::shared_ptr<validation::ValidatorsConfig> config)
36 : validator_(config) {}
40 interface::types::PublicKeyHexStringView public_key,
41 const std::optional<interface::types::TLSCertificateType>
42 &tls_certificate = std::nullopt)
override {
43 iroha::protocol::Peer peer;
44 peer.set_address(address);
45 std::string_view
const &public_key_string{public_key};
46 peer.set_peer_key(public_key_string.data(), public_key_string.size());
47 if (tls_certificate) {
48 peer.set_tls_certificate(*tls_certificate);
50 auto proto_peer = std::make_unique<Peer>(std::move(peer));
52 auto error = validator_.validatePeer(*proto_peer);
54 return validated<std::unique_ptr<interface::Peer>>(
55 std::move(proto_peer), error);
63 iroha::protocol::Account account;
64 account.set_account_id(account_id);
65 account.set_domain_id(domain_id);
66 account.set_quorum(quorum);
67 account.set_json_data(jsonData);
69 auto proto_account = std::make_unique<Account>(std::move(account));
71 auto error = validator_.validateAccount(*proto_account);
73 return validated<std::unique_ptr<interface::Account>>(
74 std::move(proto_account), error);
81 iroha::protocol::AccountAsset account_asset;
82 account_asset.set_account_id(account_id);
83 account_asset.set_asset_id(asset_id);
86 auto proto_account_asset =
87 std::make_unique<AccountAsset>(std::move(account_asset));
89 auto error = validator_.validateAccountAsset(*proto_account_asset);
91 return validated<std::unique_ptr<interface::AccountAsset>>(
92 std::move(proto_account_asset), error);
99 iroha::protocol::Asset asset;
100 asset.set_asset_id(asset_id);
101 asset.set_domain_id(domain_id);
102 asset.set_precision(precision);
104 auto proto_asset = std::make_unique<Asset>(std::move(asset));
106 auto error = validator_.validateAsset(*proto_asset);
108 return validated<std::unique_ptr<interface::Asset>>(
109 std::move(proto_asset), error);
115 iroha::protocol::Domain domain;
116 domain.set_domain_id(domain_id);
117 domain.set_default_role(default_role);
119 auto proto_domain = std::make_unique<Domain>(std::move(domain));
121 auto error = validator_.validateDomain(*proto_domain);
123 return validated<std::unique_ptr<interface::Domain>>(
124 std::move(proto_domain), error);
128 interface::types::PublicKeyHexStringView key,
129 interface::types::SignedHexStringView signed_data)
override {
130 iroha::protocol::Signature signature;
131 std::string_view
const &public_key_string{key};
132 signature.set_public_key(public_key_string.data(),
133 public_key_string.size());
134 std::string_view
const &signed_string{signed_data};
135 signature.set_signature(signed_string.data(), signed_string.size());
137 auto proto_singature =
138 std::make_unique<Signature>(std::move(signature));
140 auto error = validator_.validateSignatureForm(*proto_singature);
142 return validated<std::unique_ptr<interface::Signature>>(
143 std::move(proto_singature), error);
152 template <
typename ReturnValueType>
154 ReturnValueType
object,
155 const std::optional<validation::ValidationError> &error) {
157 return error.value().toString();
159 return iroha::expected::makeValue(std::move(
object));
162 Validator validator_;
167 #endif // IROHA_PROTO_COMMON_OBJECTS_FACTORY_HPP FactoryResult< std::unique_ptr< interface::Asset > > createAsset(const interface::types::AssetIdType &asset_id, const interface::types::DomainIdType &domain_id, interface::types::PrecisionType precision) override
Definition: proto_common_objects_factory.hpp:95
std::string AddressType
Type of peer address.
Definition: types.hpp:50
std::string DomainIdType
Iroha domain id type.
Definition: types.hpp:58
Definition: amount.hpp:21
Definition: result_fwd.hpp:27
std::string const & toStringRepr() const
Definition: amount.cpp:138
FactoryResult< std::unique_ptr< interface::AccountAsset > > createAccountAsset(const interface::types::AccountIdType &account_id, const interface::types::AssetIdType &asset_id, const interface::Amount &balance) override
Definition: proto_common_objects_factory.hpp:78
FactoryResult< std::unique_ptr< interface::Domain > > createDomain(const interface::types::DomainIdType &domain_id, const interface::types::RoleIdType &default_role) override
Definition: proto_common_objects_factory.hpp:112
Definition: proto_common_objects_factory.hpp:32
Definition: common_objects_factory.hpp:27
FactoryResult< std::unique_ptr< interface::Peer > > createPeer(const interface::types::AddressType &address, interface::types::PublicKeyHexStringView public_key, const std::optional< interface::types::TLSCertificateType > &tls_certificate=std::nullopt) override
Definition: proto_common_objects_factory.hpp:38
std::string AccountIdType
Type of account id.
Definition: types.hpp:38
FactoryResult< std::unique_ptr< interface::Signature > > createSignature(interface::types::PublicKeyHexStringView key, interface::types::SignedHexStringView signed_data) override
Definition: proto_common_objects_factory.hpp:127
ProtoCommonObjectsFactory(std::shared_ptr< validation::ValidatorsConfig > config)
Definition: proto_common_objects_factory.hpp:34
uint8_t PrecisionType
Type of precision.
Definition: types.hpp:46
Definition: command_executor.hpp:13
FactoryResult< std::unique_ptr< interface::Account > > createAccount(const interface::types::AccountIdType &account_id, const interface::types::DomainIdType &domain_id, interface::types::QuorumType quorum, const interface::types::JsonType &jsonData) override
Definition: proto_common_objects_factory.hpp:58
uint16_t QuorumType
Type of Quorum used in transaction and set quorum.
Definition: types.hpp:67
std::string JsonType
Type of JSON data.
Definition: types.hpp:79
std::string RoleIdType
Type of role (i.e admin, user)
Definition: types.hpp:56
std::string AssetIdType
Type of asset id.
Definition: types.hpp:60