Added GetArgUInt function 243/head
authorsvost <ya.nowa@yandex.ru>
Wed, 30 Sep 2015 10:15:52 +0000 (13:15 +0300)
committersvost <ya.nowa@yandex.ru>
Wed, 30 Sep 2015 10:15:52 +0000 (13:15 +0300)
src/db.cpp
src/rpcwallet.cpp
src/util.cpp
src/util.h

index 28d6032..d857cf0 100644 (file)
@@ -335,7 +335,7 @@ void CDB::Close()
     if (IsChainFile(strFile) && IsInitialBlockDownload())
         nMinutes = 5;
 
-    bitdb.dbenv.txn_checkpoint(nMinutes ? GetArg("-dblogsize", 100)*1024 : 0, nMinutes, 0);
+    bitdb.dbenv.txn_checkpoint(nMinutes ? GetArgUInt("-dblogsize", 100)*1024 : 0, nMinutes, 0);
 
     {
         LOCK(bitdb.cs_db);
index 67c24e3..8490d3e 100644 (file)
@@ -1429,7 +1429,7 @@ Value keypoolrefill(const Array& params, bool fHelp)
             "should be replaced with the newly generated one."
             + HelpRequiringPassphrase());
 
-    unsigned int nSize = max<unsigned int>(GetArg("-keypool", 100), 0);
+    unsigned int nSize = max<unsigned int>(GetArgUInt("-keypool", 100), 0);
     if (params.size() > 0) {
         if (params[0].get_int() < 0)
             throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size");
@@ -1456,7 +1456,7 @@ Value keypoolreset(const Array& params, bool fHelp)
             "should be replaced with the newly generated one."
             + HelpRequiringPassphrase());
 
-    unsigned int nSize = max<unsigned int>(GetArg("-keypool", 100), 0);
+    unsigned int nSize = max<unsigned int>(GetArgUInt("-keypool", 100), 0);
     if (params.size() > 0) {
         if (params[0].get_int() < 0)
             throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size");
index f540500..8f896d7 100644 (file)
@@ -595,6 +595,13 @@ int32_t GetArgInt(const std::string& strArg, int32_t nDefault)
     return nDefault;
 }
 
+uint32_t GetArgUInt(const std::string& strArg, uint32_t nDefault)
+{
+    if (mapArgs.count(strArg))
+        return strtoul(mapArgs[strArg]);
+    return nDefault;
+}
+
 bool GetBoolArg(const std::string& strArg, bool fDefault)
 {
     if (mapArgs.count(strArg))
index 25f6c2a..1b119d6 100644 (file)
@@ -278,6 +278,16 @@ inline int32_t strtol(const std::string& str)
     return strtol(str.c_str(), NULL, 10);
 }
 
+inline uint32_t strtoul(const char* psz)
+{
+    return strtoul(psz, NULL, 10);
+}
+
+inline uint32_t strtoul(const std::string& str)
+{
+    return strtoul(str.c_str(), NULL, 10);
+}
+
 inline int atoi(const std::string& str)
 {
     return atoi(str.c_str());
@@ -415,6 +425,15 @@ int64_t GetArg(const std::string& strArg, int64_t nDefault);
 int32_t GetArgInt(const std::string& strArg, int32_t nDefault);
 
 /**
+ * Return 32-bit unsigned integer argument or default value
+ *
+ * @param strArg Argument to get (e.g. "-foo")
+ * @param default (e.g. 1)
+ * @return command-line argument (0 if invalid number) or default value
+ */
+uint32_t GetArgUInt(const std::string& strArg, uint32_t nDefault);
+
+/**
  * Return boolean argument or default value
  *
  * @param strArg Argument to get (e.g. "-foo")