aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blockchain_db/blockchain_db.cpp32
-rw-r--r--src/blockchain_db/db_types.h7
-rw-r--r--src/blockchain_utilities/blockchain_export.cpp18
-rw-r--r--src/blockchain_utilities/blockchain_import.cpp46
-rw-r--r--src/common/command_line.cpp2
-rw-r--r--src/daemon/main.cpp9
6 files changed, 42 insertions, 72 deletions
diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp
index c7ca533ef..01a59e079 100644
--- a/src/blockchain_db/blockchain_db.cpp
+++ b/src/blockchain_db/blockchain_db.cpp
@@ -38,6 +38,14 @@
#include "berkeleydb/db_bdb.h"
#endif
+static const char *db_types[] = {
+ "lmdb",
+#ifdef BERKELEY_DB
+ "berkeley",
+#endif
+ NULL
+};
+
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "blockchain.db"
@@ -46,6 +54,30 @@ using epee::string_tools::pod_to_hex;
namespace cryptonote
{
+bool blockchain_valid_db_type(const std::string& db_type)
+{
+ int i;
+ for (i=0; db_types[i]; i++)
+ {
+ if (db_types[i] == db_type)
+ return true;
+ }
+ return false;
+}
+
+std::string blockchain_db_types(const std::string& sep)
+{
+ int i;
+ std::string ret = "";
+ for (i=0; db_types[i]; i++)
+ {
+ if (i)
+ ret += sep;
+ ret += db_types[i];
+ }
+ return ret;
+}
+
BlockchainDB *new_db(const std::string& db_type)
{
if (db_type == "lmdb")
diff --git a/src/blockchain_db/db_types.h b/src/blockchain_db/db_types.h
index 6c21b029e..8e2f58a61 100644
--- a/src/blockchain_db/db_types.h
+++ b/src/blockchain_db/db_types.h
@@ -31,9 +31,6 @@
namespace cryptonote
{
-
- const std::unordered_set<std::string> blockchain_db_types =
- { "lmdb"
- };
-
+ bool blockchain_valid_db_type(const std::string& db_type);
+ std::string blockchain_db_types(const std::string& sep);
} // namespace cryptonote
diff --git a/src/blockchain_utilities/blockchain_export.cpp b/src/blockchain_utilities/blockchain_export.cpp
index 82eca91b6..20eca09f2 100644
--- a/src/blockchain_utilities/blockchain_export.cpp
+++ b/src/blockchain_utilities/blockchain_export.cpp
@@ -40,17 +40,6 @@
namespace po = boost::program_options;
using namespace epee;
-std::string join_set_strings(const std::unordered_set<std::string>& db_types_all, const char* delim)
-{
- std::string result;
- std::ostringstream s;
- std::copy(db_types_all.begin(), db_types_all.end(), std::ostream_iterator<std::string>(s, delim));
- result = s.str();
- if (result.length() > 0)
- result.erase(result.end()-strlen(delim), result.end());
- return result;
-}
-
int main(int argc, char* argv[])
{
TRY_ENTRY();
@@ -59,10 +48,7 @@ int main(int argc, char* argv[])
std::string default_db_type = "lmdb";
- std::unordered_set<std::string> db_types_all = cryptonote::blockchain_db_types;
- db_types_all.insert("memory");
-
- std::string available_dbs = join_set_strings(db_types_all, ", ");
+ std::string available_dbs = cryptonote::blockchain_db_types(", ");
available_dbs = "available: " + available_dbs;
uint32_t log_level = 0;
@@ -140,7 +126,7 @@ int main(int argc, char* argv[])
m_config_folder = command_line::get_arg(vm, data_dir_arg);
std::string db_type = command_line::get_arg(vm, arg_database);
- if (db_types_all.count(db_type) == 0)
+ if (!cryptonote::blockchain_valid_db_type(db_type))
{
std::cerr << "Invalid database type: " << db_type << std::endl;
return 1;
diff --git a/src/blockchain_utilities/blockchain_import.cpp b/src/blockchain_utilities/blockchain_import.cpp
index 34dcb28ac..ded854ca4 100644
--- a/src/blockchain_utilities/blockchain_import.cpp
+++ b/src/blockchain_utilities/blockchain_import.cpp
@@ -42,8 +42,6 @@
#include "blockchain_db/db_types.h"
#include "cryptonote_core/cryptonote_core.h"
-#include <lmdb.h> // for db flag arguments
-
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "bcutil"
@@ -78,18 +76,6 @@ namespace po = boost::program_options;
using namespace cryptonote;
using namespace epee;
-
-std::string join_set_strings(const std::unordered_set<std::string>& db_types_all, const char* delim)
-{
- std::string result;
- std::ostringstream s;
- std::copy(db_types_all.begin(), db_types_all.end(), std::ostream_iterator<std::string>(s, delim));
- result = s.str();
- if (result.length() > 0)
- result.erase(result.end()-strlen(delim), result.end());
- return result;
-}
-
// db_mode: safe, fast, fastest
int get_db_flags_from_mode(const std::string& db_mode)
{
@@ -516,12 +502,8 @@ int main(int argc, char* argv[])
epee::string_tools::set_module_name_and_folder(argv[0]);
std::string default_db_type = "lmdb";
- std::string default_db_engine_compiled = "blockchain_db";
- std::unordered_set<std::string> db_types_all = cryptonote::blockchain_db_types;
- db_types_all.insert("memory");
-
- std::string available_dbs = join_set_strings(db_types_all, ", ");
+ std::string available_dbs = cryptonote::blockchain_db_types(", ");
available_dbs = "available: " + available_dbs;
uint32_t log_level = 0;
@@ -667,7 +649,6 @@ int main(int argc, char* argv[])
std::string db_type;
- std::string db_engine_compiled;
int db_flags = 0;
int res = 0;
res = parse_db_arguments(db_arg_str, db_type, db_flags);
@@ -677,25 +658,12 @@ int main(int argc, char* argv[])
return 1;
}
- if (db_types_all.count(db_type) == 0)
+ if (!cryptonote::blockchain_valid_db_type(db_type))
{
std::cerr << "Invalid database type: " << db_type << std::endl;
return 1;
}
- if ((db_type == "lmdb")
-#if defined(BERKELEY_DB)
- || (db_type == "berkeley")
-#endif
- )
- {
- db_engine_compiled = "blockchain_db";
- }
- else
- {
- db_engine_compiled = "memory";
- }
-
MINFO("database: " << db_type);
MINFO("database flags: " << db_flags);
MINFO("verify: " << std::boolalpha << opt_verify << std::noboolalpha);
@@ -724,16 +692,6 @@ int main(int argc, char* argv[])
// properties to do so. Both ways work, but fake core isn't necessary in that
// circumstance.
- if (db_type != "lmdb"
-#if defined(BERKELEY_DB)
- && db_type != "berkeley"
-#endif
- )
- {
- std::cerr << "database type unrecognized" << ENDL;
- return 1;
- }
-
cryptonote::cryptonote_protocol_stub pr; //TODO: stub only for this kind of test, make real validation of relayed objects
cryptonote::core core(&pr);
core.disable_dns_checkpoints(true);
diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp
index 925d8ff3b..ad66b2009 100644
--- a/src/common/command_line.cpp
+++ b/src/common/command_line.cpp
@@ -96,7 +96,7 @@ namespace command_line
, "checkpoints from DNS server will be enforced"
, false
};
- std::string arg_db_type_description = "Specify database type, available: " + boost::algorithm::join(cryptonote::blockchain_db_types, ", ");
+ std::string arg_db_type_description = "Specify database type, available: " + cryptonote::blockchain_db_types(", ");
const command_line::arg_descriptor<std::string> arg_db_type = {
"db-type"
, arg_db_type_description.c_str()
diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp
index 19dd02171..456eeee64 100644
--- a/src/daemon/main.cpp
+++ b/src/daemon/main.cpp
@@ -145,13 +145,10 @@ int main(int argc, char const * argv[])
std::string db_type = command_line::get_arg(vm, command_line::arg_db_type);
// verify that blockchaindb type is valid
- if(cryptonote::blockchain_db_types.count(db_type) == 0)
+ if(!cryptonote::blockchain_valid_db_type(db_type))
{
- std::cout << "Invalid database type (" << db_type << "), available types are:" << std::endl;
- for (const auto& type : cryptonote::blockchain_db_types)
- {
- std::cout << "\t" << type << std::endl;
- }
+ std::cout << "Invalid database type (" << db_type << "), available types are: " <<
+ cryptonote::blockchain_db_types(", ") << std::endl;
return 0;
}