Fix broken ExtractAddress (refactored, made callers check for addresses in keystore if they care)
This commit is contained in:
parent
ce336fdc21
commit
2e17ac83c6
7 changed files with 20 additions and 18 deletions
|
@ -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)
|
||||
|
|
|
@ -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]) + " ";
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue