Line data Source code
1 : /**
2 : * Copyright Soramitsu Co., Ltd. All Rights Reserved.
3 : * SPDX-License-Identifier: Apache-2.0
4 : */
5 :
6 : #include "backend/protobuf/commands/proto_command.hpp"
7 :
8 : #include "backend/protobuf/commands/proto_add_asset_quantity.hpp"
9 : #include "backend/protobuf/commands/proto_add_peer.hpp"
10 : #include "backend/protobuf/commands/proto_add_signatory.hpp"
11 : #include "backend/protobuf/commands/proto_append_role.hpp"
12 : #include "backend/protobuf/commands/proto_create_account.hpp"
13 : #include "backend/protobuf/commands/proto_create_asset.hpp"
14 : #include "backend/protobuf/commands/proto_create_domain.hpp"
15 : #include "backend/protobuf/commands/proto_create_role.hpp"
16 : #include "backend/protobuf/commands/proto_detach_role.hpp"
17 : #include "backend/protobuf/commands/proto_grant_permission.hpp"
18 : #include "backend/protobuf/commands/proto_remove_signatory.hpp"
19 : #include "backend/protobuf/commands/proto_revoke_permission.hpp"
20 : #include "backend/protobuf/commands/proto_set_account_detail.hpp"
21 : #include "backend/protobuf/commands/proto_set_quorum.hpp"
22 : #include "backend/protobuf/commands/proto_subtract_asset_quantity.hpp"
23 : #include "backend/protobuf/commands/proto_transfer_asset.hpp"
24 : #include "logger/logger.hpp"
25 : #include "utils/variant_deserializer.hpp"
26 :
27 : namespace {
28 : /// type of proto variant
29 : using ProtoCommandVariantType =
30 : ::boost::variant<shared_model::proto::AddAssetQuantity,
31 : shared_model::proto::AddPeer,
32 : shared_model::proto::AddSignatory,
33 : shared_model::proto::AppendRole,
34 : shared_model::proto::CreateAccount,
35 : shared_model::proto::CreateAsset,
36 : shared_model::proto::CreateDomain,
37 : shared_model::proto::CreateRole,
38 : shared_model::proto::DetachRole,
39 : shared_model::proto::GrantPermission,
40 : shared_model::proto::RemoveSignatory,
41 : shared_model::proto::RevokePermission,
42 : shared_model::proto::SetAccountDetail,
43 : shared_model::proto::SetQuorum,
44 : shared_model::proto::SubtractAssetQuantity,
45 : shared_model::proto::TransferAsset>;
46 :
47 : /// list of types in proto variant
48 : using ProtoCommandListType = ProtoCommandVariantType::types;
49 : } // namespace
50 :
51 : namespace shared_model {
52 : namespace proto {
53 :
54 : struct Command::Impl {
55 : explicit Impl(TransportType &ref) : proto_(ref) {}
56 :
57 : TransportType &proto_;
58 :
59 : ProtoCommandVariantType variant_{[this] {
60 67300 : auto &ar = proto_;
61 67300 : int which =
62 67300 : ar.GetDescriptor()->FindFieldByNumber(ar.command_case())->index();
63 67300 : return shared_model::detail::variant_impl<ProtoCommandListType>::
64 67300 : template load<ProtoCommandVariantType>(ar, which);
65 : }()};
66 :
67 67221 : CommandVariantType ivariant_{variant_};
68 : };
69 :
70 : Command::Command(Command &&o) noexcept = default;
71 :
72 : Command::Command(TransportType &ref) {
73 67344 : impl_ = std::make_unique<Impl>(ref);
74 67344 : }
75 :
76 : Command::~Command() = default;
77 :
78 : const Command::CommandVariantType &Command::get() const {
79 37126 : return impl_->ivariant_;
80 : }
81 :
82 : Command *Command::clone() const {
83 0 : throw std::runtime_error(
84 : "tried to clone a proto command, which is uncloneable");
85 0 : }
86 :
87 : } // namespace proto
88 : } // namespace shared_model
|