diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2011-12-22 15:51:44 -0500 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2011-12-22 15:57:31 -0500 |
commit | 2e17ac83c65b65fe2037b8c8941c25e288905903 (patch) | |
tree | 143d73d45bae5e0046ac994a3432f4353d9c0382 | |
parent | ce336fdc21c25c055ffef28fbe7c61164df7ca24 (diff) |
Fix broken ExtractAddress (refactored, made callers check for addresses in keystore if they care)
-rw-r--r-- | src/bitcoinrpc.cpp | 8 | ||||
-rw-r--r-- | src/qt/transactiondesc.cpp | 6 | ||||
-rw-r--r-- | src/qt/transactionrecord.cpp | 4 | ||||
-rw-r--r-- | src/script.cpp | 4 | ||||
-rw-r--r-- | src/script.h | 4 | ||||
-rw-r--r-- | src/test/multisig_tests.cpp | 8 | ||||
-rw-r--r-- | src/wallet.cpp | 4 |
7 files changed, 20 insertions, 18 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index bed90d4f6c..c1e8ef7690 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -689,7 +689,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp) BOOST_FOREACH(const CTxOut& txout, wtx.vout) { CBitcoinAddress address; - if (ExtractAddress(txout.scriptPubKey, pwalletMain, address) && setAddress.count(address)) + if (ExtractAddress(txout.scriptPubKey, address) && pwalletMain->HaveKey(address) && setAddress.count(address)) if (wtx.GetDepthInMainChain() >= nMinDepth) nAmount += txout.nValue; } @@ -1033,6 +1033,7 @@ Value ListReceived(const Array& params, bool fByAccounts) for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; + if (wtx.IsCoinBase() || !wtx.IsFinal()) continue; @@ -1043,7 +1044,7 @@ Value ListReceived(const Array& params, bool fByAccounts) BOOST_FOREACH(const CTxOut& txout, wtx.vout) { CBitcoinAddress address; - if (!ExtractAddress(txout.scriptPubKey, pwalletMain, address) || !address.IsValid()) + if (!ExtractAddress(txout.scriptPubKey, address) || !pwalletMain->HaveKey(address) || !address.IsValid()) continue; tallyitem& item = mapTally[address]; @@ -1142,6 +1143,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe string strSentAccount; list<pair<CBitcoinAddress, int64> > listReceived; list<pair<CBitcoinAddress, int64> > listSent; + wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount); bool fAllAccounts = (strAccount == string("*")); @@ -1682,7 +1684,7 @@ Value validateaddress(const Array& params, bool fHelp) std::vector<CBitcoinAddress> addresses; txnouttype whichType; int nRequired; - ExtractAddresses(subscript, pwalletMain, whichType, addresses, nRequired); + ExtractAddresses(subscript, whichType, addresses, nRequired); ret.push_back(Pair("script", GetTxnOutputType(whichType))); Array a; BOOST_FOREACH(const CBitcoinAddress& addr, addresses) diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 6ca3ac8c4b..821ef98131 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -99,7 +99,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) if (wallet->IsMine(txout)) { CBitcoinAddress address; - if (ExtractAddress(txout.scriptPubKey, wallet, address)) + if (ExtractAddress(txout.scriptPubKey, address) && wallet->HaveKey(address)) { if (wallet->mapAddressBook.count(address)) { @@ -184,7 +184,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) { // Offline transaction CBitcoinAddress address; - if (ExtractAddress(txout.scriptPubKey, 0, address)) + if (ExtractAddress(txout.scriptPubKey, address)) { strHTML += tr("<b>To:</b> "); if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].empty()) @@ -271,7 +271,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) strHTML += "<li>"; const CTxOut &vout = prev.vout[prevout.n]; CBitcoinAddress address; - if (ExtractAddress(vout.scriptPubKey, 0, address)) + if (ExtractAddress(vout.scriptPubKey, address)) { if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].empty()) strHTML += HtmlEscape(wallet->mapAddressBook[address]) + " "; diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 53cd35b2da..f3dbd45c6d 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -80,7 +80,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet * if(wallet->IsMine(txout)) { CBitcoinAddress address; - if (ExtractAddress(txout.scriptPubKey, wallet, address)) + if (ExtractAddress(txout.scriptPubKey, address) && wallet->HaveKey(address)) { sub.address = address.ToString(); } @@ -138,7 +138,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet * // Sent to Bitcoin Address sub.type = TransactionRecord::SendToAddress; CBitcoinAddress address; - if (ExtractAddress(txout.scriptPubKey, 0, address)) + if (ExtractAddress(txout.scriptPubKey, address)) { sub.address = address.ToString(); } diff --git a/src/script.cpp b/src/script.cpp index 467cb2f0df..0a1b3bb309 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -1442,7 +1442,7 @@ bool IsMine(const CKeyStore &keystore, const CScript& scriptPubKey) return false; } -bool ExtractAddress(const CScript& scriptPubKey, const CKeyStore* keystore, CBitcoinAddress& addressRet) +bool ExtractAddress(const CScript& scriptPubKey, CBitcoinAddress& addressRet) { vector<valtype> vSolutions; txnouttype whichType; @@ -1468,7 +1468,7 @@ bool ExtractAddress(const CScript& scriptPubKey, const CKeyStore* keystore, CBit return false; } -bool ExtractAddresses(const CScript& scriptPubKey, const CKeyStore* keystore, txnouttype& typeRet, vector<CBitcoinAddress>& addressRet, int& nRequiredRet) +bool ExtractAddresses(const CScript& scriptPubKey, txnouttype& typeRet, vector<CBitcoinAddress>& addressRet, int& nRequiredRet) { addressRet.clear(); typeRet = TX_NONSTANDARD; diff --git a/src/script.h b/src/script.h index b671e15963..0080f5b726 100644 --- a/src/script.h +++ b/src/script.h @@ -572,8 +572,8 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet); bool IsStandard(const CScript& scriptPubKey); bool IsMine(const CKeyStore& keystore, const CScript& scriptPubKey); -bool ExtractAddress(const CScript& scriptPubKey, const CKeyStore* pkeystore, CBitcoinAddress& addressRet); -bool ExtractAddresses(const CScript& scriptPubKey, const CKeyStore* pkeystore, txnouttype& typeRet, std::vector<CBitcoinAddress>& addressRet, int& nRequiredRet); +bool ExtractAddress(const CScript& scriptPubKey, CBitcoinAddress& addressRet); +bool ExtractAddresses(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CBitcoinAddress>& addressRet, int& nRequiredRet); bool SignSignature(const CKeyStore& keystore, const CTransaction& txFrom, CTransaction& txTo, unsigned int nIn, int nHashType=SIGHASH_ALL, CScript scriptPrereq=CScript()); bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsigned int nIn, int& nSigOpCountRet, int nHashType=0, bool fStrictOpEval=true); diff --git a/src/test/multisig_tests.cpp b/src/test/multisig_tests.cpp index 58f62b9542..742083f3cf 100644 --- a/src/test/multisig_tests.cpp +++ b/src/test/multisig_tests.cpp @@ -192,7 +192,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1) BOOST_CHECK(Solver(s, whichType, solutions)); BOOST_CHECK(solutions.size() == 1); CBitcoinAddress addr; - BOOST_CHECK(ExtractAddress(s, &keystore, addr)); + BOOST_CHECK(ExtractAddress(s, addr)); BOOST_CHECK(addr == keyaddr[0]); BOOST_CHECK(IsMine(keystore, s)); BOOST_CHECK(!IsMine(emptykeystore, s)); @@ -205,7 +205,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1) BOOST_CHECK(Solver(s, whichType, solutions)); BOOST_CHECK(solutions.size() == 1); CBitcoinAddress addr; - BOOST_CHECK(ExtractAddress(s, &keystore, addr)); + BOOST_CHECK(ExtractAddress(s, addr)); BOOST_CHECK(addr == keyaddr[0]); BOOST_CHECK(IsMine(keystore, s)); BOOST_CHECK(!IsMine(emptykeystore, s)); @@ -218,7 +218,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1) BOOST_CHECK(Solver(s, whichType, solutions)); BOOST_CHECK_EQUAL(solutions.size(), 4); CBitcoinAddress addr; - BOOST_CHECK(!ExtractAddress(s, &keystore, addr)); + BOOST_CHECK(!ExtractAddress(s, addr)); BOOST_CHECK(IsMine(keystore, s)); BOOST_CHECK(!IsMine(emptykeystore, s)); } @@ -231,7 +231,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1) BOOST_CHECK_EQUAL(solutions.size(), 4); vector<CBitcoinAddress> addrs; int nRequired; - BOOST_CHECK(ExtractAddresses(s, &keystore, whichType, addrs, nRequired)); + BOOST_CHECK(ExtractAddresses(s, whichType, addrs, nRequired)); BOOST_CHECK(addrs[0] == keyaddr[0]); BOOST_CHECK(addrs[1] == keyaddr[1]); BOOST_CHECK(nRequired = 1); diff --git a/src/wallet.cpp b/src/wallet.cpp index c35081ce44..28d15ef2e5 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -394,7 +394,7 @@ bool CWallet::IsChange(const CTxOut& txout) const // a better way of identifying which outputs are 'the send' and which are // 'the change' will need to be implemented (maybe extend CWalletTx to remember // which output, if any, was change). - if (ExtractAddress(txout.scriptPubKey, this, address)) + if (ExtractAddress(txout.scriptPubKey, address) && HaveKey(address)) CRITICAL_BLOCK(cs_wallet) if (!mapAddressBook.count(address)) return true; @@ -475,7 +475,7 @@ void CWalletTx::GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, l { CBitcoinAddress address; vector<unsigned char> vchPubKey; - if (!ExtractAddress(txout.scriptPubKey, NULL, address)) + if (!ExtractAddress(txout.scriptPubKey, address)) { printf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n", this->GetHash().ToString().c_str()); |