From 690c723e5fef4de77a2f1cbc51c9b3166c509520 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 26 Jul 2011 16:54:32 +0200 Subject: [PATCH 1/3] make SetHash160 return a value (as specified in the function signature) --- src/base58.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/base58.h b/src/base58.h index 266412c861..04922c74d8 100644 --- a/src/base58.h +++ b/src/base58.h @@ -244,6 +244,7 @@ public: bool SetHash160(const uint160& hash160) { SetData(fTestNet ? 111 : 0, &hash160, 20); + return true; } bool SetPubKey(const std::vector& vchPubKey) From b63241d4511896fcd65996ac7d9a5cb935118ca3 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 26 Jul 2011 19:15:45 +0200 Subject: [PATCH 2/3] Bugfix: don't overuse limited ExtractAddress ExtractAddress was called with the keystore as argument in RPC and UI, limiting results to own keys. This caused empty "address" fields. --- src/script.cpp | 33 ++++++++++++++++++++------------- src/ui.cpp | 8 ++++---- src/wallet.cpp | 2 +- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/script.cpp b/src/script.cpp index 652240f686..0fc4611fda 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -1122,30 +1122,37 @@ bool IsMine(const CKeyStore &keystore, const CScript& scriptPubKey) return true; } - -bool ExtractAddress(const CScript& scriptPubKey, const CKeyStore* keystore, CBitcoinAddress& addressRet) +// requires either keystore==0, or a lock on keystore->cs_KeyStore +bool static ExtractAddressInner(const CScript& scriptPubKey, const CKeyStore* keystore, CBitcoinAddress& addressRet) { vector > vSolution; if (!Solver(scriptPubKey, vSolution)) return false; - CRITICAL_BLOCK(keystore->cs_KeyStore) + BOOST_FOREACH(PAIRTYPE(opcodetype, valtype)& item, vSolution) { - BOOST_FOREACH(PAIRTYPE(opcodetype, valtype)& item, vSolution) - { - uint160 hash160; - if (item.first == OP_PUBKEY) - addressRet.SetPubKey(item.second); - else if (item.first == OP_PUBKEYHASH) - addressRet.SetHash160((uint160)item.second); - if (keystore == NULL || keystore->HaveKey(addressRet)) - return true; - } + if (item.first == OP_PUBKEY) + addressRet.SetPubKey(item.second); + else if (item.first == OP_PUBKEYHASH) + addressRet.SetHash160((uint160)item.second); + if (keystore == NULL || keystore->HaveKey(addressRet)) + return true; } return false; } +bool ExtractAddress(const CScript& scriptPubKey, const CKeyStore* keystore, CBitcoinAddress& addressRet) +{ + if (keystore) + CRITICAL_BLOCK(keystore->cs_KeyStore) + return ExtractAddressInner(scriptPubKey, keystore, addressRet); + else + return ExtractAddressInner(scriptPubKey, NULL, addressRet); + return false; +} + + bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CTransaction& txTo, unsigned int nIn, int nHashType) { vector > stack; diff --git a/src/ui.cpp b/src/ui.cpp index 7d06caaec4..c3c234439c 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -776,6 +776,7 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex) if (pwalletMain->IsMine(txout)) continue; + CBitcoinAddress address; string strAddress; if (!mapValue["to"].empty()) { @@ -785,15 +786,14 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex) else { // Sent to Bitcoin Address - CBitcoinAddress address; - if (ExtractAddress(txout.scriptPubKey, pwalletMain, address)) + if (ExtractAddress(txout.scriptPubKey, NULL, address)) strAddress = address.ToString(); } string strDescription = _("To: "); CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) - if (pwalletMain->mapAddressBook.count(strAddress) && !pwalletMain->mapAddressBook[strAddress].empty()) - strDescription += pwalletMain->mapAddressBook[strAddress] + " "; + if (pwalletMain->mapAddressBook.count(address) && !pwalletMain->mapAddressBook[address].empty()) + strDescription += pwalletMain->mapAddressBook[address] + " "; strDescription += strAddress; if (!mapValue["message"].empty()) { diff --git a/src/wallet.cpp b/src/wallet.cpp index 8c4903b198..1f3f44bfa0 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -437,7 +437,7 @@ void CWalletTx::GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, l { CBitcoinAddress address; vector vchPubKey; - if (!ExtractAddress(txout.scriptPubKey, pwallet, address)) + if (!ExtractAddress(txout.scriptPubKey, NULL, address)) { printf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n", this->GetHash().ToString().c_str()); From a139ed74f2a5764afbd678c0e4eb6143455a3a49 Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Tue, 26 Jul 2011 15:15:55 -0400 Subject: [PATCH 3/3] CAddrDB::LoadAddresses: properly initialize CAddress Fixes issue #424 --- src/db.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db.cpp b/src/db.cpp index 6692db239f..9c8c9c4f73 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -528,7 +528,7 @@ bool CAddrDB::LoadAddresses() char psz[1000]; while (fgets(psz, sizeof(psz), filein)) { - CAddress addr(psz, NODE_NETWORK); + CAddress addr(psz, false, NODE_NETWORK); addr.nTime = 0; // so it won't relay unless successfully connected if (addr.IsValid()) AddAddress(addr);