db_bdb: implement BlockchainBDB::reset

It is needed by the core tests
This commit is contained in:
moneromooo-monero 2015-12-13 11:12:00 +00:00
parent 18bf06e4a5
commit 4833f4f96f
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3

View File

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