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/generators/command_generator.hpp"
7 : #include "model/commands/add_asset_quantity.hpp"
8 : #include "model/commands/add_peer.hpp"
9 : #include "model/commands/add_signatory.hpp"
10 : #include "model/commands/append_role.hpp"
11 : #include "model/commands/create_account.hpp"
12 : #include "model/commands/create_asset.hpp"
13 : #include "model/commands/create_domain.hpp"
14 : #include "model/commands/create_role.hpp"
15 : #include "model/commands/remove_signatory.hpp"
16 : #include "model/commands/set_account_detail.hpp"
17 : #include "model/commands/set_quorum.hpp"
18 : #include "model/commands/subtract_asset_quantity.hpp"
19 : #include "model/commands/transfer_asset.hpp"
20 : #include "validators/permissions.hpp"
21 :
22 : using namespace generator;
23 : using namespace shared_model::permissions;
24 :
25 : namespace iroha {
26 : namespace model {
27 : namespace generators {
28 :
29 : std::shared_ptr<Command> CommandGenerator::generateAddPeer(
30 : const Peer &peer) {
31 0 : return generateCommand<AddPeer>(peer);
32 0 : }
33 :
34 : std::shared_ptr<Command> CommandGenerator::generateAddSignatory(
35 : const std::string &account_id, const pubkey_t &key) {
36 0 : return generateCommand<AddSignatory>(account_id, key);
37 0 : }
38 :
39 : std::shared_ptr<Command> CommandGenerator::generateRemoveSignatory(
40 : const std::string &account_id, const pubkey_t &key) {
41 0 : return generateCommand<RemoveSignatory>(account_id, key);
42 0 : }
43 :
44 : std::shared_ptr<Command> CommandGenerator::generateCreateAccount(
45 : const std::string &account_name,
46 : const std::string &domain_id,
47 : const pubkey_t &key) {
48 0 : return generateCommand<CreateAccount>(account_name, domain_id, key);
49 0 : }
50 :
51 : std::shared_ptr<Command> CommandGenerator::generateCreateDomain(
52 : const std::string &domain_id, const std::string &default_role) {
53 0 : return generateCommand<CreateDomain>(domain_id, default_role);
54 0 : }
55 :
56 : std::shared_ptr<Command> CommandGenerator::generateCreateAsset(
57 : const std::string &asset_name,
58 : const std::string &domain_id,
59 : uint8_t precision) {
60 0 : return generateCommand<CreateAsset>(asset_name, domain_id, precision);
61 0 : }
62 :
63 : std::shared_ptr<Command> CommandGenerator::generateCreateAdminRole(
64 : std::string role_name) {
65 0 : std::set<std::string> perms = {
66 0 : can_create_domain, can_create_account, can_add_peer};
67 0 : perms.insert(edit_self_group.begin(), edit_self_group.end());
68 0 : perms.insert(read_all_group.begin(), read_all_group.end());
69 0 : return std::make_shared<CreateRole>(role_name, perms);
70 0 : }
71 :
72 : std::shared_ptr<Command> CommandGenerator::generateCreateUserRole(
73 : std::string role_name) {
74 0 : std::set<std::string> perms = {can_receive, can_transfer};
75 : // User can read their account
76 0 : perms.insert(read_self_group.begin(), read_self_group.end());
77 : // User can grant permissions to others
78 0 : perms.insert(grant_group.begin(), grant_group.end());
79 0 : perms.insert(edit_self_group.begin(), edit_self_group.end());
80 0 : return std::make_shared<CreateRole>(role_name, perms);
81 0 : }
82 :
83 : std::shared_ptr<Command> CommandGenerator::generateCreateAssetCreatorRole(
84 : std::string role_name) {
85 0 : std::set<std::string> perms = {can_receive, can_transfer};
86 0 : perms.insert(asset_creator_group.begin(), asset_creator_group.end());
87 0 : perms.insert(read_self_group.begin(), read_self_group.begin());
88 0 : return std::make_shared<CreateRole>(role_name, perms);
89 0 : }
90 :
91 : std::shared_ptr<Command> CommandGenerator::generateAddAssetQuantity(
92 : const std::string &asset_id, const std::string &amount) {
93 0 : return generateCommand<AddAssetQuantity>(asset_id, amount);
94 0 : }
95 :
96 : std::shared_ptr<Command> CommandGenerator::generateSubtractAssetQuantity(
97 : const std::string &asset_id, const std::string &amount) {
98 0 : return generateCommand<SubtractAssetQuantity>(asset_id, amount);
99 0 : }
100 :
101 : std::shared_ptr<Command> CommandGenerator::generateSetQuorum(
102 : const std::string &account_id, uint32_t quorum) {
103 0 : return generateCommand<SetQuorum>(account_id, quorum);
104 0 : }
105 :
106 : std::shared_ptr<Command> CommandGenerator::generateTransferAsset(
107 : const std::string &src_account,
108 : const std::string &dest_account,
109 : const std::string &asset_id,
110 : const std::string &amount) {
111 0 : return generateCommand<TransferAsset>(
112 0 : src_account, dest_account, asset_id, amount);
113 0 : }
114 :
115 : std::shared_ptr<Command> CommandGenerator::generateAppendRole(
116 : const std::string &account_id, const std::string &role_name) {
117 0 : return generateCommand<AppendRole>(account_id, role_name);
118 0 : }
119 :
120 : } // namespace generators
121 : } // namespace model
122 : } // namespace iroha
|