29 #include <boost/range/adaptor/transformed.hpp> 30 #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 int main(
int argc,
char* argv[])
56 available_dbs =
"available: " + available_dbs;
62 boost::filesystem::path output_file_path;
64 po::options_description desc_cmd_only(
"Command line options");
65 po::options_description desc_cmd_sett(
"Command line options and settings options");
68 "database", available_dbs.c_str(), default_db_type
84 po::options_description desc_options(
"Allowed options");
85 desc_options.add(desc_cmd_only).add(desc_cmd_sett);
90 auto parser = po::command_line_parser(argc, argv).options(desc_options);
91 po::store(parser.run(), vm);
101 std::cout << desc_options << std::endl;
121 if (!opt_txid_string.empty() && opt_height)
123 std::cerr <<
"txid and height cannot be given at the same time" << std::endl;
127 if (!opt_txid_string.empty())
131 std::cerr <<
"Invalid txid" << std::endl;
139 std::cerr <<
"Invalid database type: " << db_type << std::endl;
154 LOG_PRINT_L0(
"Initializing source blockchain (BlockchainDB)");
155 std::unique_ptr<Blockchain> core_storage;
157 core_storage.reset(
new Blockchain(m_mempool));
161 LOG_ERROR(
"Attempted to use non-existent database type: " << db_type);
162 throw std::runtime_error(
"Attempting to use non-existent database type");
167 LOG_PRINT_L0(
"Loading blockchain from folder " << filename <<
" ...");
173 catch (
const std::exception& e)
178 r = core_storage->
init(db, net_type);
181 LOG_PRINT_L0(
"Source blockchain storage initialized OK");
183 std::vector<crypto::hash> start_txids;
184 if (!opt_txid_string.empty())
186 start_txids.push_back(opt_txid);
198 start_txids.push_back(txid);
199 if (opt_include_coinbase)
203 if (start_txids.empty())
209 std::vector<uint64_t> depths;
213 bool coinbase =
false;
216 std::vector<crypto::hash> txids(1, start_txid);
219 LOG_PRINT_L0(
"Considering "<< txids.size() <<
" transaction(s) at depth " << depth);
220 std::vector<crypto::hash> new_txids;
226 LOG_PRINT_L0(
"Failed to get txid " << txid <<
" from db");
235 for (
size_t ring = 0; ring < tx.
vin.size(); ++ring)
239 MDEBUG(txid <<
" is a coinbase transaction");
248 for (
uint64_t offset: absolute_offsets)
261 for (
size_t out = 0; out < b.
miner_tx.
vout.size(); ++out)
265 const auto &txout = boost::get<cryptonote::txout_to_key>(b.
miner_tx.
vout[out].target);
266 if (txout.key == od.
pubkey)
286 LOG_PRINT_L0(
"Failed to get txid " << block_txid <<
" from db");
295 for (
size_t out = 0; out < tx2.
vout.size(); ++out)
299 const auto &txout = boost::get<cryptonote::txout_to_key>(tx2.
vout[out].target);
300 if (txout.key == od.
pubkey)
303 new_txids.push_back(block_txid);
304 MDEBUG(
"adding txid: " << block_txid);
317 LOG_PRINT_L0(
"Output originating transaction not found");
331 std::swap(txids, new_txids);
336 LOG_PRINT_L0(
"Min depth for txid " << start_txid <<
": " << depth);
337 depths.push_back(depth);
342 cumulative_depth += depth;
343 LOG_PRINT_L0(
"Average min depth for " << start_txids.size() <<
" transaction(s): " << cumulative_depth/(float)depths.size());
const char *const ELECTRONEUM_RELEASE_NAME
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
int main(int argc, char *argv[])
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)
virtual crypto::hash get_block_hash_from_height(const uint64_t &height) const =0
fetch a block's hash
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)
std::vector< uint64_t > relative_output_offsets_to_absolute(const std::vector< uint64_t > &off)
virtual void open(const std::string &filename, const int db_flags=0)=0
open a db, or create it if necessary.
virtual bool get_pruned_tx_blob(const crypto::hash &h, cryptonote::blobdata &tx) const =0
fetches the pruned transaction blob with the given hash
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
virtual output_data_t get_output_key(const uint64_t &amount, const uint64_t &index, bool include_commitmemt=true) const =0
get some of an output's data
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
crypto::public_key pubkey
the output's public key (for spend verification)
unsigned __int64 uint64_t
const command_line::arg_descriptor< std::string, false, true, 2 > arg_data_dir
uint64_t height
the height of the block which created the output
bool parse_and_validate_tx_base_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)
Transaction pool, handles transactions which are not part of a block.
type_vec_type median(std::vector< type_vec_type > &v)
The BlockchainDB backing store interface declaration/contract.
crypto::hash get_transaction_hash(const transaction &t)
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)
a struct containing output metadata
virtual cryptonote::blobdata get_block_blob(const crypto::hash &h) const =0
fetches the block with the given hash
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)