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.
This commit is contained in:
moneromooo-monero 2015-12-05 12:40:01 +00:00
parent 3bf35e14e3
commit a702118426
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3

View file

@ -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<std::string>(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<std::string>(idx));
write_pod(d, "pubkey", string_tools::pod_to_hex(od.pubkey));
write_pod(d, "unlock_time", od.unlock_time);