Changeset View
Changeset View
Standalone View
Standalone View
src/qt/addresstablemodel.cpp
// Copyright (c) 2011-2016 The Bitcoin Core developers | // Copyright (c) 2011-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <qt/addresstablemodel.h> | #include <qt/addresstablemodel.h> | ||||
#include <cashaddrenc.h> | #include <cashaddrenc.h> | ||||
#include <interfaces/node.h> | #include <interfaces/node.h> | ||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <qt/guiutil.h> | #include <qt/guiutil.h> | ||||
#include <qt/walletmodel.h> | #include <qt/walletmodel.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#include <algorithm> | |||||
#include <QDebug> | #include <QDebug> | ||||
#include <QFont> | #include <QFont> | ||||
const QString AddressTableModel::Send = "S"; | const QString AddressTableModel::Send = "S"; | ||||
const QString AddressTableModel::Receive = "R"; | const QString AddressTableModel::Receive = "R"; | ||||
struct AddressTableEntry { | struct AddressTableEntry { | ||||
enum Type { | enum Type { | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | void refreshAddressTable(interfaces::Wallet &wallet) { | ||||
for (const auto &address : wallet.getAddresses()) { | for (const auto &address : wallet.getAddresses()) { | ||||
AddressTableEntry::Type addressType = translateTransactionType( | AddressTableEntry::Type addressType = translateTransactionType( | ||||
QString::fromStdString(address.purpose), address.is_mine); | QString::fromStdString(address.purpose), address.is_mine); | ||||
cachedAddressTable.append(AddressTableEntry( | cachedAddressTable.append(AddressTableEntry( | ||||
addressType, QString::fromStdString(address.name), | addressType, QString::fromStdString(address.name), | ||||
QString::fromStdString(EncodeCashAddr( | QString::fromStdString(EncodeCashAddr( | ||||
address.dest, parent->walletModel->getChainParams())))); | address.dest, parent->walletModel->getChainParams())))); | ||||
} | } | ||||
// qLowerBound() and qUpperBound() require our cachedAddressTable list | // std::lower_bound() and std::upper_bound() require our | ||||
// to be sorted in asc order. Even though the map is already sorted this | // cachedAddressTable list to be sorted in asc order Even though the map | ||||
// re-sorting step is needed because the originating map is sorted by | // is already sorted this re-sorting step is needed because the | ||||
// binary address, not by base58() address. | // originating map is sorted by binary address, not by base58() address. | ||||
qSort(cachedAddressTable.begin(), cachedAddressTable.end(), | std::sort(cachedAddressTable.begin(), cachedAddressTable.end(), | ||||
AddressTableEntryLessThan()); | AddressTableEntryLessThan()); | ||||
} | } | ||||
void updateEntry(const QString &address, const QString &label, bool isMine, | void updateEntry(const QString &address, const QString &label, bool isMine, | ||||
const QString &purpose, int status) { | const QString &purpose, int status) { | ||||
// Find address / label in model | // Find address / label in model | ||||
QList<AddressTableEntry>::iterator lower = | QList<AddressTableEntry>::iterator lower = std::lower_bound( | ||||
qLowerBound(cachedAddressTable.begin(), cachedAddressTable.end(), | cachedAddressTable.begin(), cachedAddressTable.end(), address, | ||||
address, AddressTableEntryLessThan()); | AddressTableEntryLessThan()); | ||||
QList<AddressTableEntry>::iterator upper = | QList<AddressTableEntry>::iterator upper = std::upper_bound( | ||||
qUpperBound(cachedAddressTable.begin(), cachedAddressTable.end(), | cachedAddressTable.begin(), cachedAddressTable.end(), address, | ||||
address, AddressTableEntryLessThan()); | AddressTableEntryLessThan()); | ||||
int lowerIndex = (lower - cachedAddressTable.begin()); | int lowerIndex = (lower - cachedAddressTable.begin()); | ||||
int upperIndex = (upper - cachedAddressTable.begin()); | int upperIndex = (upper - cachedAddressTable.begin()); | ||||
bool inModel = (lower != upper); | bool inModel = (lower != upper); | ||||
AddressTableEntry::Type newEntryType = | AddressTableEntry::Type newEntryType = | ||||
translateTransactionType(purpose, isMine); | translateTransactionType(purpose, isMine); | ||||
switch (status) { | switch (status) { | ||||
case CT_NEW: | case CT_NEW: | ||||
▲ Show 20 Lines • Show All 319 Lines • Show Last 20 Lines |