Last active
December 24, 2015 00:39
-
-
Save Bobalot/6718265 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
/* | |
Magic read test derp | |
*/ | |
#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); | |
int i=0; | |
while(i < 10000) | |
{ | |
block_header_type blk_header; | |
std::promise<std::error_code> ec_fetch_promise; | |
auto genesis_block_fetched_handler = | |
[&ec_fetch_promise, &blk_header]( | |
const std::error_code& ec, const block_header_type& header) | |
{ | |
blk_header = header; | |
ec_fetch_promise.set_value(ec); | |
}; | |
// See if we can fetch the genesis block from the leveldb database | |
chain.fetch_block_header(0, genesis_block_fetched_handler); | |
std::error_code ec = ec_fetch_promise.get_future().get(); | |
if (ec) | |
{ | |
exit(1); | |
} | |
usleep(1000); | |
std::cout << i << std::endl; | |
i++; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment