mirror of
https://github.com/wownero/lwsf-wow.git
synced 2026-10-17 07:21:28 +02:00
Update ledger-main to support monerod backend, and sort txes
This commit is contained in:
+37
-6
@@ -33,6 +33,7 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <map>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -46,17 +47,20 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
enum class backend_type : unsigned char { lws = 0, monerod };
|
||||||
struct options
|
struct options
|
||||||
{
|
{
|
||||||
const command_line::arg_descriptor<std::string> wallet_file;
|
const command_line::arg_descriptor<std::string> wallet_file;
|
||||||
const command_line::arg_descriptor<std::string> lws_url;
|
const command_line::arg_descriptor<std::string> lws_url;
|
||||||
const command_line::arg_descriptor<std::string> network;
|
const command_line::arg_descriptor<std::string> network;
|
||||||
|
const command_line::arg_descriptor<std::string> backend;
|
||||||
const command_line::arg_descriptor<std::string> config_file;
|
const command_line::arg_descriptor<std::string> config_file;
|
||||||
|
|
||||||
options()
|
options()
|
||||||
: wallet_file{"wallet-file", "Path to read-and-store wallet. Omit to skip wallet cache storage."}
|
: wallet_file{"wallet-file", "Path to read-and-store wallet. Omit to skip wallet cache storage."}
|
||||||
, lws_url{"lws-url", "<protocol>://address:port of LWS server REST API. Omit to read cached data."}
|
, lws_url{"lws-url", "<protocol>://address:port of LWS server REST API (or monerod if using that backend). Omit to read cached data."}
|
||||||
, network{"network", "<\"main\"|\"stage\"|\"test\"> - Blockchain net type", "main"}
|
, network{"network", "<\"main\"|\"stage\"|\"test\"> - Blockchain net type", "main"}
|
||||||
|
, backend{"backend", "<\"lws\"|\"monerod\"> - Backend used for file cache and probing", "lws"}
|
||||||
, config_file{"config-file", "Specify any option in a config file; <name>=<value> on separate lines"}
|
, config_file{"config-file", "Specify any option in a config file; <name>=<value> on separate lines"}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -66,6 +70,7 @@ namespace
|
|||||||
command_line::add_arg(description, lws_url);
|
command_line::add_arg(description, lws_url);
|
||||||
command_line::add_arg(description, config_file);
|
command_line::add_arg(description, config_file);
|
||||||
command_line::add_arg(description, network);
|
command_line::add_arg(description, network);
|
||||||
|
command_line::add_arg(description, backend);
|
||||||
command_line::add_arg(description, command_line::arg_help);
|
command_line::add_arg(description, command_line::arg_help);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +86,17 @@ namespace
|
|||||||
else
|
else
|
||||||
throw std::runtime_error{"Bad --network value"};
|
throw std::runtime_error{"Bad --network value"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
backend_type get_backend(boost::program_options::variables_map const& args) const
|
||||||
|
{
|
||||||
|
const std::string type = command_line::get_arg(args, backend);
|
||||||
|
if (type == "lws")
|
||||||
|
return backend_type::lws;
|
||||||
|
else if (type == "monerod")
|
||||||
|
return backend_type::monerod;
|
||||||
|
else
|
||||||
|
throw std::runtime_error{"Bad --backend value"};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct program
|
struct program
|
||||||
@@ -88,6 +104,7 @@ namespace
|
|||||||
std::string wallet_file;
|
std::string wallet_file;
|
||||||
std::string lws_url;
|
std::string lws_url;
|
||||||
Monero::NetworkType network;
|
Monero::NetworkType network;
|
||||||
|
backend_type backend;
|
||||||
};
|
};
|
||||||
|
|
||||||
void print_help(std::ostream& out)
|
void print_help(std::ostream& out)
|
||||||
@@ -136,7 +153,8 @@ namespace
|
|||||||
program prog{
|
program prog{
|
||||||
command_line::get_arg(args, opts.wallet_file),
|
command_line::get_arg(args, opts.wallet_file),
|
||||||
command_line::get_arg(args, opts.lws_url),
|
command_line::get_arg(args, opts.lws_url),
|
||||||
opts.get_network(args)
|
opts.get_network(args),
|
||||||
|
opts.get_backend(args)
|
||||||
};
|
};
|
||||||
|
|
||||||
return prog;
|
return prog;
|
||||||
@@ -144,8 +162,16 @@ namespace
|
|||||||
|
|
||||||
void run(program prog)
|
void run(program prog)
|
||||||
{
|
{
|
||||||
const std::unique_ptr<Monero::WalletManager> wm{
|
std::unique_ptr<Monero::WalletManager> wm;
|
||||||
lwsf::WalletManagerFactory::getWalletManager()
|
switch (prog.backend)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case backend_type::lws:
|
||||||
|
wm.reset(lwsf::WalletManagerFactory::getWalletManager());
|
||||||
|
break;
|
||||||
|
case backend_type::monerod:
|
||||||
|
wm.reset(Monero::WalletManagerFactory::getWalletManager());
|
||||||
|
break;
|
||||||
};
|
};
|
||||||
if (!wm)
|
if (!wm)
|
||||||
throw std::runtime_error{"Unexpected WalletManager nullptr"};
|
throw std::runtime_error{"Unexpected WalletManager nullptr"};
|
||||||
@@ -217,11 +243,16 @@ namespace
|
|||||||
|
|
||||||
std::cout << "; Transactions: " << info_list.size() << std::endl << std::endl;
|
std::cout << "; Transactions: " << info_list.size() << std::endl << std::endl;
|
||||||
|
|
||||||
|
std::multimap<std::uint64_t, const Monero::TransactionInfo*> ordered;
|
||||||
for (const Monero::TransactionInfo* info : info_list)
|
for (const Monero::TransactionInfo* info : info_list)
|
||||||
{
|
{
|
||||||
if (!info)
|
if (info)
|
||||||
throw std::runtime_error{"Unexpected info nullptr"};
|
ordered.emplace(info->blockHeight(), info);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto elem : ordered)
|
||||||
|
{
|
||||||
|
auto info = elem.second;
|
||||||
std::tm expanded{};
|
std::tm expanded{};
|
||||||
const std::time_t timestamp = info->timestamp();
|
const std::time_t timestamp = info->timestamp();
|
||||||
if (!gmtime_r(std::addressof(timestamp), std::addressof(expanded)))
|
if (!gmtime_r(std::addressof(timestamp), std::addressof(expanded)))
|
||||||
|
|||||||
Reference in New Issue
Block a user