From 38a77c6cbfd569bfb2fa3a6eebb3517f67bcc952 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Thu, 7 Apr 2016 13:41:15 +0800 Subject: [PATCH] xmreg::init_blockchain added --- main.cpp | 18 +++++------------- src/MicroCore.cpp | 27 +++++++++++++++++++++++++-- src/MicroCore.h | 9 +++++++++ src/tools.h | 2 -- src/tx_details.h | 1 - 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/main.cpp b/main.cpp index 1fb7d33..ef2bd30 100644 --- a/main.cpp +++ b/main.cpp @@ -17,39 +17,31 @@ namespace epee { } - int main() { path blockchain_path {"/home/mwo/.bitmonero/lmdb"}; - fmt::print("Blockchain path : {}\n", blockchain_path); - // enable basic monero log output xmreg::enable_monero_log(); // create instance of our MicroCore xmreg::MicroCore mcore; + cryptonote::Blockchain* core_storage; - // initialize the core using the blockchain path - if (!mcore.init(blockchain_path.string())) + if (!xmreg::init_blockchain(blockchain_path.string(), + mcore, core_storage)) { cerr << "Error accessing blockchain." << endl; return 1; } - // get the high level cryptonote::Blockchain object to interact - // with the blockchain lmdb database - cryptonote::Blockchain& core_storage = mcore.get_core(); - - // get the current blockchain height. Just to check - // if it reads ok. - uint64_t height = core_storage.get_current_blockchain_height() - 1; + // get the current blockchain height. Just to check if it reads ok. + uint64_t height = core_storage->get_current_blockchain_height() - 1; fmt::print("\n\n" "Top block height : {:d}\n", height); - std::string view {"Blockchain height {{height}}"}; mstch::map context { diff --git a/src/MicroCore.cpp b/src/MicroCore.cpp index c3f72b8..7d66e24 100644 --- a/src/MicroCore.cpp +++ b/src/MicroCore.cpp @@ -36,8 +36,8 @@ namespace xmreg { int db_flags = 0; - db_flags |= MDB_RDONLY; - db_flags |= MDB_NOLOCK; + //db_flags |= MDB_RDONLY; + //db_flags |= MDB_NOLOCK; db_flags |= MDB_NOSYNC; BlockchainDB* db = nullptr; @@ -273,4 +273,27 @@ namespace xmreg { delete &m_blockchain_storage.get_db(); } + + + bool + init_blockchain(const string& path, + MicroCore& mcore, + Blockchain*& core_storage) + { + + // initialize the core using the blockchain path + if (!mcore.init(path)) + { + cerr << "Error accessing blockchain." << endl; + return false; + } + + // get the high level Blockchain object to interact + // with the blockchain lmdb database + core_storage = &(mcore.get_core()); + + return true; + } + + } \ No newline at end of file diff --git a/src/MicroCore.h b/src/MicroCore.h index 6e64559..9e694a8 100644 --- a/src/MicroCore.h +++ b/src/MicroCore.h @@ -65,6 +65,15 @@ namespace xmreg virtual ~MicroCore(); }; + + + + bool + init_blockchain(const string& path, + MicroCore& mcore, + Blockchain*& core_storage); + + } diff --git a/src/tools.h b/src/tools.h index 4f058e4..f8be91d 100644 --- a/src/tools.h +++ b/src/tools.h @@ -144,8 +144,6 @@ namespace xmreg array timestamp_difference(uint64_t t1, uint64_t t2); - - } #endif //XMREG01_TOOLS_H diff --git a/src/tx_details.h b/src/tx_details.h index 1cb551b..db77038 100644 --- a/src/tx_details.h +++ b/src/tx_details.h @@ -60,7 +60,6 @@ namespace xmreg get_encrypted_payment_id(const transaction& tx, crypto::hash8& payment_id); - } template<>