7
7
#include < qt/guiutil.h>
8
8
#include < qt/walletmodel.h>
9
9
10
+ #include < interface/node.h>
10
11
#include < key_io.h>
11
12
#include < wallet/wallet.h>
12
13
@@ -67,28 +68,23 @@ static AddressTableEntry::Type translateTransactionType(const QString &strPurpos
67
68
class AddressTablePriv
68
69
{
69
70
public:
70
- CWallet *wallet;
71
71
QList<AddressTableEntry> cachedAddressTable;
72
72
AddressTableModel *parent;
73
73
74
- AddressTablePriv (CWallet *_wallet, AddressTableModel *_parent):
75
- wallet (_wallet), parent(_parent) {}
74
+ AddressTablePriv (AddressTableModel *_parent):
75
+ parent (_parent) {}
76
76
77
- void refreshAddressTable ()
77
+ void refreshAddressTable (interface::Wallet& wallet )
78
78
{
79
79
cachedAddressTable.clear ();
80
80
{
81
- LOCK (wallet->cs_wallet );
82
- for (const std::pair<CTxDestination, CAddressBookData>& item : wallet->mapAddressBook )
81
+ for (const auto & address : wallet.getAddresses ())
83
82
{
84
- const CTxDestination& address = item.first ;
85
- bool fMine = IsMine (*wallet, address);
86
83
AddressTableEntry::Type addressType = translateTransactionType (
87
- QString::fromStdString (item.second .purpose ), fMine );
88
- const std::string& strName = item.second .name ;
84
+ QString::fromStdString (address.purpose ), address.is_mine );
89
85
cachedAddressTable.append (AddressTableEntry (addressType,
90
- QString::fromStdString (strName ),
91
- QString::fromStdString (EncodeDestination (address))));
86
+ QString::fromStdString (address. name ),
87
+ QString::fromStdString (EncodeDestination (address. dest ))));
92
88
}
93
89
}
94
90
// qLowerBound() and qUpperBound() require our cachedAddressTable list to be sorted in asc order
@@ -162,12 +158,12 @@ class AddressTablePriv
162
158
}
163
159
};
164
160
165
- AddressTableModel::AddressTableModel (CWallet *_wallet, WalletModel *parent) :
166
- QAbstractTableModel(parent),walletModel(parent),wallet(_wallet), priv(0 )
161
+ AddressTableModel::AddressTableModel (WalletModel *parent) :
162
+ QAbstractTableModel(parent),walletModel(parent),priv(0 )
167
163
{
168
164
columns << tr (" Label" ) << tr (" Address" );
169
- priv = new AddressTablePriv (wallet, this );
170
- priv->refreshAddressTable ();
165
+ priv = new AddressTablePriv (this );
166
+ priv->refreshAddressTable (parent-> wallet () );
171
167
}
172
168
173
169
AddressTableModel::~AddressTableModel ()
@@ -244,7 +240,6 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
244
240
245
241
if (role == Qt::EditRole)
246
242
{
247
- LOCK (wallet->cs_wallet ); /* For SetAddressBook / DelAddressBook */
248
243
CTxDestination curAddress = DecodeDestination (rec->address .toStdString ());
249
244
if (index.column () == Label)
250
245
{
@@ -254,7 +249,7 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
254
249
editStatus = NO_CHANGES;
255
250
return false ;
256
251
}
257
- wallet-> SetAddressBook (curAddress, value.toString ().toStdString (), strPurpose);
252
+ walletModel-> wallet (). setAddressBook (curAddress, value.toString ().toStdString (), strPurpose);
258
253
} else if (index.column () == Address) {
259
254
CTxDestination newAddress = DecodeDestination (value.toString ().toStdString ());
260
255
// Refuse to set invalid address, set error status and return false
@@ -271,7 +266,7 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
271
266
}
272
267
// Check for duplicate addresses to prevent accidental deletion of addresses, if you try
273
268
// to paste an existing address over another address (with a different label)
274
- else if (wallet-> mapAddressBook . count (newAddress))
269
+ if (walletModel-> wallet (). getAddress (newAddress))
275
270
{
276
271
editStatus = DUPLICATE_ADDRESS;
277
272
return false ;
@@ -280,9 +275,9 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
280
275
else if (rec->type == AddressTableEntry::Sending)
281
276
{
282
277
// Remove old entry
283
- wallet-> DelAddressBook (curAddress);
278
+ walletModel-> wallet (). delAddressBook (curAddress);
284
279
// Add new entry with new address
285
- wallet-> SetAddressBook ( newAddress, rec-> label .toStdString (), strPurpose);
280
+ walletModel-> wallet (). setAddressBook ( newAddress, value. toString () .toStdString (), strPurpose);
286
281
}
287
282
}
288
283
return true ;
@@ -356,8 +351,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
356
351
}
357
352
// Check for duplicate addresses
358
353
{
359
- LOCK (wallet->cs_wallet );
360
- if (wallet->mapAddressBook .count (DecodeDestination (strAddress)))
354
+ if (walletModel->wallet ().getAddress (DecodeDestination (strAddress)))
361
355
{
362
356
editStatus = DUPLICATE_ADDRESS;
363
357
return QString ();
@@ -368,7 +362,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
368
362
{
369
363
// Generate a new address to associate with given label
370
364
CPubKey newKey;
371
- if (!wallet-> GetKeyFromPool ( newKey))
365
+ if (!walletModel-> wallet (). getKeyFromPool ( false /* internal */ , newKey))
372
366
{
373
367
WalletModel::UnlockContext ctx (walletModel->requestUnlock ());
374
368
if (!ctx.isValid ())
@@ -377,13 +371,13 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
377
371
editStatus = WALLET_UNLOCK_FAILURE;
378
372
return QString ();
379
373
}
380
- if (!wallet-> GetKeyFromPool ( newKey))
374
+ if (!walletModel-> wallet (). getKeyFromPool ( false /* internal */ , newKey))
381
375
{
382
376
editStatus = KEY_GENERATION_FAILURE;
383
377
return QString ();
384
378
}
385
379
}
386
- wallet-> LearnRelatedScripts (newKey, address_type);
380
+ walletModel-> wallet (). learnRelatedScripts (newKey, address_type);
387
381
strAddress = EncodeDestination (GetDestinationForKey (newKey, address_type));
388
382
}
389
383
else
@@ -392,7 +386,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
392
386
}
393
387
394
388
// Add entry
395
- wallet-> SetAddressBook (DecodeDestination (strAddress), strLabel,
389
+ walletModel-> wallet (). setAddressBook (DecodeDestination (strAddress), strLabel,
396
390
(type == Send ? " send" : " receive" ));
397
391
return QString::fromStdString (strAddress);
398
392
}
@@ -407,7 +401,7 @@ bool AddressTableModel::removeRows(int row, int count, const QModelIndex &parent
407
401
// Also refuse to remove receiving addresses.
408
402
return false ;
409
403
}
410
- wallet-> DelAddressBook (DecodeDestination (rec->address .toStdString ()));
404
+ walletModel-> wallet (). delAddressBook (DecodeDestination (rec->address .toStdString ()));
411
405
return true ;
412
406
}
413
407
@@ -416,12 +410,11 @@ bool AddressTableModel::removeRows(int row, int count, const QModelIndex &parent
416
410
QString AddressTableModel::labelForAddress (const QString &address) const
417
411
{
418
412
{
419
- LOCK (wallet->cs_wallet );
420
413
CTxDestination destination = DecodeDestination (address.toStdString ());
421
- std::map<CTxDestination, CAddressBookData>::iterator mi = wallet-> mapAddressBook . find (destination) ;
422
- if (mi != wallet-> mapAddressBook . end ( ))
414
+ std::string name ;
415
+ if (walletModel-> wallet (). getAddress (destination, &name ))
423
416
{
424
- return QString::fromStdString (mi-> second . name );
417
+ return QString::fromStdString (name);
425
418
}
426
419
}
427
420
return QString ();
@@ -441,7 +434,7 @@ int AddressTableModel::lookupAddress(const QString &address) const
441
434
}
442
435
}
443
436
444
- OutputType AddressTableModel::GetDefaultAddressType () const { return wallet-> m_default_address_type ; };
437
+ OutputType AddressTableModel::GetDefaultAddressType () const { return walletModel-> wallet (). getDefaultAddressType () ; };
445
438
446
439
void AddressTableModel::emitDataChanged (int idx)
447
440
{
0 commit comments