From ea4a5e1318276e5b148f2122e0057675c801129f Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Sat, 28 Mar 2015 20:13:54 +0300 Subject: [PATCH] Deprecate accounting API. Accounting API is deprecated and will be removed in future. --- src/rpcwallet.cpp | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 5607a4b..c55296c 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -24,6 +24,15 @@ std::string HelpRequiringPassphrase() : ""; } +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 \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 [minconf=1]\n" "Returns the total amount received by addresses with 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 [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) " 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(); -- 1.7.1