Line data Source code
1 : /**
2 : * Copyright Soramitsu Co., Ltd. All Rights Reserved.
3 : * SPDX-License-Identifier: Apache-2.0
4 : */
5 :
6 : #ifndef IROHA_TRANSPORT_BUILDER_HPP
7 : #define IROHA_TRANSPORT_BUILDER_HPP
8 :
9 : #include "common/result.hpp"
10 :
11 : namespace shared_model {
12 : namespace proto {
13 :
14 : /**
15 : * Class for building any shared model objects from corresponding transport
16 : * representation (e.g. protobuf object)
17 : * @tparam T Build type
18 : * @tparam SV Stateless validator type
19 : */
20 : template <typename T, typename SV>
21 : class [[deprecated]] TransportBuilder {
22 : public:
23 : TransportBuilder(const SV &validator = SV())
24 4 : : stateless_validator_(validator) {}
25 :
26 : /**
27 : * Builds result from transport object
28 : * @return value if transport object is valid and error message otherwise
29 : */
30 : iroha::expected::Result<T, std::string> build(
31 : typename T::TransportType transport) {
32 4 : auto result = T(transport);
33 4 : auto answer = stateless_validator_.validate(result);
34 4 : if (answer.hasErrors()) {
35 2 : return iroha::expected::makeError(answer.reason());
36 : }
37 2 : return iroha::expected::makeValue(T(std::move(transport)));
38 4 : }
39 :
40 : private:
41 : SV stateless_validator_;
42 : };
43 :
44 : } // namespace proto
45 : } // namespace shared_model
46 : #endif // IROHA_TRANSPORT_BUILDER_HPP
|