forked from hyperledger-iroha/iroha-dco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract generic RespType and concrete tx responses
Signed-off-by: Kitsu <[email protected]>
- Loading branch information
Showing
3 changed files
with
91 additions
and
38 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
shared_model/backend/protobuf/common_objects/common_proto.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
47 changes: 47 additions & 0 deletions
47
shared_model/backend/protobuf/transaction_responses/proto_concrete_tx_response.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters