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 protobuf convertor for queries - Change namings from acc to acct - Add implementation for query hash - Add implementation for query crypto verification - Add to query model created time and hash - Add comments - Update pb schema for query
- Loading branch information
Showing
18 changed files
with
330 additions
and
67 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
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,84 @@ | ||
/** | ||
* 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/converters/pb_query_factory.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" | ||
|
||
namespace iroha { | ||
namespace model { | ||
namespace converters { | ||
|
||
std::shared_ptr<model::Query> PbQueryFactory::deserialize( | ||
protocol::Query &pb_query) { | ||
std::shared_ptr<model::Query> val; | ||
|
||
if (pb_query.has_get_account()) { | ||
// Convert to get Account | ||
auto pb_cast = pb_query.get_account(); | ||
auto account_query = GetAccount(); | ||
account_query.account_id = pb_cast.account_id(); | ||
val = std::make_shared<model::Query>(account_query); | ||
} | ||
|
||
if (pb_query.has_get_account_assets()) { | ||
// Convert to get Account Asset | ||
auto pb_cast = pb_query.get_account_assets(); | ||
auto query = GetAccountAssets(); | ||
query.account_id = pb_cast.account_id(); | ||
query.asset_id = pb_cast.asset_id(); | ||
val = std::make_shared<model::Query>(query); | ||
} | ||
if (pb_query.has_get_account_signatories()) { | ||
// Convert to get Signatories | ||
auto pb_cast = pb_query.get_account_signatories(); | ||
auto query = GetSignatories(); | ||
query.account_id = pb_cast.account_id(); | ||
val = std::make_shared<model::Query>(query); | ||
} | ||
|
||
if (pb_query.has_get_account_transactions()) { | ||
// Convert to get Signatories | ||
auto pb_cast = pb_query.get_account_transactions(); | ||
auto query = GetAccountTransactions(); | ||
query.account_id = pb_cast.account_id(); | ||
val = std::make_shared<model::Query>(query); | ||
} | ||
|
||
if (!val) { | ||
// Query not implemented | ||
return nullptr; | ||
} | ||
|
||
Signature sign; | ||
auto pb_sign = pb_query.header().signature(); | ||
std::copy(pb_sign.pubkey().begin(), pb_sign.pubkey().end(), | ||
sign.pubkey.begin()); | ||
|
||
std::copy(pb_sign.signature().begin(), pb_sign.signature().end(), | ||
sign.signature.begin()); | ||
|
||
val->signature = sign; | ||
val->created_ts = pb_query.header().created_time(); | ||
val->creator_account_id = pb_query.creator_account_id(); | ||
return val; | ||
} | ||
} | ||
} | ||
} |
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. | ||
*/ | ||
#ifndef IROHA_PB_QUERY_FACTORY_HPP | ||
#define IROHA_PB_QUERY_FACTORY_HPP | ||
|
||
#include "model/query.hpp" | ||
#include "queries.pb.h" | ||
|
||
namespace iroha { | ||
namespace model { | ||
namespace converters { | ||
|
||
/** | ||
* Converting business objects to protobuf and vice versa | ||
*/ | ||
class PbQueryFactory { | ||
public: | ||
|
||
/** | ||
* Convert proto query to model query | ||
* @param pb_block - reference to proto query | ||
* @return model Query | ||
*/ | ||
std::shared_ptr<model::Query> deserialize(protocol::Query &pb_query); | ||
|
||
|
||
}; | ||
|
||
} // namespace converters | ||
} // namespace model | ||
} // namespace iroha | ||
|
||
#endif // IROHA_PB_QUERY_FACTORY_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
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
Oops, something went wrong.