Line data Source code
1 : /**
2 : * Copyright Soramitsu Co., Ltd. All Rights Reserved.
3 : * SPDX-License-Identifier: Apache-2.0
4 : */
5 :
6 : #include "model/converters/pb_common.hpp"
7 :
8 : #include "common/byteutils.hpp"
9 : #include "model/command.hpp"
10 : #include "model/commands/all.hpp"
11 : #include "model/domain.hpp"
12 : #include "qry_responses.pb.h"
13 :
14 : namespace iroha {
15 : namespace model {
16 : namespace converters {
17 :
18 : protocol::Peer serializePeer(iroha::model::Peer iroha_peer) {
19 4 : protocol::Peer res;
20 4 : res.set_address(iroha_peer.address);
21 4 : res.set_peer_key(iroha_peer.pubkey.to_hexstring());
22 4 : return res;
23 4 : }
24 :
25 : iroha::model::Peer deserializePeer(protocol::Peer pb_peer) {
26 2 : iroha::model::Peer res;
27 2 : res.address = pb_peer.address();
28 2 : auto blob = iroha::hexstringToBytestring(pb_peer.peer_key());
29 2 : if (not blob) {
30 0 : return res;
31 : }
32 2 : std::copy(blob->begin(),
33 2 : blob->end(),
34 2 : res.pubkey.begin());
35 2 : return res;
36 2 : }
37 :
38 : iroha::protocol::Account serializeAccount(
39 : const iroha::model::Account &account) {
40 0 : iroha::protocol::Account pb_account{};
41 0 : pb_account.set_account_id(account.account_id);
42 0 : pb_account.set_domain_id(account.domain_id);
43 0 : pb_account.set_json_data(account.json_data);
44 0 : pb_account.set_quorum(account.quorum);
45 0 : return pb_account;
46 0 : }
47 :
48 : iroha::protocol::Asset serializeAsset(const iroha::model::Asset &asset) {
49 0 : iroha::protocol::Asset pb_asset{};
50 0 : pb_asset.set_asset_id(asset.asset_id);
51 0 : pb_asset.set_domain_id(asset.domain_id);
52 0 : pb_asset.set_precision(asset.precision);
53 0 : return pb_asset;
54 0 : }
55 :
56 : iroha::protocol::AccountAsset serializeAccountAsset(
57 : const iroha::model::AccountAsset &account_asset) {
58 0 : iroha::protocol::AccountAsset pb_account_asset{};
59 0 : pb_account_asset.set_account_id(account_asset.account_id);
60 0 : pb_account_asset.set_asset_id(account_asset.asset_id);
61 0 : pb_account_asset.set_balance(account_asset.balance);
62 0 : return pb_account_asset;
63 0 : }
64 :
65 : iroha::protocol::Domain serializeDomain(
66 : const iroha::model::Domain &domain) {
67 0 : iroha::protocol::Domain pb_domain{};
68 0 : pb_domain.set_domain_id(domain.domain_id);
69 0 : pb_domain.set_default_role(domain.default_role);
70 0 : return pb_domain;
71 0 : }
72 : } // namespace converters
73 : } // namespace model
74 : } // namespace iroha
|