Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
2 changes: 2 additions & 0 deletions src/app/configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ namespace lean::app {
if (vm.contains("help")) {
std::cout << "Lean-node version " << buildVersion() << '\n';
std::cout << cli_options_ << '\n';
std::println(std::cout, "other commands");
std::println(std::cout, " lean_node key generate-node-key");
return true;
}

Expand Down
22 changes: 22 additions & 0 deletions src/executable/cmd_key_generate_node_key.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <print>

#include <libp2p/crypto/random_generator/boost_generator.hpp>
#include <libp2p/crypto/secp256k1_provider/secp256k1_provider_impl.hpp>
#include <libp2p/peer/peer_id_from.hpp>

inline void cmdKeyGenerateNodeKey() {
libp2p::crypto::secp256k1::Secp256k1ProviderImpl secp256k1{
std::make_shared<libp2p::crypto::random::BoostRandomGenerator>()};
auto keypair = secp256k1.generate().value();
auto peer_id = libp2p::peerIdFromSecp256k1(keypair.public_key);
std::println("{}", fmt::format("{:0xx}", qtils::Hex{keypair.private_key}));
std::println("{}", peer_id.toBase58());
}
17 changes: 17 additions & 0 deletions src/executable/lean_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "app/application.hpp"
#include "app/configuration.hpp"
#include "app/configurator.hpp"
#include "executable/cmd_key_generate_node_key.hpp"
#include "injector/node_injector.hpp"
#include "loaders/loader.hpp"
#include "log/logger.hpp"
Expand Down Expand Up @@ -100,6 +101,12 @@ namespace {
int main(int argc, const char **argv, const char **env) {
soralog::util::setThreadName("lean-node");

auto getArg = [&](size_t i) {
return static_cast<int>(i) < argc
? std::make_optional(std::string_view{argv[i]})
: std::nullopt;
};

qtils::FinalAction flush_std_streams_at_exit([] {
std::cout.flush();
std::cerr.flush();
Expand All @@ -117,6 +124,16 @@ int main(int argc, const char **argv, const char **env) {
return EXIT_FAILURE;
}

if (getArg(1) == "key") {
if (getArg(2) == "generate-node-key") {
cmdKeyGenerateNodeKey();
return EXIT_SUCCESS;
}
std::println(std::cerr, "Expected one of following commands");
std::println(std::cerr, " lean_node key generate-node-key");
return EXIT_FAILURE;
}

auto app_configurator =
std::make_unique<lean::app::Configurator>(argc, argv, env);

Expand Down
2 changes: 1 addition & 1 deletion src/modules/production/production.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace lean::modules {
SL_INFO(logger_,
"New leaf {} appeared{}",
msg->header.index(),
msg->best ? "; it's the new the best leaf" : "");
msg->best ? "; it's the new best leaf" : "");
}

void ProductionModuleImpl::on_block_finalized(
Expand Down
Loading