X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Frpcwallet.cpp;h=260cc57a099089f3aec28bcb99f88ee4f3ef8780;hb=0dd25284c30dfdbfeff9a882dd801be8cacd0859;hp=c55296caa20193ab68ea3128bc5f5c839e3d8578;hpb=ea4a5e1318276e5b148f2122e0057675c801129f;p=novacoin.git diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index c55296c..260cc57 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -7,6 +7,8 @@ #include "walletdb.h" #include "bitcoinrpc.h" #include "init.h" +#include "util.h" +#include "ntp.h" #include "base58.h" using namespace json_spirit; @@ -15,7 +17,8 @@ using namespace std; int64_t nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; -extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, json_spirit::Object& entry); +extern int64_t nReserveBalance; +extern void TxToJSON(const CTransaction& tx, const uint256& hashBlock, json_spirit::Object& entry); std::string HelpRequiringPassphrase() { @@ -24,15 +27,6 @@ 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()) @@ -51,11 +45,11 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry) { entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex())); entry.push_back(Pair("blockindex", wtx.nIndex)); - entry.push_back(Pair("blocktime", (boost::int64_t)(mapBlockIndex[wtx.hashBlock]->nTime))); + entry.push_back(Pair("blocktime", (int64_t)(mapBlockIndex[wtx.hashBlock]->nTime))); } entry.push_back(Pair("txid", wtx.GetHash().GetHex())); - entry.push_back(Pair("time", (boost::int64_t)wtx.GetTxTime())); - entry.push_back(Pair("timereceived", (boost::int64_t)wtx.nTimeReceived)); + entry.push_back(Pair("time", (int64_t)wtx.GetTxTime())); + entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived)); BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue) entry.push_back(Pair(item.first, item.second)); } @@ -78,7 +72,7 @@ Value getinfo(const Array& params, bool fHelp) proxyType proxy; GetProxy(NET_IPV4, proxy); - Object obj, diff; + Object obj, diff, timestamping; obj.push_back(Pair("version", FormatFullVersion())); obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION)); obj.push_back(Pair("walletversion", pwalletMain->GetVersion())); @@ -87,7 +81,18 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("newmint", ValueFromAmount(pwalletMain->GetNewMint()))); obj.push_back(Pair("stake", ValueFromAmount(pwalletMain->GetStake()))); obj.push_back(Pair("blocks", (int)nBestHeight)); - obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset())); + + timestamping.push_back(Pair("systemclock", GetTime())); + timestamping.push_back(Pair("adjustedtime", GetAdjustedTime())); + + int64_t nNtpOffset = GetNtpOffset(), + nP2POffset = GetNodesOffset(); + + timestamping.push_back(Pair("ntpoffset", nNtpOffset != INT64_MAX ? nNtpOffset : Value::null)); + timestamping.push_back(Pair("p2poffset", nP2POffset != INT64_MAX ? nP2POffset : Value::null)); + + obj.push_back(Pair("timestamping", timestamping)); + obj.push_back(Pair("moneysupply", ValueFromAmount(pindexBest->nMoneySupply))); obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string()))); @@ -98,12 +103,12 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("difficulty", diff)); obj.push_back(Pair("testnet", fTestNet)); - obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime())); + obj.push_back(Pair("keypoololdest", (int64_t)pwalletMain->GetOldestKeyPoolTime())); obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize())); obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee))); obj.push_back(Pair("mininput", ValueFromAmount(nMinimumInputValue))); if (pwalletMain->IsCrypted()) - obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime / 1000)); + obj.push_back(Pair("unlocked_until", (int64_t)nWalletUnlockTime / 1000)); obj.push_back(Pair("errors", GetWarnings("statusbar"))); return obj; } @@ -182,9 +187,6 @@ 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]); @@ -275,7 +277,7 @@ Value mergecoins(const Array& params, bool fHelp) " is resulting inputs sum\n" " is minimum value of inputs which are used in join process\n" " is resulting value of inputs which will be created\n" - "All values are real and and rounded to the nearest " + FormatMoney(MIN_TXOUT_AMOUNT) + "All values are real and and rounded to the nearest " + FormatMoney(nMinimumInputValue) + HelpRequiringPassphrase()); if (pwalletMain->IsLocked()) @@ -290,13 +292,13 @@ Value mergecoins(const Array& params, bool fHelp) // Output amount int64_t nOutputValue = AmountFromValue(params[2]); - if (nAmount < MIN_TXOUT_AMOUNT) + if (nAmount < nMinimumInputValue) throw JSONRPCError(-101, "Send amount too small"); - if (nMinValue < MIN_TXOUT_AMOUNT) + if (nMinValue < nMinimumInputValue) throw JSONRPCError(-101, "Max value too small"); - if (nOutputValue < MIN_TXOUT_AMOUNT) + if (nOutputValue < nMinimumInputValue) throw JSONRPCError(-101, "Output value too small"); if (nOutputValue < nMinValue) @@ -318,7 +320,7 @@ Value sendtoaddress(const Array& params, bool fHelp) if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( "sendtoaddress [comment] [comment-to]\n" - " is a real and is rounded to the nearest " + FormatMoney(MIN_TXOUT_AMOUNT) + " is a real and is rounded to the nearest " + FormatMoney(nMinimumInputValue) + HelpRequiringPassphrase()); CBitcoinAddress address(params[0].get_str()); @@ -328,7 +330,7 @@ Value sendtoaddress(const Array& params, bool fHelp) // Amount int64_t nAmount = AmountFromValue(params[1]); - if (nAmount < MIN_TXOUT_AMOUNT) + if (nAmount < nMinimumInputValue) throw JSONRPCError(-101, "Send amount too small"); // Wallet comments @@ -508,9 +510,6 @@ 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) @@ -625,9 +624,6 @@ 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); @@ -643,14 +639,11 @@ 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]); - if (nAmount < MIN_TXOUT_AMOUNT) + if (nAmount < nMinimumInputValue) throw JSONRPCError(-101, "Send amount too small"); if (params.size() > 3) @@ -698,19 +691,16 @@ Value sendfrom(const Array& params, bool fHelp) if (fHelp || params.size() < 3 || params.size() > 6) throw runtime_error( "sendfrom [minconf=1] [comment] [comment-to]\n" - " is a real and is rounded to the nearest " + FormatMoney(MIN_TXOUT_AMOUNT) + " is a real and is rounded to the nearest " + FormatMoney(nMinimumInputValue) + HelpRequiringPassphrase()); - // Deprecation check - accountingAllowed(); - string strAccount = AccountFromValue(params[0]); CBitcoinAddress address(params[1].get_str()); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid NovaCoin address"); int64_t nAmount = AmountFromValue(params[2]); - if (nAmount < MIN_TXOUT_AMOUNT) + if (nAmount < nMinimumInputValue) throw JSONRPCError(-101, "Send amount too small"); int nMinDepth = 1; @@ -744,13 +734,10 @@ Value sendmany(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( - "sendmany {address:amount,...} [minconf=1] [comment]\n" + "sendmany '{address:amount,...}' [minconf=1] [comment]\n" "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; @@ -780,7 +767,7 @@ Value sendmany(const Array& params, bool fHelp) scriptPubKey.SetDestination(address.Get()); int64_t nAmount = AmountFromValue(s.value_); - if (nAmount < MIN_TXOUT_AMOUNT) + if (nAmount < nMinimumInputValue) throw JSONRPCError(-101, "Send amount too small"); totalAmount += nAmount; @@ -790,13 +777,10 @@ Value sendmany(const Array& params, bool fHelp) EnsureWalletIsUnlocked(); - 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"); - } + // 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); @@ -1044,9 +1028,6 @@ 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); } @@ -1158,7 +1139,7 @@ void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Ar Object entry; entry.push_back(Pair("account", acentry.strAccount)); entry.push_back(Pair("category", "move")); - entry.push_back(Pair("time", (boost::int64_t)acentry.nTime)); + entry.push_back(Pair("time", (int64_t)acentry.nTime)); entry.push_back(Pair("amount", ValueFromAmount(acentry.nCreditDebit))); entry.push_back(Pair("otheraccount", acentry.strOtherAccount)); entry.push_back(Pair("comment", acentry.strComment)); @@ -1236,9 +1217,6 @@ 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(); @@ -1451,7 +1429,7 @@ Value keypoolrefill(const Array& params, bool fHelp) "should be replaced with the newly generated one." + HelpRequiringPassphrase()); - unsigned int nSize = max(GetArg("-keypool", 100), 0); + unsigned int nSize = max(GetArgUInt("-keypool", 100), 0); if (params.size() > 0) { if (params[0].get_int() < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size"); @@ -1478,7 +1456,7 @@ Value keypoolreset(const Array& params, bool fHelp) "should be replaced with the newly generated one." + HelpRequiringPassphrase()); - unsigned int nSize = max(GetArg("-keypool", 100), 0); + unsigned int nSize = max(GetArgUInt("-keypool", 100), 0); if (params.size() > 0) { if (params[0].get_int() < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size"); @@ -1788,7 +1766,6 @@ Value reservebalance(const Array& params, bool fHelp) } Object result; - int64_t nReserveBalance = 0; if (mapArgs.count("-reservebalance") && !ParseMoney(mapArgs["-reservebalance"], nReserveBalance)) throw runtime_error("invalid reserve balance amount\n"); result.push_back(Pair("reserve", (nReserveBalance > 0)));