aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwarptangent <warptangent@inbox.com>2015-03-22 10:57:18 -0700
committerwarptangent <warptangent@inbox.com>2015-03-22 15:45:36 -0700
commit4bedd68d2c058184333101e4d3a31856f6226cd4 (patch)
tree015b313092cec3288f5cf8483eafcbe04128732f
parentAdd README for blockchain converter, importer, and exporter utilities (diff)
downloadmonero-4bedd68d2c058184333101e4d3a31856f6226cd4.tar.xz
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.
-rw-r--r--src/blockchain_converter/blockchain_export.cpp10
-rw-r--r--src/blockchain_converter/blockchain_import.cpp6
-rw-r--r--src/blockchain_converter/fake_core.h8
-rw-r--r--src/cryptonote_core/blockchain.h4
4 files changed, 14 insertions, 14 deletions
diff --git a/src/blockchain_converter/blockchain_export.cpp b/src/blockchain_converter/blockchain_export.cpp
index 2467951de..f0fd44a4f 100644
--- a/src/blockchain_converter/blockchain_export.cpp
+++ b/src/blockchain_converter/blockchain_export.cpp
@@ -148,7 +148,7 @@ void BlockchainExport::write_block(block& block)
#if SOURCE_DB == DB_MEMORY
const transaction* cb_tx_full = m_blockchain_storage->get_tx(coinbase_tx_hash);
#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
#if SOURCE_DB == DB_MEMORY
@@ -167,7 +167,7 @@ void BlockchainExport::write_block(block& block)
#if SOURCE_DB == DB_MEMORY
const transaction* tx = m_blockchain_storage->get_tx(tx_id);
#else
- transaction tx = m_blockchain_storage->get_db()->get_tx(tx_id);
+ transaction tx = m_blockchain_storage->get_db().get_tx(tx_id);
#endif
#if SOURCE_DB == DB_MEMORY
@@ -205,18 +205,18 @@ void BlockchainExport::write_block(block& block)
#if SOURCE_DB == DB_MEMORY
size_t block_size = m_blockchain_storage->get_block_size(block_height);
#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
#if SOURCE_DB == DB_MEMORY
difficulty_type cumulative_difficulty = m_blockchain_storage->get_block_cumulative_difficulty(block_height);
#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
#if SOURCE_DB == DB_MEMORY
uint64_t coins_generated = m_blockchain_storage->get_block_coins_generated(block_height);
#else
// 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
*m_raw_archive << block_size;
diff --git a/src/blockchain_converter/blockchain_import.cpp b/src/blockchain_converter/blockchain_import.cpp
index 060fe8481..841624e43 100644
--- a/src/blockchain_converter/blockchain_import.cpp
+++ b/src/blockchain_converter/blockchain_import.cpp
@@ -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
// from addition of genesis block.
// 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
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();
std::cout << ENDL;
#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
}
}
@@ -525,7 +525,7 @@ int import_from_file(FakeCore& simple_core, std::string& import_file_path)
simple_core.batch_stop();
}
#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
if (h > 0)
LOG_PRINT_L0("Finished at height: " << h << " block: " << h-1);
diff --git a/src/blockchain_converter/fake_core.h b/src/blockchain_converter/fake_core.h
index aff249cd9..175cb4660 100644
--- a/src/blockchain_converter/fake_core.h
+++ b/src/blockchain_converter/fake_core.h
@@ -55,7 +55,7 @@ struct fake_core_lmdb
m_pool.init(path.string());
m_storage.init(path.string(), use_testnet, mdb_flags);
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_add_block = true;
}
@@ -71,17 +71,17 @@ struct fake_core_lmdb
, 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()
{
- m_storage.get_db()->batch_start();
+ m_storage.get_db().batch_start();
}
void batch_stop()
{
- m_storage.get_db()->batch_stop();
+ m_storage.get_db().batch_stop();
}
};
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index da4da075b..dc98a56a4 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -145,9 +145,9 @@ namespace cryptonote
void set_enforce_dns_checkpoints(bool enforce);
bool update_checkpoints(const std::string& file_path, bool check_dns);
- BlockchainDB* get_db()
+ BlockchainDB& get_db()
{
- return m_db;
+ return *m_db;
}
private: