From 591b481ec878ec5c1d50827abd60a87fd61fbdee Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Thu, 19 Jan 2017 01:22:33 +0000 Subject: [PATCH] get_block_by_height refactored --- src/MicroCore.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/MicroCore.cpp b/src/MicroCore.cpp index 996f1d6..66e4124 100644 --- a/src/MicroCore.cpp +++ b/src/MicroCore.cpp @@ -109,33 +109,32 @@ namespace xmreg bool MicroCore::get_block_by_height(const uint64_t& height, block& blk) { - - crypto::hash block_id; - try { - block_id = m_blockchain_storage.get_block_id_by_height(height); + blk = m_blockchain_storage.get_db().get_block_from_height(height); } - catch (const exception& e) + catch (const BLOCK_DNE& e) { - cerr << e.what() << endl; + cerr << "Block of height " << height + << " not found in the blockchain!" + << e.what() + << endl; + return false; } - - if (!m_blockchain_storage.have_block(block_id)) + catch (const DB_ERROR& e) { - cerr << "Block with hash " << block_id - << " not found in the blockchain!" + cerr << "Blockchain access error when getting block " << height + << e.what() << endl; return false; } - - if (!m_blockchain_storage.get_block_by_hash(block_id, blk)) + catch (...) { - cerr << "Block with hash " << block_id - << "and height " << height << " not found!" + cerr << "Something went terribly wrong when getting block " << height << endl; + return false; }