MCPcopy Create free account
hub / github.com/bcndev/bytecoin / export_blockchain2

Method export_blockchain2

src/Core/BlockChainFileFormat.cpp:257–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255}
256
257bool LegacyBlockChainWriter::export_blockchain2(const std::string &index_file_name, const std::string &item_file_name,
258 const BlockChainState &block_chain, Height max_height) {
259 auto idea_start = std::chrono::high_resolution_clock::now();
260 std::cout << "Start exporting blocks" << std::endl;
261 LegacyBlockChainWriter writer(index_file_name, item_file_name, block_chain.get_tip_height() + 1);
262 for (Height ha = 0; ha != block_chain.get_tip_height() + 1; ++ha) {
263 if (ha >= max_height)
264 break;
265 Hash bid{};
266 BinaryArray block_data;
267 RawBlock raw_block;
268 if (!block_chain.get_chain(ha, &bid) || !block_chain.get_block(bid, &block_data, &raw_block))
269 throw std::runtime_error("block_chain.get_block failed");
270 writer.write_block(raw_block);
271 if (ha % 10000 == 0)
272 std::cout << "Exporting block " << ha << "/" << block_chain.get_tip_height() << std::endl;
273 }
274 auto idea_ms =
275 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - idea_start);
276 std::cout << "Last exported block " << block_chain.get_tip_height() << " seconds=" << double(idea_ms.count()) / 1000
277 << std::endl;
278 return true;
279}

Callers

nothing calls this directly

Calls 4

get_chainMethod · 0.80
get_blockMethod · 0.80
write_blockMethod · 0.80
get_tip_heightMethod · 0.45

Tested by

no test coverage detected