diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-12-13 11:12:00 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-12-13 11:14:00 +0000 |
commit | 4833f4f96f4aa97cc01c672a71e76a32caf9efa0 (patch) | |
tree | 1ca94077e63a08b44f4cc0284f3f5647cfcdf06b /src/blockchain_db | |
parent | tx_pool: fix "minumim" typo in message (diff) | |
download | monero-4833f4f96f4aa97cc01c672a71e76a32caf9efa0.tar.xz |
db_bdb: implement BlockchainBDB::reset
It is needed by the core tests
Diffstat (limited to 'src/blockchain_db')
-rw-r--r-- | src/blockchain_db/berkeleydb/db_bdb.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp index f30e156c1..07cb622a7 100644 --- a/src/blockchain_db/berkeleydb/db_bdb.cpp +++ b/src/blockchain_db/berkeleydb/db_bdb.cpp @@ -1042,7 +1042,46 @@ void BlockchainBDB::sync() void BlockchainBDB::reset() { LOG_PRINT_L3("BlockchainBDB::" << __func__); - // TODO: this + check_open(); + + bdb_txn_safe txn; + if (m_env->txn_begin(NULL, txn, 0)) + throw0(DB_ERROR("Failed to create a transaction for the db")); + m_write_txn = &txn; + try + { + uint32_t count; + + m_blocks->truncate(*m_write_txn, &count, 0); + m_block_heights->truncate(*m_write_txn, &count, 0); + m_block_hashes->truncate(*m_write_txn, &count, 0); + m_block_timestamps->truncate(*m_write_txn, &count, 0); + m_block_sizes->truncate(*m_write_txn, &count, 0); + m_block_diffs->truncate(*m_write_txn, &count, 0); + m_block_coins->truncate(*m_write_txn, &count, 0); + + m_txs->truncate(*m_write_txn, &count, 0); + m_tx_unlocks->truncate(*m_write_txn, &count, 0); + m_tx_heights->truncate(*m_write_txn, &count, 0); + m_tx_outputs->truncate(*m_write_txn, &count, 0); + + m_output_txs->truncate(*m_write_txn, &count, 0); + m_output_indices->truncate(*m_write_txn, &count, 0); + m_output_amounts->truncate(*m_write_txn, &count, 0); + m_output_keys->truncate(*m_write_txn, &count, 0); + + m_spent_keys->truncate(*m_write_txn, &count, 0); + + m_hf_starting_heights->truncate(*m_write_txn, &count, 0); + m_hf_versions->truncate(*m_write_txn, &count, 0); + + m_properties->truncate(*m_write_txn, &count, 0); + } + catch (const std::exception& e) + { + throw0(DB_ERROR(std::string("Failed to reset database: ").append(e.what()).c_str())); + } + m_write_txn = NULL; } std::vector<std::string> BlockchainBDB::get_filenames() const |