X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fbitcoinrpc.cpp;h=d49f89882820abe333ab74aaf0b1fa8c7e14837d;hb=b90c9ecb132ad686275afafe506f8044719245ec;hp=5bc7353f482423d21c26e1da2c9ad4abd31e7f95;hpb=491ad6db507776054c38230387f384991f42ad29;p=novacoin.git diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 5bc7353..d49f898 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2010 Satoshi Nakamoto +// Copyright (c) 2011 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. @@ -342,21 +343,19 @@ Value getnewaddress(const Array& params, bool fHelp) strAccount = AccountFromValue(params[0]); // Generate a new key that is added to wallet - string strAddress = CBitcoinAddress(pwalletMain->GetOrReuseKeyFromPool()).ToString(); + CBitcoinAddress address(pwalletMain->GetOrReuseKeyFromPool()); // This could be done in the same main CS as GetKeyFromKeyPool. CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) - pwalletMain->SetAddressBookName(strAddress, strAccount); + pwalletMain->SetAddressBookName(address, strAccount); - return strAddress; + return address.ToString(); } // requires cs_main, cs_mapWallet, cs_mapAddressBook locks CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false) { - string strAddress; - CWalletDB walletdb(pwalletMain->strWalletFile); CAccount account; @@ -393,8 +392,7 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false) else { account.vchPubKey = pwalletMain->GetOrReuseKeyFromPool(); - string strAddress = CBitcoinAddress(account.vchPubKey).ToString(); - pwalletMain->SetAddressBookName(strAddress, strAccount); + pwalletMain->SetAddressBookName(CBitcoinAddress(account.vchPubKey), strAccount); walletdb.WriteAccount(strAccount, account); } } @@ -434,8 +432,7 @@ Value setaccount(const Array& params, bool fHelp) "setaccount \n" "Sets the account associated with the given address."); - string strAddress = params[0].get_str(); - CBitcoinAddress address(strAddress); + CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) throw JSONRPCError(-5, "Invalid bitcoin address"); @@ -456,7 +453,7 @@ Value setaccount(const Array& params, bool fHelp) GetAccountAddress(strOldAccount, true); } - pwalletMain->SetAddressBookName(strAddress, strAccount); + pwalletMain->SetAddressBookName(address, strAccount); } return Value::null; @@ -470,8 +467,9 @@ Value getaccount(const Array& params, bool fHelp) "getaccount \n" "Returns the account associated with the given address."); - string strAddress = params[0].get_str(); - CBitcoinAddress address(strAddress); + CBitcoinAddress address(params[0].get_str()); + if (!address.IsValid()) + throw JSONRPCError(-5, "Invalid bitcoin address"); string strAccount; CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) @@ -536,7 +534,9 @@ Value sendtoaddress(const Array& params, bool fHelp) "sendtoaddress [comment] [comment-to]\n" " is a real and is rounded to the nearest 0.00000001"); - string strAddress = params[0].get_str(); + CBitcoinAddress address(params[0].get_str()); + if (!address.IsValid()) + throw JSONRPCError(-5, "Invalid bitcoin address"); // Amount int64 nAmount = AmountFromValue(params[1]); @@ -554,7 +554,7 @@ Value sendtoaddress(const Array& params, bool fHelp) if(pwalletMain->IsLocked()) throw JSONRPCError(-14, "Error: The wallet passphrase entered was incorrect."); - string strError = pwalletMain->SendMoneyToBitcoinAddress(strAddress, nAmount, wtx); + string strError = pwalletMain->SendMoneyToBitcoinAddress(address, nAmount, wtx); if (strError != "") throw JSONRPCError(-4, strError); } @@ -807,7 +807,9 @@ Value sendfrom(const Array& params, bool fHelp) " is a real and is rounded to the nearest 0.00000001"); string strAccount = AccountFromValue(params[0]); - string strAddress = params[1].get_str(); + CBitcoinAddress address(params[1].get_str()); + if (!address.IsValid()) + throw JSONRPCError(-5, "Invalid bitcoin address"); int64 nAmount = AmountFromValue(params[2]); int nMinDepth = 1; if (params.size() > 3) @@ -833,7 +835,7 @@ Value sendfrom(const Array& params, bool fHelp) throw JSONRPCError(-6, "Account has insufficient funds"); // Send - string strError = pwalletMain->SendMoneyToBitcoinAddress(strAddress, nAmount, wtx); + string strError = pwalletMain->SendMoneyToBitcoinAddress(address, nAmount, wtx); if (strError != "") throw JSONRPCError(-4, strError); } @@ -1186,7 +1188,8 @@ Value listtransactions(const Array& params, bool fHelp) // Now: iterate backwards until we have nCount items to return: TxItems::reverse_iterator it = txByTime.rbegin(); - for (std::advance(it, nFrom); it != txByTime.rend(); ++it) + if (txByTime.size() > nFrom) std::advance(it, nFrom); + for (; it != txByTime.rend(); ++it) { CWalletTx *const pwtx = (*it).second.first; if (pwtx != 0) @@ -1538,8 +1541,7 @@ Value validateaddress(const Array& params, bool fHelp) "validateaddress \n" "Return information about ."); - string strAddress = params[0].get_str(); - CBitcoinAddress address(strAddress); + CBitcoinAddress address(params[0].get_str()); bool isValid = address.IsValid(); Object ret; @@ -1742,7 +1744,7 @@ string pAllowInSafeMode[] = "getinfo", "getnewaddress", "getaccountaddress", - "setlabel", + "setlabel", // deprecated "getaccount", "getlabel", // deprecated "getaddressesbyaccount", @@ -2373,7 +2375,7 @@ int CommandLineRPC(int argc, char *argv[]) if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo(params[1]); if (strMethod == "getreceivedbylabel" && n > 1) ConvertTo(params[1]); // deprecated if (strMethod == "getallreceived" && n > 0) ConvertTo(params[0]); // deprecated - if (strMethod == "getallreceived" && n > 1) ConvertTo(params[1]); + if (strMethod == "getallreceived" && n > 1) ConvertTo(params[1]); // deprecated if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo(params[0]); if (strMethod == "listreceivedbyaddress" && n > 1) ConvertTo(params[1]); if (strMethod == "listreceivedbyaccount" && n > 0) ConvertTo(params[0]);