Update Blockchain::get_db() to return reference instead of pointer

Where this method is used, a BlockchainDB object is always expected, so
a pointer is unnecessary and less safe.
This commit is contained in:
warptangent 2015-03-22 10:57:18 -07:00
parent 0386e9925b
commit 4bedd68d2c
No known key found for this signature in database
GPG key ID: 0E490BEBFBE4E92D
4 changed files with 14 additions and 14 deletions

View file

@ -148,7 +148,7 @@ void BlockchainExport::write_block(block& block)
#if SOURCE_DB == DB_MEMORY #if SOURCE_DB == DB_MEMORY
const transaction* cb_tx_full = m_blockchain_storage->get_tx(coinbase_tx_hash); const transaction* cb_tx_full = m_blockchain_storage->get_tx(coinbase_tx_hash);
#else #else
transaction cb_tx_full = m_blockchain_storage->get_db()->get_tx(coinbase_tx_hash); transaction cb_tx_full = m_blockchain_storage->get_db().get_tx(coinbase_tx_hash);
#endif #endif
#if SOURCE_DB == DB_MEMORY #if SOURCE_DB == DB_MEMORY
@ -167,7 +167,7 @@ void BlockchainExport::write_block(block& block)
#if SOURCE_DB == DB_MEMORY #if SOURCE_DB == DB_MEMORY
const transaction* tx = m_blockchain_storage->get_tx(tx_id); const transaction* tx = m_blockchain_storage->get_tx(tx_id);
#else #else
transaction tx = m_blockchain_storage->get_db()->get_tx(tx_id); transaction tx = m_blockchain_storage->get_db().get_tx(tx_id);
#endif #endif
#if SOURCE_DB == DB_MEMORY #if SOURCE_DB == DB_MEMORY
@ -205,18 +205,18 @@ void BlockchainExport::write_block(block& block)
#if SOURCE_DB == DB_MEMORY #if SOURCE_DB == DB_MEMORY
size_t block_size = m_blockchain_storage->get_block_size(block_height); size_t block_size = m_blockchain_storage->get_block_size(block_height);
#else #else
size_t block_size = m_blockchain_storage->get_db()->get_block_size(block_height); size_t block_size = m_blockchain_storage->get_db().get_block_size(block_height);
#endif #endif
#if SOURCE_DB == DB_MEMORY #if SOURCE_DB == DB_MEMORY
difficulty_type cumulative_difficulty = m_blockchain_storage->get_block_cumulative_difficulty(block_height); difficulty_type cumulative_difficulty = m_blockchain_storage->get_block_cumulative_difficulty(block_height);
#else #else
difficulty_type cumulative_difficulty = m_blockchain_storage->get_db()->get_block_cumulative_difficulty(block_height); difficulty_type cumulative_difficulty = m_blockchain_storage->get_db().get_block_cumulative_difficulty(block_height);
#endif #endif
#if SOURCE_DB == DB_MEMORY #if SOURCE_DB == DB_MEMORY
uint64_t coins_generated = m_blockchain_storage->get_block_coins_generated(block_height); uint64_t coins_generated = m_blockchain_storage->get_block_coins_generated(block_height);
#else #else
// TODO TEST to verify that this is the equivalent. make sure no off-by-one error with block height vs block number // TODO TEST to verify that this is the equivalent. make sure no off-by-one error with block height vs block number
uint64_t coins_generated = m_blockchain_storage->get_db()->get_block_already_generated_coins(block_height); uint64_t coins_generated = m_blockchain_storage->get_db().get_block_already_generated_coins(block_height);
#endif #endif
*m_raw_archive << block_size; *m_raw_archive << block_size;

View file

@ -214,7 +214,7 @@ int import_from_file(FakeCore& simple_core, std::string& import_file_path)
// Reset stats, in case we're using newly created db, accumulating stats // Reset stats, in case we're using newly created db, accumulating stats
// from addition of genesis block. // from addition of genesis block.
// This aligns internal db counts with importer counts. // This aligns internal db counts with importer counts.
simple_core.m_storage.get_db()->reset_stats(); simple_core.m_storage.get_db().reset_stats();
} }
#endif #endif
boost::filesystem::path raw_file_path(import_file_path); boost::filesystem::path raw_file_path(import_file_path);
@ -497,7 +497,7 @@ int import_from_file(FakeCore& simple_core, std::string& import_file_path)
simple_core.batch_start(); simple_core.batch_start();
std::cout << ENDL; std::cout << ENDL;
#if !defined(BLOCKCHAIN_DB) || (BLOCKCHAIN_DB == DB_LMDB) #if !defined(BLOCKCHAIN_DB) || (BLOCKCHAIN_DB == DB_LMDB)
simple_core.m_storage.get_db()->show_stats(); simple_core.m_storage.get_db().show_stats();
#endif #endif
} }
} }
@ -525,7 +525,7 @@ int import_from_file(FakeCore& simple_core, std::string& import_file_path)
simple_core.batch_stop(); simple_core.batch_stop();
} }
#if !defined(BLOCKCHAIN_DB) || (BLOCKCHAIN_DB == DB_LMDB) #if !defined(BLOCKCHAIN_DB) || (BLOCKCHAIN_DB == DB_LMDB)
simple_core.m_storage.get_db()->show_stats(); simple_core.m_storage.get_db().show_stats();
#endif #endif
if (h > 0) if (h > 0)
LOG_PRINT_L0("Finished at height: " << h << " block: " << h-1); LOG_PRINT_L0("Finished at height: " << h << " block: " << h-1);

View file

@ -55,7 +55,7 @@ struct fake_core_lmdb
m_pool.init(path.string()); m_pool.init(path.string());
m_storage.init(path.string(), use_testnet, mdb_flags); m_storage.init(path.string(), use_testnet, mdb_flags);
if (do_batch) if (do_batch)
m_storage.get_db()->set_batch_transactions(do_batch); m_storage.get_db().set_batch_transactions(do_batch);
support_batch = true; support_batch = true;
support_add_block = true; support_add_block = true;
} }
@ -71,17 +71,17 @@ struct fake_core_lmdb
, const std::vector<transaction>& txs , const std::vector<transaction>& txs
) )
{ {
return m_storage.get_db()->add_block(blk, block_size, cumulative_difficulty, coins_generated, txs); return m_storage.get_db().add_block(blk, block_size, cumulative_difficulty, coins_generated, txs);
} }
void batch_start() void batch_start()
{ {
m_storage.get_db()->batch_start(); m_storage.get_db().batch_start();
} }
void batch_stop() void batch_stop()
{ {
m_storage.get_db()->batch_stop(); m_storage.get_db().batch_stop();
} }
}; };

View file

@ -145,9 +145,9 @@ namespace cryptonote
void set_enforce_dns_checkpoints(bool enforce); void set_enforce_dns_checkpoints(bool enforce);
bool update_checkpoints(const std::string& file_path, bool check_dns); bool update_checkpoints(const std::string& file_path, bool check_dns);
BlockchainDB* get_db() BlockchainDB& get_db()
{ {
return m_db; return *m_db;
} }
private: private: