Deprecate accounting API.
[novacoin.git] / src / rpcwallet.cpp
index d1e368c..c55296c 100644 (file)
@@ -20,10 +20,19 @@ extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, json_spiri
 std::string HelpRequiringPassphrase()
 {
     return pwalletMain->IsCrypted()
-        ? "\nrequires wallet passphrase to be set with walletpassphrase first"
+        ? "\n\nRequires wallet passphrase to be set with walletpassphrase first"
         : "";
 }
 
+static void accountingAllowed()
+{
+    if (!GetBoolArg("-accounts", false))
+        throw runtime_error(
+            "Accounting API is deprecated and its removal is planned in the future.\n"
+            "It can easily result in negative or odd balances if misused or misunderstood.\n"
+            "If you still want to enable it then add accounts=1 to your options.\n");
+}
+
 void EnsureWalletIsUnlocked()
 {
     if (pwalletMain->IsLocked())
@@ -173,6 +182,9 @@ Value getaccountaddress(const Array& params, bool fHelp)
             "getaccountaddress <account>\n"
             "Returns the current NovaCoin address for receiving payments to this account.");
 
+    // Deprecation check
+    accountingAllowed();
+
     // Parse the account first so we don't generate a key if there's an error
     string strAccount = AccountFromValue(params[0]);
 
@@ -496,6 +508,9 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
             "getreceivedbyaccount <account> [minconf=1]\n"
             "Returns the total amount received by addresses with <account> in transactions with at least [minconf] confirmations.");
 
+    // Deprecation check
+    accountingAllowed();
+
     // Minimum confirmations
     int nMinDepth = 1;
     if (params.size() > 1)
@@ -610,6 +625,9 @@ Value getbalance(const Array& params, bool fHelp)
         return  ValueFromAmount(nBalance);
     }
 
+    // Deprecation check
+    accountingAllowed();
+
     string strAccount = AccountFromValue(params[0]);
 
     int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, filter);
@@ -625,6 +643,9 @@ Value movecmd(const Array& params, bool fHelp)
             "move <fromaccount> <toaccount> <amount> [minconf=1] [comment]\n"
             "Move from one account in your wallet to another.");
 
+    // Deprecation check
+    accountingAllowed();
+
     string strFrom = AccountFromValue(params[0]);
     string strTo = AccountFromValue(params[1]);
     int64_t nAmount = AmountFromValue(params[2]);
@@ -680,6 +701,9 @@ Value sendfrom(const Array& params, bool fHelp)
             "<amount> is a real and is rounded to the nearest " + FormatMoney(MIN_TXOUT_AMOUNT)
             + HelpRequiringPassphrase());
 
+    // Deprecation check
+    accountingAllowed();
+
     string strAccount = AccountFromValue(params[0]);
     CBitcoinAddress address(params[1].get_str());
     if (!address.IsValid())
@@ -724,6 +748,9 @@ Value sendmany(const Array& params, bool fHelp)
             "amounts are double-precision floating point numbers"
             + HelpRequiringPassphrase());
 
+    // Deprecation check
+    accountingAllowed();
+
     string strAccount = AccountFromValue(params[0]);
     Object sendTo = params[1].get_obj();
     int nMinDepth = 1;
@@ -763,10 +790,13 @@ Value sendmany(const Array& params, bool fHelp)
 
     EnsureWalletIsUnlocked();
 
-    // Check funds
-    int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, MINE_SPENDABLE);
-    if (totalAmount > nBalance)
-        throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
+    if (GetBoolArg("-accounts", false))
+    {
+        // Check funds
+        int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, MINE_SPENDABLE);
+        if (totalAmount > nBalance)
+            throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
+    }
 
     // Send
     CReserveKey keyChange(pwalletMain);
@@ -1014,6 +1044,9 @@ Value listreceivedbyaccount(const Array& params, bool fHelp)
             "  \"amount\" : total amount received by addresses with this account\n"
             "  \"confirmations\" : number of confirmations of the most recent transaction included");
 
+    // Deprecation check
+    accountingAllowed();
+
     return ListReceived(params, true);
 }
 
@@ -1203,6 +1236,9 @@ Value listaccounts(const Array& params, bool fHelp)
             "listaccounts [minconf=1]\n"
             "Returns Object that has account names as keys, account balances as values.");
 
+    // Deprecation check
+    accountingAllowed();
+
     int nMinDepth = 1;
     if (params.size() > 0)
         nMinDepth = params[0].get_int();
@@ -1410,7 +1446,9 @@ Value keypoolrefill(const Array& params, bool fHelp)
     if (fHelp || params.size() > 1)
         throw runtime_error(
             "keypoolrefill [new-size]\n"
-            "Fills the keypool."
+            "Fills the keypool.\n"
+            "IMPORTANT: Any previous backups you have made of your wallet file "
+            "should be replaced with the newly generated one."
             + HelpRequiringPassphrase());
 
     unsigned int nSize = max<unsigned int>(GetArg("-keypool", 100), 0);
@@ -1430,6 +1468,33 @@ Value keypoolrefill(const Array& params, bool fHelp)
     return Value::null;
 }
 
+Value keypoolreset(const Array& params, bool fHelp)
+{
+    if (fHelp || params.size() > 1)
+        throw runtime_error(
+            "keypoolreset [new-size]\n"
+            "Resets the keypool.\n"
+            "IMPORTANT: Any previous backups you have made of your wallet file "
+            "should be replaced with the newly generated one."
+            + HelpRequiringPassphrase());
+
+    unsigned int nSize = max<unsigned int>(GetArg("-keypool", 100), 0);
+    if (params.size() > 0) {
+        if (params[0].get_int() < 0)
+            throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size");
+        nSize = (unsigned int) params[0].get_int();
+    }
+
+    EnsureWalletIsUnlocked();
+
+    pwalletMain->NewKeyPool(nSize);
+
+    if (pwalletMain->GetKeyPoolSize() < nSize)
+        throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool.");
+
+    return Value::null;
+}
+
 
 void ThreadTopUpKeyPool(void* parg)
 {