Created
September 26, 2013 21:59
-
-
Save genjix/6721172 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <future> | |
#include <bitcoin/bitcoin.hpp> | |
#define LOG_BOOTSTRAP "bootstrap" | |
using namespace bc; | |
using std::placeholders::_1; | |
using std::placeholders::_2; | |
int main(int argc, char** argv) | |
{ | |
const std::string dbpath = "blockchain"; | |
// Threadpool context containing 1 thread. | |
threadpool pool(1); | |
// leveldb_blockchain operations execute in pool's thread. | |
leveldb_blockchain chain(pool); | |
// Completion handler for starting the leveldb_blockchain. | |
// Does nothing. | |
auto blockchain_start = [](const std::error_code& ec) {}; | |
// Start blockchain with a database path. | |
chain.start(dbpath, blockchain_start); | |
for (size_t i = 0; i < 10000; ++i) | |
{ | |
std::cout << i << std::endl; | |
block_header_type header; | |
std::promise<std::error_code> ec_promise; | |
auto ec_future = ec_promise.get_future(); | |
auto header_fetched = [&ec_promise, &header, i]( | |
const std::error_code& ec, const block_header_type& blk_head) | |
{ | |
std::cout << " header_fetched() [" << i << "]" << std::endl; | |
header = blk_head; | |
ec_promise.set_value(ec); | |
std::cout << " finished. [" << i << "]" << std::endl; | |
}; | |
std::cout << " chain.fetch_block_header()" << std::endl; | |
// See if we can fetch the genesis block from the leveldb database | |
chain.fetch_block_header(0, header_fetched); | |
std::error_code ec = ec_future.get(); | |
if (ec) | |
{ | |
std::cerr << "Error: " << ec.message() << std::endl; | |
exit(1); | |
} | |
//usleep(1000); | |
std::cout << " Continue." << std::endl; | |
} | |
pool.stop(); | |
pool.join(); | |
chain.stop(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment