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/transaction_generator.hpp"
7 : #include "crypto/keys_manager_impl.hpp"
8 : #include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp"
9 : #include "datetime/time.hpp"
10 : #include "model/commands/append_role.hpp"
11 : #include "model/peer.hpp"
12 :
13 : namespace iroha {
14 : namespace model {
15 : namespace generators {
16 :
17 : iroha::keypair_t *makeOldModel(
18 : const shared_model::crypto::Keypair &keypair) {
19 0 : return new iroha::keypair_t{
20 0 : iroha::pubkey_t::from_string(toBinaryString(keypair.publicKey())),
21 0 : iroha::privkey_t::from_string(
22 0 : toBinaryString(keypair.privateKey()))};
23 0 : }
24 :
25 : Transaction TransactionGenerator::generateGenesisTransaction(
26 : ts64_t timestamp,
27 : std::vector<std::string> peers_address,
28 : logger::LoggerPtr keys_manager_logger) {
29 0 : Transaction tx;
30 0 : tx.created_ts = timestamp;
31 0 : tx.creator_account_id = "";
32 : CommandGenerator command_generator;
33 : // Add peers
34 0 : for (size_t i = 0; i < peers_address.size(); ++i) {
35 0 : KeysManagerImpl manager("node" + std::to_string(i),
36 0 : keys_manager_logger);
37 0 : manager.createKeys();
38 0 : auto keypair = *std::unique_ptr<iroha::keypair_t>(
39 0 : makeOldModel(*manager.loadKeys()));
40 0 : tx.commands.push_back(command_generator.generateAddPeer(
41 0 : Peer(peers_address[i], keypair.pubkey)));
42 0 : }
43 : // Create admin role
44 0 : tx.commands.push_back(
45 0 : command_generator.generateCreateAdminRole("admin"));
46 : // Create user role
47 0 : tx.commands.push_back(command_generator.generateCreateUserRole("user"));
48 0 : tx.commands.push_back(
49 0 : command_generator.generateCreateAssetCreatorRole("money_creator"));
50 : // Add domain
51 0 : tx.commands.push_back(
52 0 : command_generator.generateCreateDomain("test", "user"));
53 : // Create asset
54 0 : auto precision = 2;
55 0 : tx.commands.push_back(
56 0 : command_generator.generateCreateAsset("coin", "test", precision));
57 : // Create accounts
58 0 : KeysManagerImpl manager("admin@test", keys_manager_logger);
59 0 : manager.createKeys();
60 0 : auto keypair = *std::unique_ptr<iroha::keypair_t>(
61 0 : makeOldModel(*manager.loadKeys()));
62 0 : tx.commands.push_back(command_generator.generateCreateAccount(
63 0 : "admin", "test", keypair.pubkey));
64 0 : manager = KeysManagerImpl("test@test", std::move(keys_manager_logger));
65 0 : manager.createKeys();
66 0 : keypair = *std::unique_ptr<iroha::keypair_t>(
67 0 : makeOldModel(*manager.loadKeys()));
68 0 : tx.commands.push_back(command_generator.generateCreateAccount(
69 0 : "test", "test", keypair.pubkey));
70 :
71 0 : tx.commands.push_back(
72 0 : std::make_shared<AppendRole>("admin@test", "admin"));
73 0 : tx.commands.push_back(
74 0 : std::make_shared<AppendRole>("admin@test", "money_creator"));
75 0 : return tx;
76 0 : }
77 :
78 : Transaction TransactionGenerator::generateTransaction(
79 : ts64_t timestamp,
80 : std::string creator_account_id,
81 : std::vector<std::shared_ptr<Command>> commands) {
82 1 : Transaction tx;
83 1 : tx.created_ts = timestamp;
84 1 : tx.creator_account_id = creator_account_id;
85 1 : tx.commands = commands;
86 1 : return tx;
87 1 : }
88 :
89 : Transaction TransactionGenerator::generateTransaction(
90 : std::string creator_account_id,
91 : std::vector<std::shared_ptr<Command>> commands) {
92 1 : return generateTransaction(
93 1 : iroha::time::now(), creator_account_id, commands);
94 0 : }
95 :
96 : } // namespace generators
97 : } // namespace model
98 : } // namespace iroha
|