aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.cpp
diff options
context:
space:
mode:
authorGregory Maxwell <greg@xiph.org>2012-09-27 13:29:35 -0400
committerGregory Maxwell <greg@xiph.org>2012-12-14 07:35:56 -0500
commita3fad2119bcf4638ed137fc5cddc2f34a3bd1dc2 (patch)
treebf78ebd8bce2eec6883b543dde9155c2a8ea83ef /src/wallet.cpp
parent14ac0adcc7c0224a467e38bbd4ebf39d824ada8d (diff)
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.
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r--src/wallet.cpp33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp
index a10f187309..3806f1e790 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -1664,29 +1664,38 @@ set< set<CTxDestination> > CWallet::GetAddressGroupings()
{
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
BOOST_FOREACH(CTxIn txin, pcoin->vin)
{
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))
continue;
grouping.insert(address);
+ any_mine = true;
}
// group change with input addresses
- BOOST_FOREACH(CTxOut txout, pcoin->vout)
- if (IsChange(txout))
- {
- CWalletTx tx = mapWallet[pcoin->vin[0].prevout.hash];
- CTxDestination txoutAddr;
- if(!ExtractDestination(txout.scriptPubKey, txoutAddr))
- continue;
- grouping.insert(txoutAddr);
- }
- groupings.insert(grouping);
- grouping.clear();
+ if (any_mine)
+ {
+ BOOST_FOREACH(CTxOut txout, pcoin->vout)
+ if (IsChange(txout))
+ {
+ CTxDestination txoutAddr;
+ if(!ExtractDestination(txout.scriptPubKey, txoutAddr))
+ continue;
+ grouping.insert(txoutAddr);
+ }
+ }
+ if (grouping.size() > 0)
+ {
+ groupings.insert(grouping);
+ grouping.clear();
+ }
}
// group lone addrs by themselves