Skip to content

Instantly share code, notes, and snippets.

@genjix
Created September 26, 2013 21:50
Show Gist options
  • Save genjix/6721097 to your computer and use it in GitHub Desktop.
Save genjix/6721097 to your computer and use it in GitHub Desktop.
8679
chain.fetch_block_header()
header_fetched()
//---------------------------------------------
/*
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);
for (size_t i = 0; i < 10000; ++i)
{
block_header_type header;
std::promise<std::error_code> ec_promise;
auto ec_future = ec_promise.get_future();
auto header_fetched = [&ec_promise, &header](
const std::error_code& ec, const block_header_type& blk_head)
{
std::cout << "header_fetched()" << std::endl;
header = blk_head;
ec_promise.set_value(ec);
};
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)
{
exit(1);
}
//usleep(1000);
std::cout << i << 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