32 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY 33 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "bcutil" 35 namespace po = boost::program_options;
49 const boost::filesystem::path dir_path = file_path.parent_path();
50 if (!dir_path.empty())
52 if (boost::filesystem::exists(dir_path))
54 if (!boost::filesystem::is_directory(dir_path))
56 MFATAL(
"export directory path is a file: " << dir_path);
62 if (!boost::filesystem::create_directory(dir_path))
64 MFATAL(
"Failed to create directory " << dir_path);
70 m_raw_data_file =
new std::ofstream();
72 MINFO(
"creating file");
74 m_raw_data_file->open(file_path.string(), std::ios_base::binary | std::ios_base::out | std::ios::trunc);
75 if (m_raw_data_file->fail())
78 initialize_file(block_stop);
86 const uint32_t nblocks = block_stop + 1;
87 unsigned char nblocksc[4];
89 nblocksc[0] = nblocks & 0xff;
90 nblocksc[1] = (nblocks >> 8) & 0xff;
91 nblocksc[2] = (nblocks >> 16) & 0xff;
92 nblocksc[3] = (nblocks >> 24) & 0xff;
95 *m_raw_data_file << nblocksc[0];
96 *m_raw_data_file << nblocksc[1];
97 *m_raw_data_file << nblocksc[2];
98 *m_raw_data_file << nblocksc[3];
105 const std::string data(block_hash.data,
sizeof(block_hash));
106 *m_raw_data_file << data;
111 if (m_raw_data_file->fail())
114 m_raw_data_file->flush();
115 delete m_raw_data_file;
123 m_blockchain_storage = _blockchain_storage;
129 MINFO(
"source blockchain height: " << m_blockchain_storage->get_current_blockchain_height()-1);
130 if ((requested_block_stop > 0) && (requested_block_stop < m_blockchain_storage->get_current_blockchain_height()))
132 MINFO(
"Using requested block height: " << requested_block_stop);
133 block_stop = requested_block_stop;
137 block_stop = m_blockchain_storage->get_current_blockchain_height() - 1;
138 MINFO(
"Using block height of source blockchain: " << block_stop);
140 MINFO(
"Storing blocks raw data...");
143 MFATAL(
"failed to open raw file for write");
146 for (m_cur_height = block_start; m_cur_height <= block_stop; ++m_cur_height)
149 crypto::hash hash = m_blockchain_storage->get_block_id_by_height(m_cur_height);
154 if (m_cur_height % progress_interval == 0) {
155 std::cout << refresh_string;
156 std::cout <<
"block " << m_cur_height <<
"/" << block_stop << std::flush;
160 std::cout << refresh_string;
161 std::cout <<
"block " << m_cur_height-1 <<
"/" << block_stop <<
ENDL;
163 MINFO(
"Number of blocks exported: " << num_blocks_written);
bool store_blockchain_raw(cryptonote::Blockchain *cs, cryptonote::tx_memory_pool *txp, boost::filesystem::path &output_file, uint64_t use_block_height=0)
bool open_writer(const boost::filesystem::path &file_path, uint64_t block_stop)
Holds cryptonote related classes and helpers.
#define NUM_BLOCKS_PER_CHUNK
bool initialize_file(uint64_t block_stop)
unsigned __int64 uint64_t
Transaction pool, handles transactions which are not part of a block.
void write_block(const crypto::hash &block_hash)