Line data Source code
1 : /**
2 : * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
3 : * http://soramitsu.co.jp
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 :
18 : #ifndef IROHA_SHARED_MODEL_MODEL_TRANSACTION_BUILDER_HPP
19 : #define IROHA_SHARED_MODEL_MODEL_TRANSACTION_BUILDER_HPP
20 :
21 : #include "builders/protobuf/builder_templates/transaction_template.hpp"
22 : #include "builders/protobuf/unsigned_proto.hpp"
23 : #include "cryptography/public_key.hpp"
24 :
25 : namespace shared_model {
26 : namespace bindings {
27 : /**
28 : * Wrapper class for transaction builder. Designed only for SWIG bindings,
29 : * don't use in other cases.
30 : */
31 : class ModelTransactionBuilder {
32 : private:
33 : template <int Sp>
34 : explicit ModelTransactionBuilder(
35 : const proto::TemplateTransactionBuilder<Sp> &o)
36 0 : : builder_(o) {}
37 :
38 : public:
39 : ModelTransactionBuilder();
40 :
41 : /**
42 : * Sets id of account creator
43 : * @param account_id - account id
44 : * @return builder with account_id field appended
45 : */
46 : ModelTransactionBuilder creatorAccountId(
47 : const interface::types::AccountIdType &account_id);
48 :
49 : /**
50 : * Sets time of creation
51 : * @param created_time - time of creation
52 : * @return builder with created_time field appended
53 : */
54 : ModelTransactionBuilder createdTime(
55 : interface::types::TimestampType created_time);
56 :
57 : /**
58 : * Sets transaction quorum
59 : * @param quorum to set
60 : * @return builder with quorum field appended
61 : */
62 : ModelTransactionBuilder quorum(interface::types::QuorumType quorum);
63 :
64 : /**
65 : * Sets batch meta
66 : * @param type - one of ATOMIC or ORDERED
67 : * @param hashes - vector of hashes of transactions in this batch
68 : * @return builder with batchMeta set
69 : */
70 : ModelTransactionBuilder batchMeta(
71 : interface::types::BatchType type,
72 : const std::vector<interface::types::HashType> &hashes);
73 :
74 : /**
75 : * Adds given quantity of given asset to account
76 : * @param asset_id - asset id
77 : * @param amount - amount of asset to add
78 : * @return builder with asset quantity command appended
79 : */
80 : ModelTransactionBuilder addAssetQuantity(
81 : const interface::types::AssetIdType &asset_id,
82 : const std::string &amount);
83 :
84 : /**
85 : * Adds new peer into ledger
86 : * @param address - peer address
87 : * @param peer_key - peer public key
88 : * @return builder with added peer command appended
89 : */
90 : ModelTransactionBuilder addPeer(
91 : const interface::types::AddressType &address,
92 : const crypto::PublicKey &peer_key);
93 :
94 : /**
95 : * Adds new signatory
96 : * @param account_id - id of signatory's account
97 : * @param public_key - public key of signatory
98 : * @return builder with added signatory command appended
99 : */
100 : ModelTransactionBuilder addSignatory(
101 : const interface::types::AddressType &account_id,
102 : const crypto::PublicKey &public_key);
103 :
104 : /**
105 : * Removes signatory
106 : * @param account_id - id of signatory's account to remove
107 : * @param public_key - public key of signatory
108 : * @return builder with removed signatory command appended
109 : */
110 : ModelTransactionBuilder removeSignatory(
111 : const interface::types::AddressType &account_id,
112 : const crypto::PublicKey &public_key);
113 :
114 : /**
115 : * Appends role
116 : * @param account_id - account id to append role
117 : * @param role_name - role name to append
118 : * @return builder with append role command appended
119 : */
120 : ModelTransactionBuilder appendRole(
121 : const interface::types::AccountIdType &account_id,
122 : const interface::types::RoleIdType &role_name);
123 :
124 : /**
125 : * Creates asset
126 : * @param asset_name - asset name to create
127 : * @param domain_id - domain id to create asset in
128 : * @param precision - asset precision
129 : * @return builder with create asset command appended
130 : */
131 : ModelTransactionBuilder createAsset(
132 : const interface::types::AssetNameType &asset_name,
133 : const interface::types::DomainIdType &domain_id,
134 : interface::types::PrecisionType precision);
135 :
136 : /**
137 : * Creates new account
138 : * @param account_name - name of account to create
139 : * @param domain_id - id of domain where account will be created
140 : * @param main_pubkey - main public key of account
141 : * @return builder with new account command appended
142 : */
143 : ModelTransactionBuilder createAccount(
144 : const interface::types::AccountNameType &account_name,
145 : const interface::types::AddressType &domain_id,
146 : const crypto::PublicKey &main_pubkey);
147 :
148 : /**
149 : * Creates new domain
150 : * @param domain_id - domain name to create
151 : * @param default_role - default role name
152 : * @return builder with new domain command appended
153 : */
154 : ModelTransactionBuilder createDomain(
155 : const interface::types::AddressType &domain_id,
156 : const interface::types::RoleIdType &default_role);
157 :
158 : /**
159 : * Creates role
160 : * @param role_name - role name to create
161 : * @param permissions - permissions to include in new role
162 : * @return builder with create role command appended
163 : */
164 : ModelTransactionBuilder createRole(
165 : const interface::types::RoleIdType &role_name,
166 : const interface::RolePermissionSet &permissions);
167 :
168 : /**
169 : * Detaches role
170 : * @param account_id - account id to detach role from
171 : * @param role_name - role name to detach
172 : * @return builder with detach role command appended
173 : */
174 : ModelTransactionBuilder detachRole(
175 : const interface::types::AccountIdType &account_id,
176 : const interface::types::RoleIdType &role_name);
177 :
178 : /**
179 : * Grants permission
180 : * @param account_id - account id to grant permission
181 : * @param permission - permission to grant
182 : * @return builder with grant permission command appended
183 : */
184 : ModelTransactionBuilder grantPermission(
185 : const interface::types::AccountIdType &account_id,
186 : interface::permissions::Grantable permission);
187 :
188 : /**
189 : * Revokes permission
190 : * @param account_id - account id to revoke permission
191 : * @param permission - permission to revoke
192 : * @return builder with revoke permission command appended
193 : */
194 : ModelTransactionBuilder revokePermission(
195 : const interface::types::AccountIdType &account_id,
196 : interface::permissions::Grantable permission);
197 :
198 : /**
199 : * Sets account detail
200 : * @param account_id - account id to set detail
201 : * @param key - detail key
202 : * @param value - detail value
203 : * @return builder with set account detail command appended
204 : */
205 : ModelTransactionBuilder setAccountDetail(
206 : const interface::types::AccountIdType &account_id,
207 : const interface::types::AccountDetailKeyType &key,
208 : const interface::types::AccountDetailValueType &value);
209 :
210 : /**
211 : * Sets account quorum
212 : * @param account_id - id of account to set quorum
213 : * @param quorum - quorum amount
214 : * @return builder with set account quorum command appended
215 : */
216 : ModelTransactionBuilder setAccountQuorum(
217 : const interface::types::AddressType &account_id,
218 : interface::types::QuorumType quorum);
219 :
220 : /**
221 : * Subtracts asset quantity
222 : * @param asset_id - asset id to subtract
223 : * @param amount - amount to subtract
224 : * @return builder with subtract asset quantity command appended
225 : */
226 : ModelTransactionBuilder subtractAssetQuantity(
227 : const interface::types::AssetIdType &asset_id,
228 : const std::string &amount);
229 :
230 : /**
231 : * Transfers asset from one account to another
232 : * @param src_account_id - source account id
233 : * @param dest_account_id - destination account id
234 : * @param asset_id - asset id
235 : * @param description - description message which user can set
236 : * @param amount - amount of asset to transfer
237 : * @return buidler with transfer asset command appended
238 : */
239 : ModelTransactionBuilder transferAsset(
240 : const interface::types::AccountIdType &src_account_id,
241 : const interface::types::AccountIdType &dest_account_id,
242 : const interface::types::AssetIdType &asset_id,
243 : const std::string &description,
244 : const std::string &amount);
245 :
246 : /**
247 : * Builds result with all appended fields
248 : * @return wrapper on unsigned transaction
249 : */
250 : proto::UnsignedWrapper<proto::Transaction> build();
251 :
252 : private:
253 : proto::TemplateTransactionBuilder<
254 : (1 << shared_model::proto::TemplateTransactionBuilder<>::total) - 1>
255 : builder_;
256 : };
257 : } // namespace bindings
258 : } // namespace shared_model
259 :
260 : #endif // IROHA_SHARED_MODEL_MODEL_TRANSACTION_BUILDER_HPP
|