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.
Implement shared model proto query response:
- Implement proto container for Query responses - Implement account asset response proto class Signed-off-by: luckychess <[email protected]>
- Loading branch information
1 parent
9dddcbb
commit a2b002d
Showing
4 changed files
with
175 additions
and
8 deletions.
There are no files selected for viewing
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
70 changes: 70 additions & 0 deletions
70
shared_model/backend/protobuf/query_responses/proto_account_asset_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,70 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
#ifndef IROHA_PROTO_ACCOUNT_ASSET_RESPONSE_HPP | ||
#define IROHA_PROTO_ACCOUNT_ASSET_RESPONSE_HPP | ||
|
||
#include "backend/protobuf/common_objects/proto_account_asset.hpp" | ||
#include "interfaces/query_responses/account_asset_response.hpp" | ||
#include "responses.pb.h" | ||
#include "utils/lazy_initializer.hpp" | ||
#include "utils/reference_holder.hpp" | ||
|
||
namespace shared_model { | ||
namespace proto { | ||
class AccountAssetResponse final : public interface::AccountAssetResponse { | ||
public: | ||
template <typename QueryResponseType> | ||
explicit AccountAssetResponse(QueryResponseType &&queryResponse) | ||
: queryResponse_(std::forward<QueryResponseType>(queryResponse)), | ||
accountAssetResponse_( | ||
[this] { return queryResponse_->account_assets_response(); }), | ||
accountAsset_([this] { | ||
return AccountAsset(accountAssetResponse_->account_asset()); | ||
}) {} | ||
|
||
AccountAssetResponse(const AccountAssetResponse &accountAssetResponse) | ||
: AccountAssetResponse(*accountAssetResponse.queryResponse_) {} | ||
|
||
AccountAssetResponse(AccountAssetResponse &&accountAssetResponse) | ||
: AccountAssetResponse( | ||
std::move(accountAssetResponse.queryResponse_.variant())) {} | ||
|
||
const interface::AccountAsset &accountAsset() const override { | ||
return *accountAsset_; | ||
} | ||
|
||
ModelType *copy() const override { | ||
return new AccountAssetResponse( | ||
iroha::protocol::QueryResponse(*queryResponse_)); | ||
} | ||
|
||
private: | ||
detail::ReferenceHolder<iroha::protocol::QueryResponse> queryResponse_; | ||
|
||
template <typename T> | ||
using Lazy = detail::LazyInitializer<T>; | ||
|
||
const Lazy<const iroha::protocol::AccountAssetResponse &> | ||
accountAssetResponse_; | ||
|
||
const Lazy<AccountAsset> accountAsset_; | ||
}; | ||
} // namespace proto | ||
} // namespace shared_model | ||
|
||
#endif // IROHA_PROTO_ACCOUNT_ASSET_RESPONSE_HPP |
96 changes: 96 additions & 0 deletions
96
shared_model/backend/protobuf/query_responses/proto_query_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,96 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
#ifndef IROHA_PROTO_QUERY_RESPONSE_HPP | ||
#define IROHA_PROTO_QUERY_RESPONSE_HPP | ||
|
||
#include "backend/protobuf/query_responses/proto_account_asset_response.hpp" | ||
#include "interfaces/queries/query.hpp" | ||
#include "interfaces/query_responses/query_response.hpp" | ||
#include "responses.pb.h" | ||
#include "utils/lazy_initializer.hpp" | ||
#include "utils/variant_deserializer.hpp" | ||
|
||
template <typename... T, typename Archive> | ||
auto loadQueryResponse(Archive &&ar) { | ||
int which = | ||
ar.GetDescriptor()->FindFieldByNumber(ar.response_case())->index(); | ||
return shared_model::detail::variant_impl<T...>::template load< | ||
shared_model::interface::QueryResponse::QueryResponseVariantType>( | ||
std::forward<Archive>(ar), which); | ||
} | ||
|
||
namespace shared_model { | ||
namespace proto { | ||
class QueryResponse final : public interface::QueryResponse { | ||
private: | ||
template <typename Value> | ||
using w = detail::PolymorphicWrapper<Value>; | ||
|
||
template <typename T> | ||
using Lazy = detail::LazyInitializer<T>; | ||
|
||
using LazyVariantType = Lazy<QueryResponseVariantType>; | ||
|
||
public: | ||
/// type of proto variant | ||
using ProtoQueryResponseVariantType = | ||
boost::variant<w<AccountAssetResponse>>; | ||
|
||
/// list of types in variant | ||
using ProtoQueryResponseListType = ProtoQueryResponseVariantType::types; | ||
|
||
/// Type of query hash | ||
using QueryHashType = interface::Query::HashType; | ||
|
||
template <typename QueryResponseType> | ||
explicit QueryResponse(QueryResponseType &&queryResponse) | ||
: queryResponse_(std::forward<QueryResponseType>(queryResponse)), | ||
variant_([this] { | ||
return loadQueryResponse<ProtoQueryResponseListType>( | ||
*queryResponse_); | ||
}), | ||
hash_([this] { | ||
return QueryHashType(queryResponse_->query_hash()); | ||
}) {} | ||
|
||
QueryResponse(const QueryResponse &o) | ||
: QueryResponse(*o.queryResponse_) {} | ||
|
||
QueryResponse(QueryResponse &&o) noexcept | ||
: QueryResponse(std::move(o.queryResponse_.variant())) {} | ||
|
||
const QueryResponseVariantType &get() const override { return *variant_; } | ||
|
||
const QueryHashType &queryHash() const override { return *hash_; } | ||
|
||
ModelType *copy() const override { | ||
return new QueryResponse( | ||
iroha::protocol::QueryResponse(*queryResponse_)); | ||
} | ||
|
||
private: | ||
detail::ReferenceHolder<iroha::protocol::QueryResponse> queryResponse_; | ||
|
||
const LazyVariantType variant_; | ||
|
||
const Lazy<QueryHashType> hash_; | ||
}; | ||
} // namespace proto | ||
} // namespace shared_model | ||
|
||
#endif // IROHA_PROTO_QUERY_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