Merge pull request #435 from sipa/fixextract

Bugfix: don't overuse limited ExtractAddress
This commit is contained in:
Pieter Wuille 2011-07-26 10:43:00 -07:00
commit aa7c5e7ceb
3 changed files with 25 additions and 18 deletions

View file

@ -1122,18 +1122,15 @@ 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<pair<opcodetype, valtype> > vSolution;
if (!Solver(scriptPubKey, vSolution))
return false;
CRITICAL_BLOCK(keystore->cs_KeyStore)
{
BOOST_FOREACH(PAIRTYPE(opcodetype, valtype)& item, vSolution)
{
uint160 hash160;
if (item.first == OP_PUBKEY)
addressRet.SetPubKey(item.second);
else if (item.first == OP_PUBKEYHASH)
@ -1141,7 +1138,17 @@ bool ExtractAddress(const CScript& scriptPubKey, const CKeyStore* keystore, CBit
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;
}

View file

@ -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())
{

View file

@ -437,7 +437,7 @@ void CWalletTx::GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, l
{
CBitcoinAddress address;
vector<unsigned char> 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());