Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Add feature for custom genesis block gen #1168

Merged
merged 2 commits into from
Apr 16, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions iroha-cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/

#include <gflags/gflags.h>
#include <rapidjson/istreamwrapper.h>
#include <rapidjson/rapidjson.h>
#include <boost/filesystem.hpp>
#include <fstream>
#include <iostream>
Expand Down Expand Up @@ -55,6 +57,9 @@ DEFINE_string(json_query, "", "Query in json format");
DEFINE_bool(genesis_block,
false,
"Generate genesis block for new Iroha network");
DEFINE_string(genesis_transaction,
"",
"File with transaction in json format for the genesis");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the genesis block

DEFINE_string(peers_address,
"",
"File with peers address for new Iroha network");
Expand All @@ -76,19 +81,36 @@ int main(int argc, char *argv[]) {
// Generate new genesis block now Iroha network
if (FLAGS_genesis_block) {
BlockGenerator generator;

if (FLAGS_peers_address.empty()) {
logger->error("--peers_address is empty");
return EXIT_FAILURE;
iroha::model::Transaction transaction;
if (FLAGS_genesis_transaction == "") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe empty()

if (FLAGS_peers_address.empty()) {
logger->error("--peers_address is empty");
return EXIT_FAILURE;
}
std::ifstream file(FLAGS_peers_address);
std::vector<std::string> peers_address;
std::copy(std::istream_iterator<std::string>(file),
std::istream_iterator<std::string>(),
std::back_inserter(peers_address));
// Generate genesis block
transaction = TransactionGenerator().generateGenesisTransaction(
0, std::move(peers_address));
} else {
rapidjson::Document doc;
std::ifstream file(FLAGS_genesis_transaction);
rapidjson::IStreamWrapper isw(file);
doc.ParseStream(isw);
auto some_tx = JsonTransactionFactory{}.deserialize(doc);
if (some_tx) {
transaction = *some_tx;
} else {
logger->error(
"Cannot deserialize genesis transaction (problem with file reading "
"or illformed json?)");
return EXIT_FAILURE;
}
}
std::ifstream file(FLAGS_peers_address);
std::vector<std::string> peers_address;
std::copy(std::istream_iterator<std::string>(file),
std::istream_iterator<std::string>(),
std::back_inserter(peers_address));
// Generate genesis block
auto transaction = TransactionGenerator().generateGenesisTransaction(
0, std::move(peers_address));

auto block = generator.generateGenesisBlock(0, {transaction});
// Convert to json
JsonBlockFactory json_factory;
Expand Down