@@ -1210,15 +1210,13 @@ void CWallet::BlockUntilSyncedToCurrentChain() const {
1210
1210
1211
1211
isminetype CWallet::IsMine (const CTxIn &txin) const
1212
1212
{
1213
+ AssertLockHeld (cs_wallet);
1214
+ std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find (txin.prevout .hash );
1215
+ if (mi != mapWallet.end ())
1213
1216
{
1214
- LOCK (cs_wallet);
1215
- std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find (txin.prevout .hash );
1216
- if (mi != mapWallet.end ())
1217
- {
1218
- const CWalletTx& prev = (*mi).second ;
1219
- if (txin.prevout .n < prev.tx ->vout .size ())
1220
- return IsMine (prev.tx ->vout [txin.prevout .n ]);
1221
- }
1217
+ const CWalletTx& prev = (*mi).second ;
1218
+ if (txin.prevout .n < prev.tx ->vout .size ())
1219
+ return IsMine (prev.tx ->vout [txin.prevout .n ]);
1222
1220
}
1223
1221
return ISMINE_NO;
1224
1222
}
@@ -1243,16 +1241,19 @@ CAmount CWallet::GetDebit(const CTxIn &txin, const isminefilter& filter) const
1243
1241
1244
1242
isminetype CWallet::IsMine (const CTxOut& txout) const
1245
1243
{
1244
+ AssertLockHeld (cs_wallet);
1246
1245
return IsMine (txout.scriptPubKey );
1247
1246
}
1248
1247
1249
1248
isminetype CWallet::IsMine (const CTxDestination& dest) const
1250
1249
{
1250
+ AssertLockHeld (cs_wallet);
1251
1251
return IsMine (GetScriptForDestination (dest));
1252
1252
}
1253
1253
1254
1254
isminetype CWallet::IsMine (const CScript& script) const
1255
1255
{
1256
+ AssertLockHeld (cs_wallet);
1256
1257
isminetype result = ISMINE_NO;
1257
1258
for (const auto & spk_man_pair : m_spk_managers) {
1258
1259
result = std::max (result, spk_man_pair.second ->IsMine (script));
@@ -1264,6 +1265,7 @@ CAmount CWallet::GetCredit(const CTxOut& txout, const isminefilter& filter) cons
1264
1265
{
1265
1266
if (!MoneyRange (txout.nValue ))
1266
1267
throw std::runtime_error (std::string (__func__) + " : value out of range" );
1268
+ LOCK (cs_wallet);
1267
1269
return ((IsMine (txout) & filter) ? txout.nValue : 0 );
1268
1270
}
1269
1271
@@ -1281,13 +1283,12 @@ bool CWallet::IsChange(const CScript& script) const
1281
1283
// a better way of identifying which outputs are 'the send' and which are
1282
1284
// 'the change' will need to be implemented (maybe extend CWalletTx to remember
1283
1285
// which output, if any, was change).
1286
+ LOCK (cs_wallet);
1284
1287
if (IsMine (script))
1285
1288
{
1286
1289
CTxDestination address;
1287
1290
if (!ExtractDestination (script, address))
1288
1291
return true ;
1289
-
1290
- LOCK (cs_wallet);
1291
1292
if (!FindAddressBookEntry (address)) {
1292
1293
return true ;
1293
1294
}
@@ -1304,6 +1305,7 @@ CAmount CWallet::GetChange(const CTxOut& txout) const
1304
1305
1305
1306
bool CWallet::IsMine (const CTransaction& tx) const
1306
1307
{
1308
+ AssertLockHeld (cs_wallet);
1307
1309
for (const CTxOut& txout : tx.vout )
1308
1310
if (IsMine (txout))
1309
1311
return true ;
@@ -1597,6 +1599,7 @@ void CWalletTx::GetAmounts(std::list<COutputEntry>& listReceived,
1597
1599
nFee = nDebit - nValueOut;
1598
1600
}
1599
1601
1602
+ LOCK (pwallet->cs_wallet );
1600
1603
// Sent/received.
1601
1604
for (unsigned int i = 0 ; i < tx->vout .size (); ++i)
1602
1605
{
@@ -3155,15 +3158,17 @@ DBErrors CWallet::ZapWalletTx(std::list<CWalletTx>& vWtx)
3155
3158
bool CWallet::SetAddressBookWithDB (WalletBatch& batch, const CTxDestination& address, const std::string& strName, const std::string& strPurpose)
3156
3159
{
3157
3160
bool fUpdated = false ;
3161
+ bool is_mine;
3158
3162
{
3159
3163
LOCK (cs_wallet);
3160
3164
std::map<CTxDestination, CAddressBookData>::iterator mi = m_address_book.find (address);
3161
3165
fUpdated = (mi != m_address_book.end () && !mi->second .IsChange ());
3162
3166
m_address_book[address].SetLabel (strName);
3163
3167
if (!strPurpose.empty ()) /* update purpose only if requested */
3164
3168
m_address_book[address].purpose = strPurpose;
3169
+ is_mine = IsMine (address) != ISMINE_NO;
3165
3170
}
3166
- NotifyAddressBookChanged (this , address, strName, IsMine (address) != ISMINE_NO ,
3171
+ NotifyAddressBookChanged (this , address, strName, is_mine ,
3167
3172
strPurpose, (fUpdated ? CT_UPDATED : CT_NEW) );
3168
3173
if (!strPurpose.empty () && !batch.WritePurpose (EncodeDestination (address), strPurpose))
3169
3174
return false ;
@@ -3178,27 +3183,27 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
3178
3183
3179
3184
bool CWallet::DelAddressBook (const CTxDestination& address)
3180
3185
{
3181
- // If we want to delete receiving addresses, we need to take care that DestData "used" (and possibly newer DestData) gets preserved (and the "deleted" address transformed into a change entry instead of actually being deleted)
3182
- // NOTE: This isn't a problem for sending addresses because they never have any DestData yet!
3183
- // When adding new DestData, it should be considered here whether to retain or delete it (or move it?).
3184
- if (IsMine (address)) {
3185
- WalletLogPrintf (" %s called with IsMine address, NOT SUPPORTED. Please report this bug! %s\n " , __func__, PACKAGE_BUGREPORT);
3186
- return false ;
3187
- }
3188
-
3186
+ bool is_mine;
3189
3187
{
3190
3188
LOCK (cs_wallet);
3191
-
3189
+ // If we want to delete receiving addresses, we need to take care that DestData "used" (and possibly newer DestData) gets preserved (and the "deleted" address transformed into a change entry instead of actually being deleted)
3190
+ // NOTE: This isn't a problem for sending addresses because they never have any DestData yet!
3191
+ // When adding new DestData, it should be considered here whether to retain or delete it (or move it?).
3192
+ if (IsMine (address)) {
3193
+ WalletLogPrintf (" %s called with IsMine address, NOT SUPPORTED. Please report this bug! %s\n " , __func__, PACKAGE_BUGREPORT);
3194
+ return false ;
3195
+ }
3192
3196
// Delete destdata tuples associated with address
3193
3197
std::string strAddress = EncodeDestination (address);
3194
3198
for (const std::pair<const std::string, std::string> &item : m_address_book[address].destdata )
3195
3199
{
3196
3200
WalletBatch (*database).EraseDestData (strAddress, item.first );
3197
3201
}
3198
3202
m_address_book.erase (address);
3203
+ is_mine = IsMine (address) != ISMINE_NO;
3199
3204
}
3200
3205
3201
- NotifyAddressBookChanged (this , address, " " , IsMine (address) != ISMINE_NO , " " , CT_DELETED);
3206
+ NotifyAddressBookChanged (this , address, " " , is_mine , " " , CT_DELETED);
3202
3207
3203
3208
WalletBatch (*database).ErasePurpose (EncodeDestination (address));
3204
3209
return WalletBatch (*database).EraseName (EncodeDestination (address));
0 commit comments