6 #ifndef IROHA_PROTO_TRANSACTION_BUILDER_TEMPLATE_HPP 7 #define IROHA_PROTO_TRANSACTION_BUILDER_TEMPLATE_HPP 11 #include <boost/range/algorithm/for_each.hpp> 13 #include "commands.pb.h" 14 #include "primitive.pb.h" 15 #include "transaction.pb.h" 22 #include "module/irohad/common/validators_config.hpp" 37 typename BT = UnsignedWrapper<Transaction>>
40 template <
int,
typename,
typename>
55 using ProtoCommand = iroha::protocol::Command;
60 : transaction_(o.transaction_),
61 stateless_validator_(o.stateless_validator_) {}
69 template <
int Fields,
typename Transformation>
70 auto transform(Transformation t)
const {
82 template <
typename Transformation>
83 auto addCommand(Transformation t)
const {
85 t(copy.transaction_.mutable_payload()
86 ->mutable_reduced_payload()
92 : stateless_validator_(validator) {}
99 SV(
iroha::test::kTestsValidatorsConfig)) {}
103 return transform<CreatorAccountId>([&](
auto &tx) {
105 ->mutable_reduced_payload()
106 ->set_creator_account_id(account_id);
111 std::vector<interface::types::HashType> hashes)
const {
112 return transform<0>([&](
auto &tx) {
113 tx.mutable_payload()->mutable_batch()->set_type(
117 for (
const auto &
hash : hashes) {
118 tx.mutable_payload()->mutable_batch()->add_reduced_hashes(
125 return transform<CreatedTime>([&](
auto &tx) {
126 tx.mutable_payload()->mutable_reduced_payload()->set_created_time(
132 return transform<Quorum>([&](
auto &tx) {
133 tx.mutable_payload()->mutable_reduced_payload()->set_quorum(quorum);
138 const std::string &amount)
const {
139 return addCommand([&](
auto proto_command) {
140 auto command = proto_command->mutable_add_asset_quantity();
141 command->set_asset_id(asset_id);
142 command->set_amount(amount);
147 interface::types::PublicKeyHexStringView peer_key,
148 const std::optional<interface::types::TLSCertificateType>
149 &tls_certificate = std::nullopt)
const {
150 return addCommand([&](
auto proto_command) {
151 auto command = proto_command->mutable_add_peer();
152 auto peer = command->mutable_peer();
153 peer->set_address(address);
154 const std::string_view peer_key_sv{peer_key};
155 peer->set_peer_key(peer_key_sv.data(), peer_key_sv.size());
156 if (tls_certificate) {
157 peer->set_tls_certificate(*tls_certificate);
162 auto removePeer(interface::types::PublicKeyHexStringView public_key)
164 return addCommand([&](
auto proto_command) {
165 auto command = proto_command->mutable_remove_peer();
166 std::string_view
const &public_key_string{public_key};
167 command->set_public_key(public_key_string.data(),
168 public_key_string.size());
173 interface::types::PublicKeyHexStringView public_key)
175 return addCommand([&](
auto proto_command) {
176 auto command = proto_command->mutable_add_signatory();
177 command->set_account_id(account_id);
178 const std::string_view &public_key_sv = public_key;
179 command->set_public_key(public_key_sv.data(), public_key_sv.size());
184 interface::types::PublicKeyHexStringView public_key)
186 return addCommand([&](
auto proto_command) {
187 auto command = proto_command->mutable_remove_signatory();
188 command->set_account_id(account_id);
189 const std::string_view public_key_sv = public_key;
190 command->set_public_key(public_key_sv.data(), public_key_sv.size());
196 std::optional<interface::types::EvmCalleeHexStringView> callee,
197 interface::types::EvmCodeHexStringView input)
const {
198 return addCommand([&](
auto proto_command) {
199 auto command = proto_command->mutable_call_engine();
201 CallEngine_EngineType_kSolidity);
202 command->set_caller(caller);
204 const auto callee_sv =
205 static_cast<std::string_view
const &
>(callee.value());
206 command->set_callee(callee_sv.data(), callee_sv.size());
208 const auto input_sv =
static_cast<std::string_view
const &
>(input);
209 command->set_input(input_sv.data(), input_sv.size());
215 return addCommand([&](
auto proto_command) {
216 auto command = proto_command->mutable_append_role();
217 command->set_account_id(account_id);
218 command->set_role_name(role_name);
225 return addCommand([&](
auto proto_command) {
226 auto command = proto_command->mutable_create_asset();
227 command->set_asset_name(asset_name);
228 command->set_domain_id(domain_id);
229 command->set_precision(precision);
235 interface::types::PublicKeyHexStringView main_pubkey)
237 return addCommand([&](
auto proto_command) {
238 auto command = proto_command->mutable_create_account();
239 command->set_account_name(account_name);
240 command->set_domain_id(domain_id);
241 std::string_view main_pubkey_sv{main_pubkey};
242 command->set_public_key(main_pubkey_sv.data(), main_pubkey_sv.size());
249 return addCommand([&](
auto proto_command) {
250 auto command = proto_command->mutable_create_domain();
251 command->set_domain_id(domain_id);
252 command->set_default_role(default_role);
258 return addCommand([&](
auto proto_command) {
259 auto command = proto_command->mutable_create_role();
260 command->set_role_name(role_name);
261 for (
size_t i = 0; i < permissions.
size(); ++i) {
263 if (permissions.
isSet(perm)) {
272 return addCommand([&](
auto proto_command) {
273 auto command = proto_command->mutable_detach_role();
274 command->set_account_id(account_id);
275 command->set_role_name(role_name);
281 return addCommand([&](
auto proto_command) {
282 auto command = proto_command->mutable_grant_permission();
283 command->set_account_id(account_id);
291 return addCommand([&](
auto proto_command) {
292 auto command = proto_command->mutable_revoke_permission();
293 command->set_account_id(account_id);
302 return addCommand([&](
auto proto_command) {
303 auto command = proto_command->mutable_set_account_detail();
304 command->set_account_id(account_id);
305 command->set_key(key);
306 command->set_value(value);
312 return addCommand([&](
auto proto_command) {
313 auto command = proto_command->mutable_set_account_quorum();
314 command->set_account_id(account_id);
315 command->set_quorum(quorum);
320 const std::string &amount)
const {
321 return addCommand([&](
auto proto_command) {
322 auto command = proto_command->mutable_subtract_asset_quantity();
323 command->set_asset_id(asset_id);
324 command->set_amount(amount);
332 const std::string &amount)
const {
333 return addCommand([&](
auto proto_command) {
334 auto command = proto_command->mutable_transfer_asset();
335 command->set_src_account_id(src_account_id);
336 command->set_dest_account_id(dest_account_id);
337 command->set_asset_id(asset_id);
338 command->set_description(description);
339 command->set_amount(amount);
346 return addCommand([&](
auto proto_command) {
347 auto command = proto_command->mutable_set_setting_value();
348 command->set_key(key);
349 command->set_value(value);
354 static_assert(S == (1 << TOTAL) - 1,
"Required fields are not set");
356 if (
auto error = stateless_validator_.validate(result)) {
357 throw std::invalid_argument(error->toString());
359 return BT(std::move(result));
362 static const int total = RequiredFields::TOTAL;
365 ProtoTx transaction_;
366 SV stateless_validator_;
372 #endif // IROHA_PROTO_TRANSACTION_BUILDER_TEMPLATE_HPP auto detachRole(const interface::types::AccountIdType &account_id, const interface::types::RoleIdType &role_name) const
Definition: transaction_template.hpp:270
auto createRole(const interface::types::RoleIdType &role_name, const interface::RolePermissionSet &permissions) const
Definition: transaction_template.hpp:256
std::string AddressType
Type of peer address.
Definition: types.hpp:50
Definition: proto_command.hpp:16
iroha::protocol::RolePermission toTransport(interface::permissions::Role r)
Definition: permissions.cpp:19
Definition: transaction.hpp:14
auto setAccountQuorum(const interface::types::AddressType &account_id, interface::types::QuorumType quorum) const
Definition: transaction_template.hpp:310
Grantable
Definition: permissions.hpp:75
std::string SettingKeyType
Type of setting key.
Definition: types.hpp:88
std::string DomainIdType
Iroha domain id type.
Definition: types.hpp:56
auto creatorAccountId(const interface::types::AccountIdType &account_id) const
Definition: transaction_template.hpp:101
Definition: permissions.hpp:102
auto appendRole(const interface::types::AccountIdType &account_id, const interface::types::RoleIdType &role_name) const
Definition: transaction_template.hpp:213
auto addSignatory(const interface::types::AccountIdType &account_id, interface::types::PublicKeyHexStringView public_key) const
Definition: transaction_template.hpp:172
static constexpr size_t size()
Definition: permissions.hpp:111
TransactionValidator< FieldValidator, CommandValidatorVisitor< FieldValidator > > DefaultUnsignedTransactionValidator
Definition: default_validator.hpp:30
auto callEngine(const interface::types::AccountIdType &caller, std::optional< interface::types::EvmCalleeHexStringView > callee, interface::types::EvmCodeHexStringView input) const
Definition: transaction_template.hpp:194
std::string DescriptionType
Type of the transfer message.
Definition: types.hpp:86
std::string AccountDetailKeyType
Type of account detail key.
Definition: types.hpp:79
Role
Definition: permissions.hpp:17
auto createdTime(interface::types::TimestampType created_time) const
Definition: transaction_template.hpp:124
auto grantPermission(const interface::types::AccountIdType &account_id, interface::permissions::Grantable permission) const
Definition: transaction_template.hpp:279
auto transferAsset(const interface::types::AccountIdType &src_account_id, const interface::types::AccountIdType &dest_account_id, const interface::types::AssetIdType &asset_id, const interface::types::DescriptionType &description, const std::string &amount) const
Definition: transaction_template.hpp:328
Definition: block_query.hpp:15
auto createDomain(const interface::types::DomainIdType &domain_id, const interface::types::RoleIdType &default_role) const
Definition: transaction_template.hpp:246
std::string AccountIdType
Type of account id.
Definition: types.hpp:38
hash256_t hash(const T &pb)
Definition: pb_common.hpp:43
auto setAccountDetail(const interface::types::AccountIdType &account_id, const interface::types::AccountDetailKeyType &key, const interface::types::AccountDetailValueType &value) const
Definition: transaction_template.hpp:298
auto setSettingValue(const interface::types::SettingKeyType &key, const interface::types::SettingValueType &value) const
Definition: transaction_template.hpp:343
auto createAsset(const interface::types::AssetNameType &asset_name, const interface::types::DomainIdType &domain_id, interface::types::PrecisionType precision) const
Definition: transaction_template.hpp:222
auto batchMeta(interface::types::BatchType type, std::vector< interface::types::HashType > hashes) const
Definition: transaction_template.hpp:110
Definition: transaction_template.hpp:38
EngineType
Type of smart contract engine.
Definition: engine_type.hpp:12
auto subtractAssetQuantity(const interface::types::AssetIdType &asset_id, const std::string &amount) const
Definition: transaction_template.hpp:319
auto build() const
Definition: transaction_template.hpp:353
auto addAssetQuantity(const interface::types::AssetIdType &asset_id, const std::string &amount) const
Definition: transaction_template.hpp:137
auto quorum(interface::types::QuorumType quorum) const
Definition: transaction_template.hpp:131
uint8_t PrecisionType
Type of precision.
Definition: types.hpp:46
std::string SettingValueType
Type of setting value.
Definition: types.hpp:90
std::string AccountNameType
Type of account name.
Definition: types.hpp:71
auto revokePermission(const interface::types::AccountIdType &account_id, interface::permissions::Grantable permission) const
Definition: transaction_template.hpp:288
auto removeSignatory(const interface::types::AccountIdType &account_id, interface::types::PublicKeyHexStringView public_key) const
Definition: transaction_template.hpp:183
auto addPeer(const interface::types::AddressType &address, interface::types::PublicKeyHexStringView peer_key, const std::optional< interface::types::TLSCertificateType > &tls_certificate=std::nullopt) const
Definition: transaction_template.hpp:146
BatchType
Definition: types.hpp:101
auto createAccount(const interface::types::AccountNameType &account_name, const interface::types::DomainIdType &domain_id, interface::types::PublicKeyHexStringView main_pubkey) const
Definition: transaction_template.hpp:233
std::string AccountDetailValueType
Type of account detail value.
Definition: types.hpp:81
Definition: command_executor.hpp:12
bool isSet(Perm p) const
Definition: permissions.cpp:94
uint16_t QuorumType
Type of Quorum used in transaction and set quorum.
Definition: types.hpp:65
std::string AssetNameType
Type of asset name.
Definition: types.hpp:73
std::string RoleIdType
Type of role (i.e admin, user)
Definition: types.hpp:54
auto removePeer(interface::types::PublicKeyHexStringView public_key) const
Definition: transaction_template.hpp:162
TemplateTransactionBuilder()
Definition: transaction_template.hpp:97
uint64_t TimestampType
Type of timestamp.
Definition: types.hpp:67
std::string AssetIdType
Type of asset id.
Definition: types.hpp:58