From fd61d6f5068cf92d34569862b4225f177049a4f0 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 14 May 2012 19:07:52 +0200 Subject: Encapsulate public keys in CPubKey --- src/bitcoinrpc.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/bitcoinrpc.cpp') diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 8f4fb93a5..f227e363c 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -590,7 +590,7 @@ Value getnewaddress(const Array& params, bool fHelp) pwalletMain->TopUpKeyPool(); // Generate a new key that is added to wallet - std::vector newKey; + CPubKey newKey; if (!pwalletMain->GetKeyFromPool(newKey, false)) throw JSONRPCError(-12, "Error: Keypool ran out, please call keypoolrefill first"); CBitcoinAddress address(newKey); @@ -611,12 +611,12 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false) bool bKeyUsed = false; // Check if the current key has been used - if (!account.vchPubKey.empty()) + if (account.vchPubKey.IsValid()) { CScript scriptPubKey; scriptPubKey.SetBitcoinAddress(account.vchPubKey); for (map::iterator it = pwalletMain->mapWallet.begin(); - it != pwalletMain->mapWallet.end() && !account.vchPubKey.empty(); + it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid(); ++it) { const CWalletTx& wtx = (*it).second; @@ -627,7 +627,7 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false) } // Generate a new key - if (account.vchPubKey.empty() || bForceNew || bKeyUsed) + if (!account.vchPubKey.IsValid() || bForceNew || bKeyUsed) { if (!pwalletMain->GetKeyFromPool(account.vchPubKey, false)) throw JSONRPCError(-12, "Error: Keypool ran out, please call keypoolrefill first"); @@ -1203,19 +1203,19 @@ Value addmultisigaddress(const Array& params, bool fHelp) if (address.IsScript()) throw runtime_error( strprintf("%s is a pay-to-script address",ks.c_str())); - std::vector vchPubKey; + CPubKey vchPubKey; if (!pwalletMain->GetPubKey(address, vchPubKey)) throw runtime_error( strprintf("no full public key for address %s",ks.c_str())); - if (vchPubKey.empty() || !pubkeys[i].SetPubKey(vchPubKey)) + if (!vchPubKey.IsValid() || !pubkeys[i].SetPubKey(vchPubKey)) throw runtime_error(" Invalid public key: "+ks); } // Case 2: hex public key else if (IsHex(ks)) { - vector vchPubKey = ParseHex(ks); - if (vchPubKey.empty() || !pubkeys[i].SetPubKey(vchPubKey)) + CPubKey vchPubKey(ParseHex(ks)); + if (!vchPubKey.IsValid() || !pubkeys[i].SetPubKey(vchPubKey)) throw runtime_error(" Invalid public key: "+ks); } else @@ -1954,9 +1954,9 @@ Value validateaddress(const Array& params, bool fHelp) if (pwalletMain->HaveKey(address)) { ret.push_back(Pair("ismine", true)); - std::vector vchPubKey; + CPubKey vchPubKey; pwalletMain->GetPubKey(address, vchPubKey); - ret.push_back(Pair("pubkey", HexStr(vchPubKey))); + ret.push_back(Pair("pubkey", HexStr(vchPubKey.Raw()))); CKey key; key.SetPubKey(vchPubKey); ret.push_back(Pair("iscompressed", key.IsCompressed())); -- cgit v1.2.3 From 1025440184ef100a22d07c7bb543ee45cf169d64 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 14 May 2012 23:44:52 +0200 Subject: Refactor: split CKeyID/CScriptID/CTxDestination from CBitcoinAddress This introduces internal types: * CKeyID: reference (hash160) of a key * CScriptID: reference (hash160) of a script * CTxDestination: a boost::variant of the former two CBitcoinAddress is retrofitted to be a Base58 encoding of a CTxDestination. This allows all internal code to only use the internal types, and only have RPC and GUI depend on the base58 code. Furthermore, the header dependencies are a lot saner now. base58.h is at the top (right below rpc and gui) instead of at the bottom. For the rest: wallet -> script -> keystore -> key. Only keystore still requires a forward declaration of CScript. Solving that would require splitting script into two layers. --- src/bitcoinrpc.cpp | 199 ++++++++++++++++++++++++++++------------------------- 1 file changed, 106 insertions(+), 93 deletions(-) (limited to 'src/bitcoinrpc.cpp') diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index f227e363c..75e3fd6e9 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -10,6 +10,7 @@ #include "net.h" #include "init.h" #include "ui_interface.h" +#include "base58.h" #include "bitcoinrpc.h" #undef printf @@ -184,10 +185,10 @@ ScriptSigToJSON(const CTxIn& txin, Object& out) return; txnouttype type; - vector addresses; + vector addresses; int nRequired; - if (!ExtractAddresses(txprev.vout[txin.prevout.n].scriptPubKey, type, + if (!ExtractDestinations(txprev.vout[txin.prevout.n].scriptPubKey, type, addresses, nRequired)) { out.push_back(Pair("type", GetTxnOutputType(TX_NONSTANDARD))); @@ -202,8 +203,8 @@ ScriptSigToJSON(const CTxIn& txin, Object& out) } Array a; - BOOST_FOREACH(const CBitcoinAddress& addr, addresses) - a.push_back(addr.ToString()); + BOOST_FOREACH(const CTxDestination& addr, addresses) + a.push_back(CBitcoinAddress(addr).ToString()); out.push_back(Pair("addresses", a)); } @@ -211,13 +212,13 @@ void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out) { txnouttype type; - vector addresses; + vector addresses; int nRequired; out.push_back(Pair("asm", scriptPubKey.ToString())); out.push_back(Pair("hex", HexStr(scriptPubKey.begin(), scriptPubKey.end()))); - if (!ExtractAddresses(scriptPubKey, type, addresses, nRequired)) + if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) { out.push_back(Pair("type", GetTxnOutputType(TX_NONSTANDARD))); return; @@ -227,8 +228,8 @@ ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out) out.push_back(Pair("type", GetTxnOutputType(type))); Array a; - BOOST_FOREACH(const CBitcoinAddress& addr, addresses) - a.push_back(addr.ToString()); + BOOST_FOREACH(const CTxDestination& addr, addresses) + a.push_back(CBitcoinAddress(addr).ToString()); out.push_back(Pair("addresses", a)); } @@ -593,11 +594,11 @@ Value getnewaddress(const Array& params, bool fHelp) CPubKey newKey; if (!pwalletMain->GetKeyFromPool(newKey, false)) throw JSONRPCError(-12, "Error: Keypool ran out, please call keypoolrefill first"); - CBitcoinAddress address(newKey); + CKeyID keyID = newKey.GetID(); - pwalletMain->SetAddressBookName(address, strAccount); + pwalletMain->SetAddressBookName(keyID, strAccount); - return address.ToString(); + return CBitcoinAddress(keyID).ToString(); } @@ -614,7 +615,7 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false) if (account.vchPubKey.IsValid()) { CScript scriptPubKey; - scriptPubKey.SetBitcoinAddress(account.vchPubKey); + scriptPubKey.SetDestination(account.vchPubKey.GetID()); for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid(); ++it) @@ -632,11 +633,11 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false) if (!pwalletMain->GetKeyFromPool(account.vchPubKey, false)) throw JSONRPCError(-12, "Error: Keypool ran out, please call keypoolrefill first"); - pwalletMain->SetAddressBookName(CBitcoinAddress(account.vchPubKey), strAccount); + pwalletMain->SetAddressBookName(account.vchPubKey.GetID(), strAccount); walletdb.WriteAccount(strAccount, account); } - return CBitcoinAddress(account.vchPubKey); + return CBitcoinAddress(account.vchPubKey.GetID()); } Value getaccountaddress(const Array& params, bool fHelp) @@ -675,14 +676,14 @@ Value setaccount(const Array& params, bool fHelp) strAccount = AccountFromValue(params[1]); // Detect when changing the account of an address that is the 'unused current key' of another account: - if (pwalletMain->mapAddressBook.count(address)) + if (pwalletMain->mapAddressBook.count(address.Get())) { - string strOldAccount = pwalletMain->mapAddressBook[address]; + string strOldAccount = pwalletMain->mapAddressBook[address.Get()]; if (address == GetAccountAddress(strOldAccount)) GetAccountAddress(strOldAccount, true); } - pwalletMain->SetAddressBookName(address, strAccount); + pwalletMain->SetAddressBookName(address.Get(), strAccount); return Value::null; } @@ -700,7 +701,7 @@ Value getaccount(const Array& params, bool fHelp) throw JSONRPCError(-5, "Invalid Bitcoin address"); string strAccount; - map::iterator mi = pwalletMain->mapAddressBook.find(address); + map::iterator mi = pwalletMain->mapAddressBook.find(address.Get()); if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.empty()) strAccount = (*mi).second; return strAccount; @@ -769,7 +770,7 @@ Value sendtoaddress(const Array& params, bool fHelp) if (pwalletMain->IsLocked()) throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first."); - string strError = pwalletMain->SendMoneyToBitcoinAddress(address, nAmount, wtx); + string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx); if (strError != "") throw JSONRPCError(-4, strError); @@ -792,8 +793,12 @@ Value signmessage(const Array& params, bool fHelp) if (!addr.IsValid()) throw JSONRPCError(-3, "Invalid address"); + CKeyID keyID; + if (!addr.GetKeyID(keyID)) + throw JSONRPCError(-3, "Address does not refer to key"); + CKey key; - if (!pwalletMain->GetKey(addr, key)) + if (!pwalletMain->GetKey(keyID, key)) throw JSONRPCError(-4, "Private key not available"); CDataStream ss(SER_GETHASH, 0); @@ -822,6 +827,10 @@ Value verifymessage(const Array& params, bool fHelp) if (!addr.IsValid()) throw JSONRPCError(-3, "Invalid address"); + CKeyID keyID; + if (!addr.GetKeyID(keyID)) + throw JSONRPCError(-3, "Address does not refer to key"); + bool fInvalid = false; vector vchSig = DecodeBase64(strSign.c_str(), &fInvalid); @@ -836,7 +845,7 @@ Value verifymessage(const Array& params, bool fHelp) if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig)) return false; - return (CBitcoinAddress(key.GetPubKey()) == addr); + return (key.GetPubKey().GetID() == keyID); } @@ -852,7 +861,7 @@ Value getreceivedbyaddress(const Array& params, bool fHelp) CScript scriptPubKey; if (!address.IsValid()) throw JSONRPCError(-5, "Invalid Bitcoin address"); - scriptPubKey.SetBitcoinAddress(address); + scriptPubKey.SetDestination(address.Get()); if (!IsMine(*pwalletMain,scriptPubKey)) return (double)0.0; @@ -879,18 +888,17 @@ Value getreceivedbyaddress(const Array& params, bool fHelp) } -void GetAccountAddresses(string strAccount, set& setAddress) +void GetAccountAddresses(string strAccount, set& setAddress) { - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, string)& item, pwalletMain->mapAddressBook) + BOOST_FOREACH(const PAIRTYPE(CTxDestination, string)& item, pwalletMain->mapAddressBook) { - const CBitcoinAddress& address = item.first; + const CTxDestination& address = item.first; const string& strName = item.second; if (strName == strAccount) setAddress.insert(address); } } - Value getreceivedbyaccount(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) @@ -905,7 +913,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp) // Get the set of pub keys assigned to account string strAccount = AccountFromValue(params[0]); - set setAddress; + set setAddress; GetAccountAddresses(strAccount, setAddress); // Tally @@ -918,8 +926,8 @@ Value getreceivedbyaccount(const Array& params, bool fHelp) BOOST_FOREACH(const CTxOut& txout, wtx.vout) { - CBitcoinAddress address; - if (ExtractAddress(txout.scriptPubKey, address) && pwalletMain->HaveKey(address) && setAddress.count(address)) + CTxDestination address; + if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*pwalletMain, address) && setAddress.count(address)) if (wtx.GetDepthInMainChain() >= nMinDepth) nAmount += txout.nValue; } @@ -990,15 +998,15 @@ Value getbalance(const Array& params, bool fHelp) int64 allGeneratedImmature, allGeneratedMature, allFee; allGeneratedImmature = allGeneratedMature = allFee = 0; string strSentAccount; - list > listReceived; - list > listSent; + list > listReceived; + list > listSent; wtx.GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount); if (wtx.GetDepthInMainChain() >= nMinDepth) { - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64)& r, listReceived) + BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& r, listReceived) nBalance += r.second; } - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64)& r, listSent) + BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& r, listSent) nBalance -= r.second; nBalance -= allFee; nBalance += allGeneratedMature; @@ -1094,7 +1102,7 @@ Value sendfrom(const Array& params, bool fHelp) throw JSONRPCError(-6, "Account has insufficient funds"); // Send - string strError = pwalletMain->SendMoneyToBitcoinAddress(address, nAmount, wtx); + string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx); if (strError != "") throw JSONRPCError(-4, strError); @@ -1136,7 +1144,7 @@ Value sendmany(const Array& params, bool fHelp) setAddress.insert(address); CScript scriptPubKey; - scriptPubKey.SetBitcoinAddress(address); + scriptPubKey.SetDestination(address.Get()); int64 nAmount = AmountFromValue(s.value_); totalAmount += nAmount; @@ -1200,11 +1208,12 @@ Value addmultisigaddress(const Array& params, bool fHelp) CBitcoinAddress address(ks); if (address.IsValid()) { - if (address.IsScript()) + CKeyID keyID; + if (!address.GetKeyID(keyID)) throw runtime_error( - strprintf("%s is a pay-to-script address",ks.c_str())); + strprintf("%s does not refer to a key",ks.c_str())); CPubKey vchPubKey; - if (!pwalletMain->GetPubKey(address, vchPubKey)) + 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)) @@ -1227,16 +1236,11 @@ Value addmultisigaddress(const Array& params, bool fHelp) // Construct using pay-to-script-hash: CScript inner; inner.SetMultisig(nRequired, pubkeys); - - uint160 scriptHash = Hash160(inner); - CScript scriptPubKey; - scriptPubKey.SetPayToScriptHash(inner); + CScriptID innerID = inner.GetID(); pwalletMain->AddCScript(inner); - CBitcoinAddress address; - address.SetScriptHash160(scriptHash); - pwalletMain->SetAddressBookName(address, strAccount); - return address.ToString(); + pwalletMain->SetAddressBookName(innerID, strAccount); + return CBitcoinAddress(innerID).ToString(); } @@ -1278,8 +1282,8 @@ Value ListReceived(const Array& params, bool fByAccounts) BOOST_FOREACH(const CTxOut& txout, wtx.vout) { - CBitcoinAddress address; - if (!ExtractAddress(txout.scriptPubKey, address) || !pwalletMain->HaveKey(address) || !address.IsValid()) + CTxDestination address; + if (!ExtractDestination(txout.scriptPubKey, address) || !IsMine(*pwalletMain, address)) continue; tallyitem& item = mapTally[address]; @@ -1376,8 +1380,8 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe { int64 nGeneratedImmature, nGeneratedMature, nFee; string strSentAccount; - list > listReceived; - list > listSent; + list > listReceived; + list > listSent; wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount); @@ -1406,11 +1410,11 @@ 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)& s, listSent) + BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& s, listSent) { Object entry; entry.push_back(Pair("account", strSentAccount)); - entry.push_back(Pair("address", s.first.ToString())); + entry.push_back(Pair("address", CBitcoinAddress(s.first).ToString())); entry.push_back(Pair("category", "send")); entry.push_back(Pair("amount", ValueFromAmount(-s.second))); entry.push_back(Pair("fee", ValueFromAmount(-nFee))); @@ -1423,7 +1427,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)& r, listReceived) + BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& r, listReceived) { string account; if (pwalletMain->mapAddressBook.count(r.first)) @@ -1432,7 +1436,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe { Object entry; entry.push_back(Pair("account", account)); - entry.push_back(Pair("address", r.first.ToString())); + entry.push_back(Pair("address", CBitcoinAddress(r.first).ToString())); entry.push_back(Pair("category", "receive")); entry.push_back(Pair("amount", ValueFromAmount(r.second))); if (fLong) @@ -1547,8 +1551,8 @@ Value listaccounts(const Array& params, bool fHelp) nMinDepth = params[0].get_int(); map mapAccountBalances; - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, string)& entry, pwalletMain->mapAddressBook) { - if (pwalletMain->HaveKey(entry.first)) // This address belongs to me + BOOST_FOREACH(const PAIRTYPE(CTxDestination, string)& entry, pwalletMain->mapAddressBook) { + if (IsMine(*pwalletMain, entry.first)) // This address belongs to me mapAccountBalances[entry.second] = 0; } @@ -1557,16 +1561,16 @@ Value listaccounts(const Array& params, bool fHelp) const CWalletTx& wtx = (*it).second; int64 nGeneratedImmature, nGeneratedMature, nFee; string strSentAccount; - list > listReceived; - list > listSent; + list > listReceived; + list > listSent; wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount); mapAccountBalances[strSentAccount] -= nFee; - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, int64)& s, listSent) + BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& s, listSent) mapAccountBalances[strSentAccount] -= s.second; if (wtx.GetDepthInMainChain() >= nMinDepth) { mapAccountBalances[""] += nGeneratedMature; - BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, int64)& r, listReceived) + BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& r, listReceived) if (pwalletMain->mapAddressBook.count(r.first)) mapAccountBalances[pwalletMain->mapAddressBook[r.first]] += r.second; else @@ -1932,6 +1936,40 @@ Value encryptwallet(const Array& params, bool fHelp) return "wallet encrypted; Bitcoin server stopping, restart to run with encrypted wallet"; } +class DescribeAddressVisitor : public boost::static_visitor +{ +public: + Object operator()(const CNoDestination &dest) const { return Object(); } + + Object operator()(const CKeyID &keyID) const { + Object obj; + CPubKey vchPubKey; + pwalletMain->GetPubKey(keyID, vchPubKey); + obj.push_back(Pair("isscript", false)); + obj.push_back(Pair("pubkey", HexStr(vchPubKey.Raw()))); + obj.push_back(Pair("iscompressed", vchPubKey.IsCompressed())); + return obj; + } + + Object operator()(const CScriptID &scriptID) const { + Object obj; + obj.push_back(Pair("isscript", true)); + CScript subscript; + pwalletMain->GetCScript(scriptID, subscript); + std::vector addresses; + txnouttype whichType; + int nRequired; + ExtractDestinations(subscript, whichType, addresses, nRequired); + obj.push_back(Pair("script", GetTxnOutputType(whichType))); + Array a; + BOOST_FOREACH(const CTxDestination& addr, addresses) + a.push_back(CBitcoinAddress(addr).ToString()); + obj.push_back(Pair("addresses", a)); + if (whichType == TX_MULTISIG) + obj.push_back(Pair("sigsrequired", nRequired)); + return obj; + } +}; Value validateaddress(const Array& params, bool fHelp) { @@ -1947,42 +1985,17 @@ Value validateaddress(const Array& params, bool fHelp) ret.push_back(Pair("isvalid", isValid)); if (isValid) { - // Call Hash160ToAddress() so we always return current ADDRESSVERSION - // version of the address: + CTxDestination dest = address.Get(); string currentAddress = address.ToString(); ret.push_back(Pair("address", currentAddress)); - if (pwalletMain->HaveKey(address)) - { - ret.push_back(Pair("ismine", true)); - CPubKey vchPubKey; - pwalletMain->GetPubKey(address, vchPubKey); - ret.push_back(Pair("pubkey", HexStr(vchPubKey.Raw()))); - CKey key; - key.SetPubKey(vchPubKey); - ret.push_back(Pair("iscompressed", key.IsCompressed())); - } - else if (pwalletMain->HaveCScript(address.GetHash160())) - { - ret.push_back(Pair("isscript", true)); - CScript subscript; - pwalletMain->GetCScript(address.GetHash160(), subscript); - ret.push_back(Pair("ismine", ::IsMine(*pwalletMain, subscript))); - std::vector addresses; - txnouttype whichType; - int nRequired; - ExtractAddresses(subscript, whichType, addresses, nRequired); - ret.push_back(Pair("script", GetTxnOutputType(whichType))); - Array a; - BOOST_FOREACH(const CBitcoinAddress& addr, addresses) - a.push_back(addr.ToString()); - ret.push_back(Pair("addresses", a)); - if (whichType == TX_MULTISIG) - ret.push_back(Pair("sigsrequired", nRequired)); + bool fMine = IsMine(*pwalletMain, dest); + ret.push_back(Pair("ismine", fMine)); + if (fMine) { + Object detail = boost::apply_visitor(DescribeAddressVisitor(), dest); + ret.insert(ret.end(), detail.begin(), detail.end()); } - else - ret.push_back(Pair("ismine", false)); - if (pwalletMain->mapAddressBook.count(address)) - ret.push_back(Pair("account", pwalletMain->mapAddressBook[address])); + if (pwalletMain->mapAddressBook.count(dest)) + ret.push_back(Pair("account", pwalletMain->mapAddressBook[dest])); } return ret; } -- cgit v1.2.3 From 587f929c6462698a674fe8add2f301161219d05a Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Thu, 24 May 2012 19:02:21 +0200 Subject: Rework network config settings --- src/bitcoinrpc.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/bitcoinrpc.cpp') diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 75e3fd6e9..e31022d82 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -531,6 +531,9 @@ Value getinfo(const Array& params, bool fHelp) "getinfo\n" "Returns an object containing various state info."); + CService addrProxy; + GetProxy(NET_IPV4, addrProxy); + Object obj; obj.push_back(Pair("version", (int)CLIENT_VERSION)); obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION)); @@ -538,7 +541,7 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance()))); obj.push_back(Pair("blocks", (int)nBestHeight)); obj.push_back(Pair("connections", (int)vNodes.size())); - obj.push_back(Pair("proxy", (fUseProxy ? addrProxy.ToStringIPPort() : string()))); + obj.push_back(Pair("proxy", (addrProxy.IsValid() ? addrProxy.ToStringIPPort() : string()))); obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("testnet", fTestNet)); obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime())); -- cgit v1.2.3 From ea7582bb41416e112d79a2ae43a8c28c695faa8d Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Thu, 31 May 2012 16:05:07 -0400 Subject: Make sendrawtx return txid to be consistent with other send methods. --- src/bitcoinrpc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bitcoinrpc.cpp') diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 75e3fd6e9..f582ff97e 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -2261,7 +2261,7 @@ Value sendrawtx(const Array& params, bool fHelp) CInv inv(MSG_TX, tx.GetHash()); RelayInventory(inv); - return true; + return tx.GetHash().GetHex(); } -- cgit v1.2.3 From 98474d3d6f07ff03f25f59f2016baf1f1385fbed Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Thu, 31 May 2012 16:09:31 -0400 Subject: Use ConvertTo to simplify sendmany/addmultisigaddress argument handling --- src/bitcoinrpc.cpp | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'src/bitcoinrpc.cpp') diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index f582ff97e..1e32f055b 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -2989,24 +2989,11 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 0) ConvertTo(params[0]); if (strMethod == "walletpassphrase" && n > 1) ConvertTo(params[1]); if (strMethod == "listsinceblock" && n > 1) ConvertTo(params[1]); - if (strMethod == "sendmany" && n > 1) - { - string s = params[1].get_str(); - Value v; - if (!read_string(s, v) || v.type() != obj_type) - throw runtime_error("type mismatch"); - params[1] = v.get_obj(); - } - if (strMethod == "sendmany" && n > 2) ConvertTo(params[2]); - if (strMethod == "addmultisigaddress" && n > 0) ConvertTo(params[0]); - if (strMethod == "addmultisigaddress" && n > 1) - { - string s = params[1].get_str(); - Value v; - if (!read_string(s, v) || v.type() != array_type) - throw runtime_error("type mismatch "+s); - params[1] = v.get_array(); - } + if (strMethod == "sendmany" && n > 1) ConvertTo(params[1]); + if (strMethod == "sendmany" && n > 2) ConvertTo(params[2]); + if (strMethod == "addmultisigaddress" && n > 0) ConvertTo(params[0]); + if (strMethod == "addmultisigaddress" && n > 1) ConvertTo(params[1]); + return params; } -- cgit v1.2.3 From 9247134eaba9a1d0fa74f22de238af1476663005 Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Mon, 11 Jun 2012 07:40:14 +0200 Subject: introduce a new StartShutdown() function, which starts a thread with Shutdown() if no GUI is used and calls uiInterface.QueueShutdown() if a GUI is used / all direct uiInterface.QueueShutdown() calls are replaced with Shutdown() - this ensures a clean GUI shutdown, even when catching a SIGTERM and allows the BitcoinGUI destructor to get called (which fixes a tray-icon issue and keeps the tray-icon until Bitcoin-Qt exits) --- src/bitcoinrpc.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/bitcoinrpc.cpp') diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 999c6dda0..8c3a615fd 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include typedef boost::asio::ssl::stream SSLStream; @@ -436,7 +436,7 @@ Value stop(const Array& params, bool fHelp) "stop\n" "Stop Bitcoin server."); // Shutdown will take long enough that the response should get back - uiInterface.QueueShutdown(); + StartShutdown(); return "Bitcoin server stopping"; } @@ -1148,7 +1148,7 @@ Value sendmany(const Array& params, bool fHelp) CScript scriptPubKey; scriptPubKey.SetDestination(address.Get()); - int64 nAmount = AmountFromValue(s.value_); + int64 nAmount = AmountFromValue(s.value_); totalAmount += nAmount; vecSend.push_back(make_pair(scriptPubKey, nAmount)); @@ -1524,7 +1524,7 @@ Value listtransactions(const Array& params, bool fHelp) if ((int)ret.size() >= (nCount+nFrom)) break; } // ret is newest to oldest - + if (nFrom > (int)ret.size()) nFrom = ret.size(); if ((nFrom + nCount) > (int)ret.size()) @@ -1935,7 +1935,7 @@ Value encryptwallet(const Array& params, bool fHelp) // BDB seems to have a bad habit of writing old data into // slack space in .dat files; that is bad if the old data is // unencrypted private keys. So: - uiInterface.QueueShutdown(); + StartShutdown(); return "wallet encrypted; Bitcoin server stopping, restart to run with encrypted wallet"; } @@ -2682,7 +2682,7 @@ void ThreadRPCServer2(void* parg) GetConfigFile().string().c_str(), EncodeBase58(&rand_pwd[0],&rand_pwd[0]+32).c_str()), _("Error"), CClientUIInterface::OK | CClientUIInterface::MODAL); - uiInterface.QueueShutdown(); + StartShutdown(); return; } @@ -2703,7 +2703,7 @@ void ThreadRPCServer2(void* parg) { uiInterface.ThreadSafeMessageBox(strprintf(_("An error occured while setting up the RPC port %i for listening: %s"), endpoint.port(), e.what()), _("Error"), CClientUIInterface::OK | CClientUIInterface::MODAL); - uiInterface.QueueShutdown(); + StartShutdown(); return; } -- cgit v1.2.3