Skip to content

Commit

Permalink
Extract generic RespType and concrete tx responses
Browse files Browse the repository at this point in the history
Signed-off-by: Kitsu <[email protected]>
  • Loading branch information
l4l authored and lebdron committed Dec 19, 2017
1 parent a2341d1 commit 1c6ce34
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 38 deletions.
42 changes: 42 additions & 0 deletions shared_model/backend/protobuf/common_objects/common_proto.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
* http://soramitsu.co.jp
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "utils/reference_holder.hpp"

namespace shared_model {
namespace proto {
/**
* Simple generic class for handling proto objects
* @tparam Iface is interface to inherit from
* @tparam Proto is protobuf containter
*/
template <typename Iface, typename Proto>
class CommonProto final : public Iface {
public:
template <typename TxResponse>
explicit CommonProto(TxResponse &&ref)
: proto_(std::forward<TxResponse>(ref)) {}

typename Iface::ModelType *copy() const override {
return new CommonProto(*proto_);
}

private:
detail::ReferenceHolder<Proto> proto_;
};
} // namespace proto
} // namespace shared_model
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
* http://soramitsu.co.jp
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "backend/protobuf/common_objects/common_proto.hpp"
#include "endpoint.pb.h"
#include "interfaces/transaction_responses/committed_tx_response.hpp"
#include "interfaces/transaction_responses/stateful_failed_tx_response.hpp"
#include "interfaces/transaction_responses/stateful_valid_tx_response.hpp"
#include "interfaces/transaction_responses/stateless_failed_tx_response.hpp"
#include "interfaces/transaction_responses/stateless_valid_tx_response.hpp"
#include "interfaces/transaction_responses/tx_response.hpp"
#include "interfaces/transaction_responses/unknown_tx_response.hpp"

namespace shared_model {
namespace proto {
using StatelessFailedTxResponse =
CommonProto<interface::StatelessFailedTxResponse,
iroha::protocol::ToriiResponse>;
using StatelessValidTxResponse =
CommonProto<interface::StatelessValidTxResponse,
iroha::protocol::ToriiResponse>;
using StatefulFailedTxResponse =
CommonProto<interface::StatefulFailedTxResponse,
iroha::protocol::ToriiResponse>;
using StatefulValidTxResponse =
CommonProto<interface::StatefulValidTxResponse,
iroha::protocol::ToriiResponse>;
using CommittedTxResponse = CommonProto<interface::CommittedTxResponse,
iroha::protocol::ToriiResponse>;
using UnknownTxResponse = CommonProto<interface::UnknownTxResponse,
iroha::protocol::ToriiResponse>;
} // namespace proto
} // namespace shared_model
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@
#ifndef IROHA_PROTO_TX_RESPONSE_HPP
#define IROHA_PROTO_TX_RESPONSE_HPP

#include "endpoint.pb.h"
#include "interfaces/transaction_responses/committed_tx_response.hpp"
#include "interfaces/transaction_responses/stateful_failed_tx_response.hpp"
#include "interfaces/transaction_responses/stateful_valid_tx_response.hpp"
#include "interfaces/transaction_responses/stateless_failed_tx_response.hpp"
#include "interfaces/transaction_responses/stateless_valid_tx_response.hpp"
#include "interfaces/transaction_responses/tx_response.hpp"
#include "interfaces/transaction_responses/unknown_tx_response.hpp"
#include "backend/protobuf/transaction_responses/proto_concrete_tx_response.hpp"
#include "utils/lazy_initializer.hpp"
#include "utils/reference_holder.hpp"
#include "utils/variant_deserializer.hpp"
Expand All @@ -43,35 +36,6 @@ auto load(const iroha::protocol::ToriiResponse &ar) {

namespace shared_model {
namespace proto {
using RefToriiResp =
detail::ReferenceHolder<iroha::protocol::ToriiResponse>;

template <typename Iface>
class RespType final : public Iface {
public:
template <typename TxResponse>
explicit RespType(TxResponse &&ref)
: response_(std::forward<TxResponse>(ref)) {}

typename Iface::ModelType *copy() const override {
return new RespType(*response_);
}

private:
RefToriiResp response_;
};

using StatelessFailedTxResponse =
RespType<interface::StatelessFailedTxResponse>;
using StatelessValidTxResponse =
RespType<interface::StatelessValidTxResponse>;
using StatefulFailedTxResponse =
RespType<interface::StatefulFailedTxResponse>;
using StatefulValidTxResponse =
RespType<interface::StatefulValidTxResponse>;
using CommittedTxResponse = RespType<interface::CommittedTxResponse>;
using UnknownTxResponse = RespType<interface::UnknownTxResponse>;

/**
* TransactionResponse is a status of transaction in system
*/
Expand Down Expand Up @@ -127,7 +91,7 @@ namespace shared_model {
// ------------------------------| fields |-------------------------------

// proto
RefToriiResp response_;
detail::ReferenceHolder<iroha::protocol::ToriiResponse> response_;

template <typename T>
using Lazy = detail::LazyInitializer<T>;
Expand Down

0 comments on commit 1c6ce34

Please sign in to comment.