mirror of
https://github.com/monero-project/monero-gui.git
synced 2025-01-22 10:44:46 +00:00
Merge pull request #2623
c9900c0
SubaddressAccount: drop useless getAll 'update' default argument (xiphon)e0ab9aa
SubaddressAccount: fix use-after-free bug (xiphon)
This commit is contained in:
commit
598de0f03f
4 changed files with 44 additions and 28 deletions
|
@ -36,49 +36,57 @@ SubaddressAccount::SubaddressAccount(Monero::SubaddressAccount *subaddressAccoun
|
||||||
getAll();
|
getAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Monero::SubaddressAccountRow*> SubaddressAccount::getAll(bool update) const
|
void SubaddressAccount::getAll() const
|
||||||
{
|
{
|
||||||
qDebug(__FUNCTION__);
|
qDebug(__FUNCTION__);
|
||||||
|
|
||||||
emit refreshStarted();
|
emit refreshStarted();
|
||||||
|
|
||||||
if(update)
|
{
|
||||||
|
QWriteLocker locker(&m_lock);
|
||||||
m_rows.clear();
|
m_rows.clear();
|
||||||
|
|
||||||
if (m_rows.empty()){
|
|
||||||
for (auto &row: m_subaddressAccountImpl->getAll()) {
|
for (auto &row: m_subaddressAccountImpl->getAll()) {
|
||||||
m_rows.append(row);
|
m_rows.append(row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit refreshFinished();
|
emit refreshFinished();
|
||||||
return m_rows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Monero::SubaddressAccountRow * SubaddressAccount::getRow(int index) const
|
bool SubaddressAccount::getRow(int index, std::function<void (Monero::SubaddressAccountRow &)> callback) const
|
||||||
{
|
{
|
||||||
return m_rows.at(index);
|
QReadLocker locker(&m_lock);
|
||||||
|
|
||||||
|
if (index < 0 || index >= m_rows.size())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(*m_rows.value(index));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubaddressAccount::addRow(const QString &label) const
|
void SubaddressAccount::addRow(const QString &label) const
|
||||||
{
|
{
|
||||||
m_subaddressAccountImpl->addRow(label.toStdString());
|
m_subaddressAccountImpl->addRow(label.toStdString());
|
||||||
getAll(true);
|
getAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubaddressAccount::setLabel(quint32 accountIndex, const QString &label) const
|
void SubaddressAccount::setLabel(quint32 accountIndex, const QString &label) const
|
||||||
{
|
{
|
||||||
m_subaddressAccountImpl->setLabel(accountIndex, label.toStdString());
|
m_subaddressAccountImpl->setLabel(accountIndex, label.toStdString());
|
||||||
getAll(true);
|
getAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubaddressAccount::refresh() const
|
void SubaddressAccount::refresh() const
|
||||||
{
|
{
|
||||||
m_subaddressAccountImpl->refresh();
|
m_subaddressAccountImpl->refresh();
|
||||||
getAll(true);
|
getAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
quint64 SubaddressAccount::count() const
|
quint64 SubaddressAccount::count() const
|
||||||
{
|
{
|
||||||
|
QReadLocker locker(&m_lock);
|
||||||
|
|
||||||
return m_rows.size();
|
return m_rows.size();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#include <wallet/api/wallet2_api.h>
|
#include <wallet/api/wallet2_api.h>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QReadWriteLock>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
|
@ -38,8 +39,8 @@ class SubaddressAccount : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Q_INVOKABLE QList<Monero::SubaddressAccountRow*> getAll(bool update = false) const;
|
Q_INVOKABLE void getAll() const;
|
||||||
Q_INVOKABLE Monero::SubaddressAccountRow * getRow(int index) const;
|
Q_INVOKABLE bool getRow(int index, std::function<void (Monero::SubaddressAccountRow &)> callback) const;
|
||||||
Q_INVOKABLE void addRow(const QString &label) const;
|
Q_INVOKABLE void addRow(const QString &label) const;
|
||||||
Q_INVOKABLE void setLabel(quint32 accountIndex, const QString &label) const;
|
Q_INVOKABLE void setLabel(quint32 accountIndex, const QString &label) const;
|
||||||
Q_INVOKABLE void refresh() const;
|
Q_INVOKABLE void refresh() const;
|
||||||
|
@ -54,6 +55,7 @@ public slots:
|
||||||
private:
|
private:
|
||||||
explicit SubaddressAccount(Monero::SubaddressAccount * subaddressAccountImpl, QObject *parent);
|
explicit SubaddressAccount(Monero::SubaddressAccount * subaddressAccountImpl, QObject *parent);
|
||||||
friend class Wallet;
|
friend class Wallet;
|
||||||
|
mutable QReadWriteLock m_lock;
|
||||||
Monero::SubaddressAccount * m_subaddressAccountImpl;
|
Monero::SubaddressAccount * m_subaddressAccountImpl;
|
||||||
mutable QList<Monero::SubaddressAccountRow*> m_rows;
|
mutable QList<Monero::SubaddressAccountRow*> m_rows;
|
||||||
};
|
};
|
||||||
|
|
|
@ -438,7 +438,7 @@ bool Wallet::refresh()
|
||||||
bool result = m_walletImpl->refresh();
|
bool result = m_walletImpl->refresh();
|
||||||
m_history->refresh(currentSubaddressAccount());
|
m_history->refresh(currentSubaddressAccount());
|
||||||
m_subaddress->refresh(currentSubaddressAccount());
|
m_subaddress->refresh(currentSubaddressAccount());
|
||||||
m_subaddressAccount->getAll(true);
|
m_subaddressAccount->getAll();
|
||||||
if (result)
|
if (result)
|
||||||
emit updated();
|
emit updated();
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -59,22 +59,28 @@ QVariant SubaddressAccountModel::data(const QModelIndex &index, int role) const
|
||||||
if (!index.isValid() || index.row() < 0 || (unsigned)index.row() >= m_subaddressAccount->count())
|
if (!index.isValid() || index.row() < 0 || (unsigned)index.row() >= m_subaddressAccount->count())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
Monero::SubaddressAccountRow * sr = m_subaddressAccount->getRow(index.row());
|
QVariant result;
|
||||||
|
|
||||||
QVariant result = "";
|
bool found = m_subaddressAccount->getRow(index.row(), [&result, &role](const Monero::SubaddressAccountRow &row) {
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case SubaddressAccountAddressRole:
|
case SubaddressAccountAddressRole:
|
||||||
result = QString::fromStdString(sr->getAddress());
|
result = QString::fromStdString(row.getAddress());
|
||||||
break;
|
break;
|
||||||
case SubaddressAccountLabelRole:
|
case SubaddressAccountLabelRole:
|
||||||
result = QString::fromStdString(sr->getLabel());
|
result = QString::fromStdString(row.getLabel());
|
||||||
break;
|
break;
|
||||||
case SubaddressAccountBalanceRole:
|
case SubaddressAccountBalanceRole:
|
||||||
result = QString::fromStdString(sr->getBalance());
|
result = QString::fromStdString(row.getBalance());
|
||||||
break;
|
break;
|
||||||
case SubaddressAccountUnlockedBalanceRole:
|
case SubaddressAccountUnlockedBalanceRole:
|
||||||
result = QString::fromStdString(sr->getUnlockedBalance());
|
result = QString::fromStdString(row.getUnlockedBalance());
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
qCritical() << "Unimplemented role" << role;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!found) {
|
||||||
|
qCritical("%s: internal error: invalid index %d", __FUNCTION__, index.row());
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue