@@ -244,49 +244,46 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
244
244
245
245
if (role == Qt::EditRole)
246
246
{
247
- switch (index.column ())
247
+ LOCK (wallet->cs_wallet ); /* For SetAddressBook / DelAddressBook */
248
+ CTxDestination curAddress = CBitcoinAddress (rec->address .toStdString ()).Get ();
249
+ if (index.column () == Label)
248
250
{
249
- case Label:
250
251
// Do nothing, if old label == new label
251
252
if (rec->label == value.toString ())
252
253
{
253
254
editStatus = NO_CHANGES;
254
255
return false ;
255
256
}
256
- wallet->SetAddressBook (CBitcoinAddress (rec-> address . toStdString ()). Get () , value.toString ().toStdString (), strPurpose);
257
- break ;
258
- case Address:
259
- // Do nothing, if old address == new address
260
- if (CBitcoinAddress (rec-> address . toStdString ()) == CBitcoinAddress (value. toString (). toStdString () ))
257
+ wallet->SetAddressBook (curAddress , value.toString ().toStdString (), strPurpose);
258
+ } else if (index. column () == Address) {
259
+ CTxDestination newAddress = CBitcoinAddress (value. toString (). toStdString ()). Get ();
260
+ // Refuse to set invalid address, set error status and return false
261
+ if (boost::get<CNoDestination>(&newAddress ))
261
262
{
262
- editStatus = NO_CHANGES ;
263
+ editStatus = INVALID_ADDRESS ;
263
264
return false ;
264
265
}
265
- // Refuse to set invalid address, set error status and return false
266
- else if (!walletModel-> validateAddress (value. toString ()) )
266
+ // Do nothing, if old address == new address
267
+ else if (newAddress == curAddress )
267
268
{
268
- editStatus = INVALID_ADDRESS ;
269
+ editStatus = NO_CHANGES ;
269
270
return false ;
270
271
}
271
272
// Check for duplicate addresses to prevent accidental deletion of addresses, if you try
272
273
// to paste an existing address over another address (with a different label)
273
- else if (wallet->mapAddressBook .count (CBitcoinAddress (value. toString (). toStdString ()). Get () ))
274
+ else if (wallet->mapAddressBook .count (newAddress ))
274
275
{
275
276
editStatus = DUPLICATE_ADDRESS;
276
277
return false ;
277
278
}
278
279
// Double-check that we're not overwriting a receiving address
279
280
else if (rec->type == AddressTableEntry::Sending)
280
281
{
281
- {
282
- LOCK (wallet->cs_wallet );
283
- // Remove old entry
284
- wallet->DelAddressBook (CBitcoinAddress (rec->address .toStdString ()).Get ());
285
- // Add new entry with new address
286
- wallet->SetAddressBook (CBitcoinAddress (value.toString ().toStdString ()).Get (), rec->label .toStdString (), strPurpose);
287
- }
282
+ // Remove old entry
283
+ wallet->DelAddressBook (curAddress);
284
+ // Add new entry with new address
285
+ wallet->SetAddressBook (newAddress, rec->label .toStdString (), strPurpose);
288
286
}
289
- break ;
290
287
}
291
288
return true ;
292
289
}
0 commit comments