29 #include <boost/algorithm/string.hpp> 40 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY 41 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "bcutil" 43 namespace po = boost::program_options;
47 static bool stop_requested =
false;
49 int main(
int argc,
char* argv[])
58 available_dbs =
"available: " + available_dbs;
66 boost::filesystem::path output_file_path;
68 po::options_description desc_cmd_only(
"Command line options");
69 po::options_description desc_cmd_sett(
"Command line options and settings options");
72 "database", available_dbs.c_str(), default_db_type
94 po::options_description desc_options(
"Allowed options");
95 desc_options.add(desc_cmd_only).add(desc_cmd_sett);
100 auto parser = po::command_line_parser(argc, argv).options(desc_options);
101 po::store(parser.run(), vm);
111 std::cout << desc_options << std::endl;
137 std::cerr <<
"Invalid database type: " << db_type << std::endl;
141 LOG_PRINT_L0(
"Initializing source blockchain (BlockchainDB)");
142 std::unique_ptr<Blockchain> core_storage;
144 core_storage.reset(
new Blockchain(m_mempool));
148 LOG_ERROR(
"Attempted to use non-existent database type: " << db_type);
149 throw std::runtime_error(
"Attempting to use non-existent database type");
154 LOG_PRINT_L0(
"Loading blockchain from folder " << filename <<
" ...");
160 catch (
const std::exception& e)
165 r = core_storage->
init(db, net_type);
168 LOG_PRINT_L0(
"Source blockchain storage initialized OK");
171 stop_requested =
true;
176 block_stop = db_height;
177 MINFO(
"Starting from height " << block_start <<
", stopping at height " << block_stop);
196 std::cout <<
ENDL <<
"# DATA" <<
ENDL;
197 std::cout <<
"Date\tBlocks/day\tBlocks\tTxs/Day\tTxs\tBytes/Day\tBytes";
199 std::cout <<
"\tInMin\tInMax\tInAvg";
201 std::cout <<
"\tOutMin\tOutMax\tOutAvg";
203 std::cout <<
"\tRingMin\tRingMax\tRingAvg";
207 for (i=0; i<24; i++) {
208 sprintf(
buf,
"\t%02u:00", i);
214 struct tm prevtm = {0}, currtm;
218 uint64_t totins = 0, totouts = 0, totrings = 0;
221 uint32_t minrings = 50, maxrings = 0;
226 for (
uint64_t h = block_start; h < block_stop; ++h)
241 if (currtm.tm_mday > prevtm.tm_mday || (currtm.tm_mday == 1 && prevtm.tm_mday > 27))
244 if (prevtm.tm_mday == 1 && currtm.tm_mday > 27)
246 strftime(timebuf,
sizeof(timebuf),
"%Y-%m-%d", &prevtm);
248 std::cout << timebuf <<
"\t" << currblks <<
"\t" << h <<
"\t" << currtxs <<
"\t" << prevtxs + currtxs <<
"\t" << currsz <<
"\t" << prevsz + currsz;
257 std::cout <<
"\t" << (maxins ? minins : 0) <<
"\t" << maxins <<
"\t" << totins / tottxs;
258 minins = 10; maxins = 0; totins = 0;
261 std::cout <<
"\t" << (maxouts ? minouts : 0) <<
"\t" << maxouts <<
"\t" << totouts / tottxs;
262 minouts = 10; maxouts = 0; totouts = 0;
265 std::cout <<
"\t" << (maxrings ? minrings : 0) <<
"\t" << maxrings <<
"\t" << totrings / tottxs;
266 minrings = 50; maxrings = 0; totrings = 0;
270 for (i=0; i<24; i++) {
271 std::cout <<
"\t" << txhr[i];
281 if (tx_id == crypto::null_hash)
283 throw std::runtime_error(
"Aborting: tx == null_hash");
287 throw std::runtime_error(
"Aborting: tx not found");
298 txhr[currtm.tm_hour]++;
303 else if (io > maxins)
309 = boost::get<cryptonote::txin_to_key>(tx.
vin[0]);
313 else if (io > maxrings)
321 else if (io > maxouts)
const char *const ELECTRONEUM_RELEASE_NAME
virtual bool get_tx_blob(const crypto::hash &h, cryptonote::blobdata &tx) const =0
fetches the transaction blob with the given hash
std::vector< crypto::hash > tx_hashes
virtual std::string get_db_name() const =0
gets the name of the folder the BlockchainDB's file(s) should be in
virtual cryptonote::blobdata get_block_blob_from_height(const uint64_t &height) const =0
fetch a block blob by height
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
void mlog_set_log(const char *log)
#define CATCH_ENTRY(location, return_val)
std::string mlog_get_default_log_path(const char *default_filename)
void mlog_configure(const std::string &filename_base, bool console, const std::size_t max_log_file_size=MAX_LOG_FILE_SIZE, const std::size_t max_log_files=MAX_LOG_FILES)
provides the implementation of varint's
const command_line::arg_descriptor< bool, false > arg_stagenet_on
const arg_descriptor< bool > arg_help
std::vector< uint64_t > key_offsets
std::string blockchain_db_types(const std::string &sep)
virtual void open(const std::string &filename, const int db_flags=0)=0
open a db, or create it if necessary.
std::vector< tx_out > vout
Holds cryptonote related classes and helpers.
const char *const ELECTRONEUM_VERSION_FULL
bool blockchain_valid_db_type(const std::string &db_type)
std::vector< txin_v > vin
const command_line::arg_descriptor< bool, false > arg_testnet_on
BlockchainDB * new_db(const std::string &db_type)
bool handle_error_helper(const boost::program_options::options_description &desc, F parser)
const command_line::arg_descriptor< std::string > arg_log_level
bool get_gmt_time(time_t t, struct tm &tm)
unsigned __int64 uint64_t
const command_line::arg_descriptor< std::string, false, true, 2 > arg_data_dir
virtual uint64_t height() const =0
fetch the current blockchain height
bool parse_and_validate_tx_from_blob(const blobdata &tx_blob, transaction &tx)
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
int main(int argc, char *argv[])
Transaction pool, handles transactions which are not part of a block.
The BlockchainDB backing store interface declaration/contract.
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
bool init(BlockchainDB *db, const network_type nettype=MAINNET, bool offline=false, const cryptonote::test_options *test_options=NULL, difficulty_type fixed_difficulty=0, const GetCheckpointsCallback &get_checkpoints=nullptr, bool ignore_bsig=false, bool fallback_to_pow=false)
Initialize the Blockchain state.
std::string to_string(t_connection_type type)
bool is_arg_defaulted(const boost::program_options::variables_map &vm, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg)
bool deinit()
Uninitializes the blockchain state.
bool parse_and_validate_block_from_blob(const blobdata &b_blob, block &b, crypto::hash *block_hash)