X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Frpcwallet.cpp;h=e75fe87e9c5dcc2f6b5e228cfb60503c2ed8376a;hb=fd3e29de89dadb40606f9b5c258b673ba9f24798;hp=5ff8320fd7120c245b197b9b00af6dea16dcc48b;hpb=ebbcbf24322c0d1e5d3e386a1edb0a3b48667ae7;p=novacoin.git diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 5ff8320..e75fe87 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -50,7 +50,7 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry) entry.push_back(Pair("txid", wtx.GetHash().GetHex())); 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) + for (const auto& item : wtx.mapValue) entry.push_back(Pair(item.first, item.second)); } @@ -161,7 +161,7 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false) ++it) { const CWalletTx& wtx = (*it).second; - BOOST_FOREACH(const CTxOut& txout, wtx.vout) + for (const CTxOut& txout : wtx.vout) if (txout.scriptPubKey == scriptPubKey) bKeyUsed = true; } @@ -259,7 +259,7 @@ Value getaddressesbyaccount(const Array& params, bool fHelp) // Find all addresses that have the given account Array ret; - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, string)& item, pwalletMain->mapAddressBook) + for (const auto& item : pwalletMain->mapAddressBook) { const CBitcoinAddress& address = item.first; const string& strName = item.second; @@ -309,7 +309,7 @@ Value mergecoins(const Array& params, bool fHelp) return Value::null; Array mergedHashes; - BOOST_FOREACH(const uint256 txHash, listMerged) + for (const uint256 txHash : listMerged) mergedHashes.push_back(txHash.GetHex()); return mergedHashes; @@ -350,7 +350,7 @@ Value sendtoaddress(const Array& params, bool fHelp) throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx); - if (strError != "") + if (!strError.empty()) throw JSONRPCError(RPC_WALLET_ERROR, strError); return wtx.GetHash().GetHex(); @@ -367,10 +367,10 @@ Value listaddressgroupings(const Array& params, bool fHelp) Array jsonGroupings; map balances = pwalletMain->GetAddressBalances(); - BOOST_FOREACH(set grouping, pwalletMain->GetAddressGroupings()) + for (set grouping : pwalletMain->GetAddressGroupings()) { Array jsonGrouping; - BOOST_FOREACH(CBitcoinAddress address, grouping) + for (CBitcoinAddress address : grouping) { Array addressInfo; addressInfo.push_back(address.ToString()); @@ -451,11 +451,11 @@ Value verifymessage(const Array& params, bool fHelp) ss << strMessageMagic; ss << strMessage; - CKey key; + CPubKey key; if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig)) return false; - return (key.GetPubKey().GetID() == keyID); + return (key.GetID() == keyID); } @@ -484,7 +484,7 @@ Value getreceivedbyaddress(const Array& params, bool fHelp) const CWalletTx& wtx = (*it).second; if (wtx.IsCoinBase() || wtx.IsCoinStake() || !wtx.IsFinal()) continue; - BOOST_FOREACH(const CTxOut& txout, wtx.vout) + for (const CTxOut& txout : wtx.vout) { CBitcoinAddress addressRet; if (!ExtractAddress(*pwalletMain, txout.scriptPubKey, addressRet)) @@ -500,7 +500,7 @@ Value getreceivedbyaddress(const Array& params, bool fHelp) void GetAccountAddresses(string strAccount, set& setAddress) { - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, string)& item, pwalletMain->mapAddressBook) + for (const auto& item : pwalletMain->mapAddressBook) { const CBitcoinAddress& address = item.first; const string& strName = item.second; @@ -534,7 +534,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp) if (wtx.IsCoinBase() || wtx.IsCoinStake() || !wtx.IsFinal()) continue; - BOOST_FOREACH(const CTxOut& txout, wtx.vout) + for (const CTxOut& txout : wtx.vout) { CBitcoinAddress address; if (ExtractAddress(*pwalletMain, txout.scriptPubKey, address) && IsMine(*pwalletMain, address) && setAddress.count(address)) @@ -581,7 +581,7 @@ int64_t GetAccountBalance(const string& strAccount, int nMinDepth, const isminef Value getbalance(const Array& params, bool fHelp) { - if (fHelp || params.size() > 2) + if (fHelp || params.size() > 3) throw runtime_error( "getbalance [account] [minconf=1] [watchonly=0]\n" "If [account] is not specified, returns the server's total available balance.\n" @@ -619,10 +619,10 @@ Value getbalance(const Array& params, bool fHelp) wtx.GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount, filter); if (wtx.GetDepthInMainChain() >= nMinDepth) { - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64_t)& r, listReceived) + for (const auto& r : listReceived) nBalance += r.second; } - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64_t)& r, listSent) + for (const auto& r : listSent) nBalance -= r.second; nBalance -= allFee; nBalance += allGeneratedMature; @@ -704,7 +704,7 @@ Value sendfrom(const Array& params, bool fHelp) // Parse address CScript scriptPubKey; - string strAddress = params[0].get_str(); + string strAddress = params[1].get_str(); CBitcoinAddress address(strAddress); if (address.IsValid()) @@ -738,7 +738,7 @@ Value sendfrom(const Array& params, bool fHelp) // Send string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx); - if (strError != "") + if (!strError.empty()) throw JSONRPCError(RPC_WALLET_ERROR, strError); return wtx.GetHash().GetHex(); @@ -768,7 +768,7 @@ Value sendmany(const Array& params, bool fHelp) vector > vecSend; int64_t totalAmount = 0; - BOOST_FOREACH(const Pair& s, sendTo) + for (const Pair& s : sendTo) { CBitcoinAddress address(s.name_); if (!address.IsValid()) @@ -843,7 +843,7 @@ Value addmultisigaddress(const Array& params, bool fHelp) "(got %" PRIszu " keys, but need at least %d to redeem)", keys.size(), nRequired)); if (keys.size() > 16) throw runtime_error("Number of addresses involved in the multisignature address creation > 16\nReduce the number"); - std::vector pubkeys; + std::vector pubkeys; pubkeys.resize(keys.size()); for (unsigned int i = 0; i < keys.size(); i++) { @@ -861,16 +861,18 @@ Value addmultisigaddress(const Array& params, bool fHelp) if (!pwalletMain->GetPubKey(keyID, vchPubKey)) throw runtime_error( strprintf("no full public key for address %s",ks.c_str())); - if (!vchPubKey.IsValid() || !pubkeys[i].SetPubKey(vchPubKey)) + if (!vchPubKey.IsValid()) throw runtime_error(" Invalid public key: "+ks); + pubkeys[i] = vchPubKey; } // Case 2: hex public key else if (IsHex(ks)) { CPubKey vchPubKey(ParseHex(ks)); - if (!vchPubKey.IsValid() || !pubkeys[i].SetPubKey(vchPubKey)) + if (!vchPubKey.IsValid()) throw runtime_error(" Invalid public key: "+ks); + pubkeys[i] = vchPubKey; } else { @@ -953,7 +955,7 @@ Value ListReceived(const Array& params, bool fByAccounts) if (nDepth < nMinDepth) continue; - BOOST_FOREACH(const CTxOut& txout, wtx.vout) + for (const CTxOut& txout : wtx.vout) { CTxDestination address; if (!ExtractDestination(txout.scriptPubKey, address) || !IsMine(*pwalletMain, address)) @@ -968,7 +970,7 @@ Value ListReceived(const Array& params, bool fByAccounts) // Reply Array ret; map mapAccountTally; - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, string)& item, pwalletMain->mapAddressBook) + for (const auto& item : pwalletMain->mapAddressBook) { const CBitcoinAddress& address = item.first; const string& strAccount = item.second; @@ -1067,7 +1069,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe bool involvesWatchonly = wtx.IsFromMe(MINE_WATCH_ONLY); // Generated blocks assigned to account "" - if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount == "")) + if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount.empty())) { Object entry; entry.push_back(Pair("account", string(""))); @@ -1089,7 +1091,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe // Sent if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount)) { - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, int64_t)& s, listSent) + for (const auto& s : listSent) { Object entry; entry.push_back(Pair("account", strSentAccount)); @@ -1114,7 +1116,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe // Received if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) { - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, int64_t)& r, listReceived) + for (const auto& r : listReceived) { string account; if (pwalletMain->mapAddressBook.count(r.first)) @@ -1244,7 +1246,7 @@ Value listaccounts(const Array& params, bool fHelp) map mapAccountBalances; - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, string)& entry, pwalletMain->mapAddressBook) { + for (const auto& entry : pwalletMain->mapAddressBook) { if (IsMine(*pwalletMain, entry.first)) // This address belongs to me mapAccountBalances[entry.second] = 0; } @@ -1258,12 +1260,12 @@ Value listaccounts(const Array& params, bool fHelp) list > listSent; wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount, includeWatchonly); mapAccountBalances[strSentAccount] -= nFee; - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, int64_t)& s, listSent) + for (const auto& s : listSent) mapAccountBalances[strSentAccount] -= s.second; if (wtx.GetDepthInMainChain() >= nMinDepth) { mapAccountBalances[""] += nGeneratedMature; - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, int64_t)& r, listReceived) + for (const auto& r : listReceived) if (pwalletMain->mapAddressBook.count(r.first)) mapAccountBalances[pwalletMain->mapAddressBook[r.first]] += r.second; else @@ -1273,11 +1275,11 @@ Value listaccounts(const Array& params, bool fHelp) list acentries; CWalletDB(pwalletMain->strWalletFile).ListAccountCreditDebit("*", acentries); - BOOST_FOREACH(const CAccountingEntry& entry, acentries) + for (const CAccountingEntry& entry : acentries) mapAccountBalances[entry.strAccount] += entry.nCreditDebit; Object ret; - BOOST_FOREACH(const PAIRTYPE(string, int64_t)& accountBalance, mapAccountBalances) { + for (const auto& accountBalance : mapAccountBalances) { ret.push_back(Pair(accountBalance.first, ValueFromAmount(accountBalance.second))); } return ret; @@ -1511,7 +1513,7 @@ void ThreadCleanWalletPassphrase(void* parg) { nWalletUnlockTime = nMyWakeTime; - do + for ( ; ; ) { if (nWalletUnlockTime==0) break; @@ -1523,7 +1525,7 @@ void ThreadCleanWalletPassphrase(void* parg) Sleep(nToSleep); ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime); - } while(1); + }; if (nWalletUnlockTime) { @@ -1690,7 +1692,7 @@ public: obj.push_back(Pair("isscript", false)); if (mine == MINE_SPENDABLE) { pwalletMain->GetPubKey(keyID, vchPubKey); - obj.push_back(Pair("pubkey", HexStr(vchPubKey.Raw()))); + obj.push_back(Pair("pubkey", HexStr(vchPubKey.begin(), vchPubKey.end()))); obj.push_back(Pair("iscompressed", vchPubKey.IsCompressed())); } return obj; @@ -1709,7 +1711,7 @@ public: obj.push_back(Pair("script", GetTxnOutputType(whichType))); obj.push_back(Pair("hex", HexStr(subscript.begin(), subscript.end()))); Array a; - BOOST_FOREACH(const CTxDestination& addr, addresses) + for (const CTxDestination& addr : addresses) a.push_back(CBitcoinAddress(addr).ToString()); obj.push_back(Pair("addresses", a)); if (whichType == TX_MULTISIG) @@ -1742,6 +1744,7 @@ Value validateaddress(const Array& params, bool fHelp) CMalleableKeyView view; bool isMine = pwalletMain->GetMalleableView(mpk, view); ret.push_back(Pair("ismine", isMine)); + ret.push_back(Pair("PubkeyPair", mpk.ToString())); if (isMine) ret.push_back(Pair("KeyView", view.ToString())); @@ -1755,7 +1758,7 @@ Value validateaddress(const Array& params, bool fHelp) ret.push_back(Pair("ismine", mine != MINE_NO)); if (mine != MINE_NO) { ret.push_back(Pair("watchonly", mine == MINE_WATCH_ONLY)); - Object detail = boost::apply_visitor(DescribeAddressVisitor(mine), dest); + Object detail = std::visit(DescribeAddressVisitor(mine), dest); ret.insert(ret.end(), detail.begin(), detail.end()); } if (pwalletMain->mapAddressBook.count(address)) @@ -1865,6 +1868,29 @@ Value resendtx(const Array& params, bool fHelp) return Value::null; } +Value resendwallettransactions(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "resendwallettransactions\n" + "Immediately re-broadcast unconfirmed wallet transactions to all peers.\n" + "Intended only for testing; the wallet code periodically re-broadcasts\n" + "automatically.\n" + "Returns array of transaction ids that were re-broadcast.\n" + ); + + LOCK2(cs_main, pwalletMain->cs_wallet); + + std::vector txids = pwalletMain->ResendWalletTransactionsBefore(GetTime()); + Array result; + for (const uint256& txid : txids) + { + result.push_back(txid.ToString()); + } + return result; +} + + // Make a public-private key pair Value makekeypair(const Array& params, bool fHelp) { @@ -1886,8 +1912,9 @@ Value makekeypair(const Array& params, bool fHelp) bool fCompressed; CSecret vchSecret = key.GetSecret(fCompressed); + CPubKey vchPubKey = key.GetPubKey(); result.push_back(Pair("Secret", HexStr(vchSecret.begin(), vchSecret.end()))); - result.push_back(Pair("PublicKey", HexStr(key.GetPubKey().Raw()))); + result.push_back(Pair("PublicKey", HexStr(vchPubKey.begin(), vchPubKey.end()))); return result; } @@ -1955,23 +1982,41 @@ Value adjustmalleablepubkey(const Array& params, bool fHelp) { if (fHelp || params.size() > 2 || params.size() == 0) throw runtime_error( - "adjustmalleablepubkey \n" - "Calculate new public key using provided malleable public key data.\n"); + "adjustmalleablepubkey \n" + "Calculate new public key using provided data.\n"); - string pubKeyPair = params[0].get_str(); + string strData = params[0].get_str(); CMalleablePubKey malleablePubKey; - if (pubKeyPair.size() == 136) { - malleablePubKey.setvch(ParseHex(pubKeyPair)); - } else - malleablePubKey.SetString(pubKeyPair); + do + { + CBitcoinAddress addr(strData); + if (addr.IsValid() && addr.IsPair()) + { + // Initialize malleable pubkey with address data + malleablePubKey = CMalleablePubKey(addr.GetData()); + break; + } + CMalleableKeyView viewTmp(strData); + if (viewTmp.IsValid()) + { + // Shazaam, we have a valid key view here. + malleablePubKey = viewTmp.GetMalleablePubKey(); + break; + } + if (malleablePubKey.SetString(strData)) + break; // A valid public key pair + + throw runtime_error("Though your data seems a valid Base58 string, we were unable to recognize it."); + } + while(false); CPubKey R, vchPubKeyVariant; malleablePubKey.GetVariant(R, vchPubKeyVariant); Object result; - result.push_back(Pair("R", HexStr(R.Raw()))); - result.push_back(Pair("PubkeyVariant", HexStr(vchPubKeyVariant.Raw()))); + result.push_back(Pair("R", HexStr(R.begin(), R.end()))); + result.push_back(Pair("PubkeyVariant", HexStr(vchPubKeyVariant.begin(), vchPubKeyVariant.end()))); result.push_back(Pair("KeyVariantID", CBitcoinAddress(vchPubKeyVariant.GetID()).ToString())); return result; @@ -1988,7 +2033,7 @@ Value listmalleableviews(const Array& params, bool fHelp) pwalletMain->ListMalleableViews(keyViewList); Array result; - BOOST_FOREACH(const CMalleableKeyView &keyView, keyViewList) + for (const CMalleableKeyView &keyView : keyViewList) { result.push_back(keyView.ToString()); }