Skip to content

Commit

Permalink
Base for genesis block
Browse files Browse the repository at this point in the history
  • Loading branch information
l4l committed Jul 25, 2017
1 parent b368c32 commit 7a7b4dc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
5 changes: 2 additions & 3 deletions iroha-cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
cmake_minimum_required(VERSION 3.0)
PROJECT(iroha C CXX)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

add_library(cli_client
client.cpp
)

target_link_libraries(cli_client
endpoint optional)
endpoint ametsuchi model)

add_executable(cli-main main.cpp validators.cpp)
target_link_libraries(cli-main gflags ed25519 cli_client)
44 changes: 38 additions & 6 deletions iroha-cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <fstream>
#include <iostream>

#include <ametsuchi/impl/storage_impl.hpp>
#include "client.hpp"
#include "validators.hpp"

Expand All @@ -29,9 +30,22 @@ DEFINE_string(name, "", "Name of the account");

DEFINE_bool(grpc, false, "Send sample transaction to IrohaNetwork");
DEFINE_string(address, "127.0.0.1", "Address of the Iroha node");
DEFINE_int32(port, 50051, "Port of iroha's Torii");

DEFINE_validator(port, &iroha_cli::validate_port);
// todo: host validator
DEFINE_int32(torii_port, 50051, "Port of iroha's Torii");
DEFINE_validator(torii_port, &iroha_cli::validate_port);

DEFINE_bool(new_ledger, false,
"Creates new database and genesis block for the ledger");
DEFINE_string(path, "/var/iroha/db/", "Path of the Ametsuchi");
// todo: path validator
DEFINE_string(redis, "127.0.0.1", "Redis address");
DEFINE_int32(redis_port, 6379, "Redis port");
DEFINE_validator(redis_port, &iroha_cli::validate_port);
DEFINE_string(pg_conn, "host=localhost",
"Postgres parameters,"
"check out http://tinyurl.com/ycspggge");
DEFINE_string(peers, "", "Public keys of iroha nodes separated by \";\"");
DEFINE_validator(peers, &iroha_cli::validate_peers);

void create_account(std::string name);

Expand All @@ -51,14 +65,32 @@ int main(int argc, char* argv[]) {
}

if (FLAGS_grpc) {
std::cout << "Send transaction to " << FLAGS_address << ":" << FLAGS_port
<< std::endl;
auto client = iroha_cli::CliClient(FLAGS_address, FLAGS_port);
std::cout << "Send transaction to " << FLAGS_address << ":"
<< FLAGS_torii_port << std::endl;
auto client = iroha_cli::CliClient(FLAGS_address, FLAGS_torii_port);
// ToDo more variables transaction
client.sendTx(iroha::model::Transaction{});
return 0;
}

if (FLAGS_new_ledger) {
auto storage = iroha::ametsuchi::StorageImpl::create(
FLAGS_path, FLAGS_redis, FLAGS_redis_port, FLAGS_pg_conn);
auto mut = storage->createMutableStorage();
// auto block;
// storage.apply(block, [](const auto& current_block, auto& executor,
// auto& query, auto& top_block) {
// for (const auto& tx : current_block.transactions) {
// for (const auto& command : tx.commands) {
// if (not command->execute(query, executor)) {
// return false;
// }
// }
// }
// return true;
// });
}

return 0;
}

Expand Down
17 changes: 16 additions & 1 deletion iroha-cli/validators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,30 @@
*/

#include <iostream>
#include <sstream>
#include "validators.hpp"

namespace iroha_cli {

bool validate_port(const char*, gflags::int32 port) {
if (port > 0 && port < 32768) return 1;
// fixme port max num macro
if (port > 0 && port < 65535) return 1;

std::cout<<"Port can be only in range (0, 32768)";
return 0;
}

bool validate_peers(const char*, const std::string& s) {
std::stringstream ss(s);
std::string tmp;
while (std::getline(ss, tmp, ';')){
// fixme macro
if (tmp.size() != 32) {
printf("\"%s\" doesn't look like pubkey (size != 32)", tmp.c_str());
return 0;
}
}
return 1;
}

} // namespace iroha_cli
1 change: 1 addition & 0 deletions iroha-cli/validators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
namespace iroha_cli {

bool validate_port(const char*, gflags::int32);
bool validate_peers(const char*, const std::string&);

} // namespace iroha_cli

0 comments on commit 7a7b4dc

Please sign in to comment.