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.
- Add creator_account to query - Remove client from query-response
- Loading branch information
Showing
9 changed files
with
296 additions
and
9 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
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,214 @@ | ||
/** | ||
* 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 "model/query_execution.hpp" | ||
#include <ametsuchi/block_query.hpp> | ||
#include "common/types.hpp" | ||
#include "model/queries/responses/account_assets_response.hpp" | ||
#include "model/queries/responses/account_response.hpp" | ||
#include "model/queries/responses/error_response.hpp" | ||
#include "model/queries/responses/signatories_response.hpp" | ||
#include "model/queries/responses/transactions_response.hpp" | ||
|
||
iroha::model::QueryProcessingFactory::QueryProcessingFactory( | ||
ametsuchi::WsvQuery& wsvQuery, ametsuchi::BlockQuery& blockQuery) { | ||
_wsvQuery = wsvQuery; | ||
_blockQuery = blockQuery; | ||
} | ||
|
||
bool iroha::model::QueryProcessingFactory::validate( | ||
const model::GetAccount& query) { | ||
auto creator = _wsvQuery.getAccount(query.creator_account_id); | ||
return | ||
// Creator account exits | ||
creator.has_value() && | ||
// Creator has permission to read, or account = creator | ||
(creator.value().permissions.read_all_accounts || | ||
query.account_id == query.creator_account_id); | ||
} | ||
|
||
bool iroha::model::QueryProcessingFactory::validate( | ||
const model::GetSignatories& query) { | ||
auto creator = _wsvQuery.getAccount(query.creator_account_id); | ||
return | ||
// Creator account exits | ||
creator.has_value() && | ||
// Creator has permission to read, or account = creator | ||
(creator.value().permissions.read_all_accounts || | ||
query.account_id == query.creator_account_id); | ||
} | ||
|
||
bool iroha::model::QueryProcessingFactory::validate( | ||
const model::GetAccountAssets& query) { | ||
auto creator = _wsvQuery.getAccount(query.creator_account_id); | ||
return | ||
// Creator account exits | ||
creator.has_value() && | ||
// Creator has permission to read, or account = creator | ||
(creator.value().permissions.read_all_accounts || | ||
query.account_id == query.creator_account_id); | ||
} | ||
|
||
bool iroha::model::QueryProcessingFactory::validate( | ||
const model::GetAccountTransactions& query) { | ||
auto creator = _wsvQuery.getAccount(query.creator_account_id); | ||
return | ||
// Creator account exits | ||
creator.has_value() && | ||
// Creator has permission to read, or account = creator | ||
(creator.value().permissions.read_all_accounts || | ||
query.account_id == query.creator_account_id); | ||
} | ||
|
||
bool iroha::model::QueryProcessingFactory::validate( | ||
const model::GetAccountAssetTransactions& query) { | ||
auto creator = _wsvQuery.getAccount(query.creator_account_id); | ||
return | ||
// Creator account exits | ||
creator.has_value() && | ||
// Creator has permission to read, or account = creator | ||
(creator.value().permissions.read_all_accounts || | ||
query.account_id == query.creator_account_id); | ||
} | ||
|
||
iroha::model::QueryResponse | ||
iroha::model::QueryProcessingFactory::executeGetAccount( | ||
const model::GetAccount& query) { | ||
auto acc = _wsvQuery.getAccount(query.account_id); | ||
if (!acc.has_value()) { | ||
iroha::model::ErrorResponse response; | ||
response.query = query; | ||
response.reason = "No account"; | ||
return response; | ||
} | ||
iroha::model::AccountResponse response; | ||
response.account = acc.value(); | ||
response.query = query; | ||
return response; | ||
} | ||
|
||
iroha::model::QueryResponse | ||
iroha::model::QueryProcessingFactory::executeGetAccountAssets( | ||
const model::GetAccountAssets& query) { | ||
auto acc_assets = _wsvQuery.getAccountAsset(query.account_id, query.asset_id); | ||
if (!acc_assets.has_value()) { | ||
iroha::model::ErrorResponse response; | ||
response.query = query; | ||
response.reason = "No Account Asset"; | ||
return response; | ||
} | ||
iroha::model::AccountAssetsResponse response; | ||
response.= acc_assets.value(); | ||
response.query = query; | ||
return response; | ||
} | ||
|
||
iroha::model::QueryResponse | ||
iroha::model::QueryProcessingFactory::executeGetAccountAssetTransactions( | ||
const model::GetAccountAssetTransactions& query) { | ||
// auto acc_asset_tx = _blockQuery. | ||
// TODO: implement | ||
iroha::model::ErrorResponse response; | ||
response.query = query; | ||
response.reason = "Not implemented"; | ||
return response; | ||
} | ||
|
||
iroha::model::QueryResponse | ||
iroha::model::QueryProcessingFactory::executeGetAccountTransactions( | ||
const model::GetAccountTransactions& query) { | ||
auto acc_tx = _blockQuery.getAccountTransactions(query.account_id); | ||
iroha::model::TransactionsResponse response; | ||
response.query = query; | ||
response.transactions = acc_tx; | ||
return response; | ||
} | ||
|
||
iroha::model::QueryResponse | ||
iroha::model::QueryProcessingFactory::executeGetSignatories( | ||
const model::GetSignatories& query) { | ||
auto signs = _wsvQuery.getSignatories(query.account_id); | ||
if (!signs.has_value()) { | ||
iroha::model::ErrorResponse response; | ||
response.query = query; | ||
response.reason = "No signatories"; | ||
return response; | ||
} | ||
iroha::model::SignatoriesResponse response; | ||
response.query = query; | ||
response.keys = signs.value(); | ||
return response; | ||
} | ||
|
||
iroha::model::QueryResponse iroha::model::QueryProcessingFactory::execute( | ||
const model::Query& query) { | ||
if (instanceof <iroha::model::GetAccount>(query)) { | ||
auto qry = static_cast<const iroha::model::GetAccount&>(query); | ||
if (!validate(qry)) { | ||
iroha::model::ErrorResponse response; | ||
response.query = qry; | ||
response.reason = "Not valid query"; | ||
return response; | ||
} | ||
return executeGetAccount(qry); | ||
} | ||
if (instanceof <iroha::model::GetAccountAssets>(query)) { | ||
auto qry = static_cast<const iroha::model::GetAccountAssets&>(query); | ||
if (!validate(qry)) { | ||
iroha::model::ErrorResponse response; | ||
response.query = qry; | ||
response.reason = "Not valid query"; | ||
return response; | ||
} | ||
return executeGetAccountAssets(qry); | ||
} | ||
if (instanceof <iroha::model::GetSignatories>(query)) { | ||
auto qry = static_cast<const iroha::model::GetSignatories&>(query); | ||
if (!validate(qry)) { | ||
iroha::model::ErrorResponse response; | ||
response.query = qry; | ||
response.reason = "Not valid query"; | ||
return response; | ||
} | ||
return executeGetSignatories(qry); | ||
} | ||
if (instanceof <iroha::model::GetAccountTransactions>(query)) { | ||
auto qry = static_cast<const iroha::model::GetAccountTransactions&>(query); | ||
if (!validate(qry)) { | ||
iroha::model::ErrorResponse response; | ||
response.query = qry; | ||
response.reason = "Not valid query"; | ||
return response; | ||
} | ||
return executeGetAccountTransactions(qry); | ||
} | ||
if (instanceof <iroha::model::GetAccountAssetTransactions>(query)) { | ||
auto qry = | ||
static_cast<const iroha::model::GetAccountAssetTransactions&>(query); | ||
if (!validate(qry)) { | ||
iroha::model::ErrorResponse response; | ||
response.query = qry; | ||
response.reason = "Not valid query"; | ||
return response; | ||
} | ||
return executeGetAccountAssetTransactions(qry); | ||
} | ||
iroha::model::ErrorResponse response; | ||
response.query = query; | ||
response.reason = "Not implemented"; | ||
return response; | ||
} |
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
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
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
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
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
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,67 @@ | ||
/** | ||
* 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_QUERY_EXECUTION_HPP | ||
#define IROHA_QUERY_EXECUTION_HPP | ||
|
||
#include <nonstd/optional.hpp> | ||
#include "model/query.hpp" | ||
#include "model/query_response.hpp" | ||
|
||
#include "model/queries/get_account.hpp" | ||
#include "model/queries/get_account_assets.hpp" | ||
#include "model/queries/get_signatories.hpp" | ||
#include "model/queries/get_transactions.hpp" | ||
|
||
#include "ametsuchi/wsv_query.hpp" | ||
|
||
namespace iroha { | ||
namespace model { | ||
|
||
/** | ||
* Converting business objects to protobuf and vice versa | ||
*/ | ||
class QueryProcessingFactory { | ||
public: | ||
model::QueryResponse execute(const model::Query& query); | ||
QueryProcessingFactory(ametsuchi::WsvQuery& wsvQuery, | ||
ametsuchi::BlockQuery& blockQuery); | ||
|
||
private: | ||
bool validate(const model::GetAccountAssets& query); | ||
bool validate(const model::GetAccount& query); | ||
bool validate(const model::GetSignatories& query); | ||
bool validate(const model::GetAccountAssetTransactions& query); | ||
bool validate(const model::GetAccountTransactions& query); | ||
|
||
model::QueryResponse executeGetAccountAssets( | ||
const model::GetAccountAssets& query); | ||
model::QueryResponse executeGetAccount(const model::GetAccount& query); | ||
model::QueryResponse executeGetSignatories( | ||
const model::GetSignatories& query); | ||
model::QueryResponse executeGetAccountAssetTransactions( | ||
const model::GetAccountAssetTransactions& query); | ||
model::QueryResponse executeGetAccountTransactions( | ||
const model::GetAccountTransactions& query); | ||
|
||
ametsuchi::WsvQuery _wsvQuery; | ||
ametsuchi::BlockQuery _blockQuery; | ||
}; | ||
|
||
} // namespace model | ||
} // namespace iroha | ||
|
||
#endif // IROHA_QUERY_EXECUTION_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