Browse Source

In listaddressgroupings push down the IsMine check to run on each input.

This avoids a potential crash when trying to read the scrippubkeys on
transactions where the first input IsMine but some of the rest are not
when running listaddressgroupings.
0.8
Gregory Maxwell 12 years ago
parent
commit
a3fad2119b
  1. 33
      src/wallet.cpp

33
src/wallet.cpp

@ -1664,29 +1664,38 @@ set< set<CTxDestination> > CWallet::GetAddressGroupings()
{ {
CWalletTx *pcoin = &walletEntry.second; CWalletTx *pcoin = &walletEntry.second;
if (pcoin->vin.size() > 0 && IsMine(pcoin->vin[0])) if (pcoin->vin.size() > 0)
{ {
bool any_mine = false;
// group all input addresses with each other // group all input addresses with each other
BOOST_FOREACH(CTxIn txin, pcoin->vin) BOOST_FOREACH(CTxIn txin, pcoin->vin)
{ {
CTxDestination address; CTxDestination address;
if(!IsMine(txin)) /* If this input isn't mine, ignore it */
continue;
if(!ExtractDestination(mapWallet[txin.prevout.hash].vout[txin.prevout.n].scriptPubKey, address)) if(!ExtractDestination(mapWallet[txin.prevout.hash].vout[txin.prevout.n].scriptPubKey, address))
continue; continue;
grouping.insert(address); grouping.insert(address);
any_mine = true;
} }
// group change with input addresses // group change with input addresses
BOOST_FOREACH(CTxOut txout, pcoin->vout) if (any_mine)
if (IsChange(txout)) {
{ BOOST_FOREACH(CTxOut txout, pcoin->vout)
CWalletTx tx = mapWallet[pcoin->vin[0].prevout.hash]; if (IsChange(txout))
CTxDestination txoutAddr; {
if(!ExtractDestination(txout.scriptPubKey, txoutAddr)) CTxDestination txoutAddr;
continue; if(!ExtractDestination(txout.scriptPubKey, txoutAddr))
grouping.insert(txoutAddr); continue;
} grouping.insert(txoutAddr);
groupings.insert(grouping); }
grouping.clear(); }
if (grouping.size() > 0)
{
groupings.insert(grouping);
grouping.clear();
}
} }
// group lone addrs by themselves // group lone addrs by themselves

Loading…
Cancel
Save