From a70211842693f00f81c2374b7999eda9e184efce Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 5 Dec 2015 12:40:01 +0000 Subject: [PATCH] blockchain_dump: fix output key dump for BDB 1-based indices Berkeley DB uses 1 based indices for RECNO databases, and the implementation of BlockchainDB for Berkeley DB assumes 1 based indices are passed to the API, whereas the LMDB one assumes 0 based indices. This is all internally consisteny, but since the BDB code stores 1 based indices in the database, external users have to be aware of this, as the indices will be off by one depending on which DB is used. --- src/blockchain_utilities/blockchain_dump.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/blockchain_utilities/blockchain_dump.cpp b/src/blockchain_utilities/blockchain_dump.cpp index f3666c72..6c61cb90 100644 --- a/src/blockchain_utilities/blockchain_dump.cpp +++ b/src/blockchain_utilities/blockchain_dump.cpp @@ -236,16 +236,19 @@ int main(int argc, char* argv[]) BlockchainDB* db; int mdb_flags = 0; std::string db_type = command_line::get_arg(vm, arg_db_type); + size_t base_idx = 0; if (db_type.empty() || db_type == "lmdb") { db = new BlockchainLMDB(); mdb_flags |= MDB_RDONLY; + base_idx = 0; } #ifdef BERKELEY_DB else if (db_type == "berkeley") { db = new BlockchainBDB(); // can't open readonly due to the way flags are split in db_bdb.cpp + base_idx = 1; } #endif else @@ -386,7 +389,7 @@ int main(int argc, char* argv[]) { try { - tx_out_index toi = db->get_output_tx_and_index_from_global(idx); + tx_out_index toi = db->get_output_tx_and_index_from_global(idx + base_idx); start_struct(d, boost::lexical_cast(idx)); write_pod(d, "tx_hash", string_tools::pod_to_hex(toi.first)); write_pod(d, "tx_index", string_tools::pod_to_hex(toi.second)); @@ -406,7 +409,7 @@ int main(int argc, char* argv[]) { try { - output_data_t od = db->get_output_key(idx); + output_data_t od = db->get_output_key(idx + base_idx); start_struct(d, boost::lexical_cast(idx)); write_pod(d, "pubkey", string_tools::pod_to_hex(od.pubkey)); write_pod(d, "unlock_time", od.unlock_time);