Electroneum
Loading...
Searching...
No Matches
BlocksdatFile Class Reference

#include <blocksdat_file.h>

Collaboration diagram for BlocksdatFile:

Public Member Functions

bool store_blockchain_raw (cryptonote::Blockchain *cs, cryptonote::tx_memory_pool *txp, boost::filesystem::path &output_file, uint64_t use_block_height=0)

Protected Member Functions

bool open_writer (const boost::filesystem::path &file_path, uint64_t block_stop)
bool initialize_file (uint64_t block_stop)
bool close ()
void write_block (const crypto::hash &block_hash)

Protected Attributes

Blockchainm_blockchain_storage
std::ofstream * m_raw_data_file

Detailed Description

Definition at line 58 of file blocksdat_file.h.

Member Function Documentation

◆ close()

bool BlocksdatFile::close ( )
protected

Definition at line 109 of file blocksdat_file.cpp.

110{
111 if (m_raw_data_file->fail())
112 return false;
113
114 m_raw_data_file->flush();
115 delete m_raw_data_file;
116 return true;
117}
std::ofstream * m_raw_data_file
Here is the caller graph for this function:

◆ initialize_file()

bool BlocksdatFile::initialize_file ( uint64_t block_stop)
protected

Definition at line 84 of file blocksdat_file.cpp.

85{
86 const uint32_t nblocks = block_stop + 1;
87 unsigned char nblocksc[4];
88
89 nblocksc[0] = nblocks & 0xff;
90 nblocksc[1] = (nblocks >> 8) & 0xff;
91 nblocksc[2] = (nblocks >> 16) & 0xff;
92 nblocksc[3] = (nblocks >> 24) & 0xff;
93
94 // 4 bytes little endian
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];
99
100 return true;
101}
unsigned int uint32_t
Definition stdint.h:126
Here is the caller graph for this function:

◆ open_writer()

bool BlocksdatFile::open_writer ( const boost::filesystem::path & file_path,
uint64_t block_stop )
protected

Definition at line 47 of file blocksdat_file.cpp.

48{
49 const boost::filesystem::path dir_path = file_path.parent_path();
50 if (!dir_path.empty())
51 {
52 if (boost::filesystem::exists(dir_path))
53 {
54 if (!boost::filesystem::is_directory(dir_path))
55 {
56 MFATAL("export directory path is a file: " << dir_path);
57 return false;
58 }
59 }
60 else
61 {
62 if (!boost::filesystem::create_directory(dir_path))
63 {
64 MFATAL("Failed to create directory " << dir_path);
65 return false;
66 }
67 }
68 }
69
70 m_raw_data_file = new std::ofstream();
71
72 MINFO("creating file");
73
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())
76 return false;
77
78 initialize_file(block_stop);
79
80 return true;
81}
bool initialize_file(uint64_t block_stop)
#define MFATAL(x)
Definition misc_log_ex.h:72
#define MINFO(x)
Definition misc_log_ex.h:75
Here is the call graph for this function:
Here is the caller graph for this function:

◆ store_blockchain_raw()

bool BlocksdatFile::store_blockchain_raw ( cryptonote::Blockchain * cs,
cryptonote::tx_memory_pool * txp,
boost::filesystem::path & output_file,
uint64_t use_block_height = 0 )

Definition at line 120 of file blocksdat_file.cpp.

121{
122 uint64_t num_blocks_written = 0;
123 m_blockchain_storage = _blockchain_storage;
124 uint64_t progress_interval = 100;
125 block b;
126
127 uint64_t block_start = 0;
128 uint64_t block_stop = 0;
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()))
131 {
132 MINFO("Using requested block height: " << requested_block_stop);
133 block_stop = requested_block_stop;
134 }
135 else
136 {
137 block_stop = m_blockchain_storage->get_current_blockchain_height() - 1;
138 MINFO("Using block height of source blockchain: " << block_stop);
139 }
140 MINFO("Storing blocks raw data...");
141 if (!BlocksdatFile::open_writer(output_file, block_stop))
142 {
143 MFATAL("failed to open raw file for write");
144 return false;
145 }
146 for (m_cur_height = block_start; m_cur_height <= block_stop; ++m_cur_height)
147 {
148 // this method's height refers to 0-based height (genesis block = height 0)
149 crypto::hash hash = m_blockchain_storage->get_block_id_by_height(m_cur_height);
150 write_block(hash);
151 if (m_cur_height % NUM_BLOCKS_PER_CHUNK == 0) {
152 num_blocks_written += NUM_BLOCKS_PER_CHUNK;
153 }
154 if (m_cur_height % progress_interval == 0) {
155 std::cout << refresh_string;
156 std::cout << "block " << m_cur_height << "/" << block_stop << std::flush;
157 }
158 }
159 // print message for last block, which may not have been printed yet due to progress_interval
160 std::cout << refresh_string;
161 std::cout << "block " << m_cur_height-1 << "/" << block_stop << ENDL;
162
163 MINFO("Number of blocks exported: " << num_blocks_written);
164
165 return BlocksdatFile::close();
166}
#define NUM_BLOCKS_PER_CHUNK
bool open_writer(const boost::filesystem::path &file_path, uint64_t block_stop)
Blockchain * m_blockchain_storage
void write_block(const crypto::hash &block_hash)
#define ENDL
POD_CLASS hash
Definition hash.h:50
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_block()

void BlocksdatFile::write_block ( const crypto::hash & block_hash)
protected

Definition at line 103 of file blocksdat_file.cpp.

104{
105 const std::string data(block_hash.data, sizeof(block_hash));
106 *m_raw_data_file << data;
107}
Here is the caller graph for this function:

Member Data Documentation

◆ m_blockchain_storage

Blockchain* BlocksdatFile::m_blockchain_storage
protected

Definition at line 67 of file blocksdat_file.h.

◆ m_raw_data_file

std::ofstream* BlocksdatFile::m_raw_data_file
protected

Definition at line 69 of file blocksdat_file.h.


The documentation for this class was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/blockchain_utilities/blocksdat_file.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/blockchain_utilities/blocksdat_file.cpp