xmreg::init_blockchain added

This commit is contained in:
moneroexamples 2016-04-07 13:41:15 +08:00
parent ca2e97e8dc
commit 38a77c6cbf
5 changed files with 39 additions and 18 deletions

View File

@ -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 {

View File

@ -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;
}
}

View File

@ -65,6 +65,15 @@ namespace xmreg
virtual ~MicroCore();
};
bool
init_blockchain(const string& path,
MicroCore& mcore,
Blockchain*& core_storage);
}

View File

@ -144,8 +144,6 @@ namespace xmreg
array<size_t, 5>
timestamp_difference(uint64_t t1, uint64_t t2);
}
#endif //XMREG01_TOOLS_H

View File

@ -60,7 +60,6 @@ namespace xmreg
get_encrypted_payment_id(const transaction& tx,
crypto::hash8& payment_id);
}
template<>