| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#pragma once |
| 30 |
|
| 31 |
#include <boost/iostreams/stream_buffer.hpp> |
| 32 |
#include <boost/iostreams/stream.hpp> |
| 33 |
#include <boost/iostreams/device/back_inserter.hpp> |
| 34 |
#include <boost/iostreams/filtering_streambuf.hpp> |
| 35 |
#include <boost/filesystem/path.hpp> |
| 36 |
#include <boost/filesystem/operations.hpp> |
| 37 |
|
| 38 |
#include "cryptonote_basic/cryptonote_basic.h" |
| 39 |
#include "cryptonote_core/blockchain.h" |
| 40 |
|
| 41 |
#include <algorithm> |
| 42 |
#include <cstdio> |
| 43 |
#include <fstream> |
| 44 |
#include <atomic> |
| 45 |
|
| 46 |
#include "common/command_line.h" |
| 47 |
#include "version.h" |
| 48 |
|
| 49 |
#include "blockchain_utilities.h" |
| 50 |
|
| 51 |
|
| 52 |
using namespace cryptonote; |
| 53 |
|
| 54 |
|
| 55 |
class BootstrapFile |
| 56 |
{ |
| 57 |
public: |
| 58 |
|
| 59 |
uint64_t count_bytes(std::ifstream& import_file, uint64_t blocks, uint64_t& h, bool& quit); |
| 60 |
uint64_t count_blocks(const std::string& dir_path, std::streampos& start_pos, uint64_t& seek_height, uint64_t& block_first); |
| 61 |
uint64_t count_blocks(const std::string& dir_path); |
| 62 |
uint64_t seek_to_first_chunk(std::ifstream& import_file, uint8_t &major_version, uint8_t &minor_version, uint64_t &block_first, uint64_t &block_last); |
| 63 |
|
| 64 |
bool store_blockchain_raw(cryptonote::Blockchain* cs, cryptonote::tx_memory_pool* txp, |
| 65 |
boost::filesystem::path& output_file, uint64_t start_block=0, uint64_t stop_block=0); |
| 66 |
|
| 67 |
protected: |
| 68 |
|
| 69 |
Blockchain* m_blockchain_storage; |
| 70 |
|
| 71 |
tx_memory_pool* m_tx_pool; |
| 72 |
typedef std::vector<char> buffer_type; |
| 73 |
std::ofstream * m_raw_data_file; |
| 74 |
buffer_type m_buffer; |
| 75 |
boost::iostreams::stream<boost::iostreams::back_insert_device<buffer_type>>* m_output_stream; |
| 76 |
|
| 77 |
|
| 78 |
bool open_writer(const boost::filesystem::path& file_path, uint64_t start_block, uint64_t stop_block); |
| 79 |
bool initialize_file(uint64_t start_block, uint64_t stop_block); |
| 80 |
bool close(); |
| 81 |
void write_block(block& block); |
| 82 |
void flush_chunk(); |
| 83 |
|
| 84 |
private: |
| 85 |
|
| 86 |
uint64_t m_height; |
| 87 |
uint64_t m_cur_height; |
| 88 |
uint32_t m_max_chunk; |
| 89 |
}; |