2020-10-14 15:12:33 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
2021-01-05 00:25:23 +01:00
|
|
|
* Copyright (C) 2020-2021 Tom Zander <tom@flowee.org>
|
2020-10-14 15:12:33 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
#include "AccountInfo.h"
|
|
|
|
|
#include "Wallet.h"
|
|
|
|
|
#include "WalletHistoryModel.h"
|
2020-12-17 23:12:39 +01:00
|
|
|
#include "FloweePay.h"
|
2020-10-14 15:12:33 +02:00
|
|
|
|
|
|
|
|
#include <p2p/PrivacySegment.h>
|
|
|
|
|
|
|
|
|
|
AccountInfo::AccountInfo(Wallet *wallet, QObject *parent)
|
|
|
|
|
: QObject(parent),
|
|
|
|
|
m_wallet(wallet)
|
|
|
|
|
{
|
|
|
|
|
connect(wallet, SIGNAL(utxosChanged()), this, SIGNAL(utxosChanged()), Qt::QueuedConnection);
|
2020-11-06 22:15:03 +01:00
|
|
|
connect(wallet, SIGNAL(balanceChanged()), this, SIGNAL(balanceChanged()), Qt::QueuedConnection);
|
2020-10-17 17:34:40 +02:00
|
|
|
connect(wallet, SIGNAL(lastBlockSynchedChanged()), this, SIGNAL(lastBlockSynchedChanged()), Qt::QueuedConnection);
|
2021-01-07 20:10:09 +01:00
|
|
|
connect(wallet, SIGNAL(paymentRequestsChanged()), this, SIGNAL(paymentRequestsChanged()), Qt::QueuedConnection);
|
2020-10-14 15:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AccountInfo::id() const
|
|
|
|
|
{
|
|
|
|
|
return m_wallet->segment()->segmentId();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-06 22:15:03 +01:00
|
|
|
double AccountInfo::balanceConfirmed() const
|
2020-10-14 15:12:33 +02:00
|
|
|
{
|
2020-11-06 22:15:03 +01:00
|
|
|
return static_cast<double>(m_wallet->balanceConfirmed());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double AccountInfo::balanceUnconfirmed() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<double>(m_wallet->balanceUnconfirmed());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double AccountInfo::balanceImmature() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<double>(m_wallet->balanceImmature());
|
2020-10-14 15:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AccountInfo::unspentOutputCount() const
|
|
|
|
|
{
|
|
|
|
|
return m_wallet->unspentOutputCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AccountInfo::historicalOutputCount() const
|
|
|
|
|
{
|
|
|
|
|
return m_wallet->historicalOutputCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AccountInfo::setName(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
if (m_wallet->name() == name)
|
|
|
|
|
return;
|
|
|
|
|
m_wallet->setName(name);
|
|
|
|
|
emit nameChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AccountInfo::name() const
|
|
|
|
|
{
|
|
|
|
|
return m_wallet->name();
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-17 17:34:40 +02:00
|
|
|
int AccountInfo::lastBlockSynched() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_wallet->segment())
|
|
|
|
|
return 0;
|
|
|
|
|
return m_wallet->segment()->lastBlockSynched();
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 15:12:33 +02:00
|
|
|
WalletHistoryModel *AccountInfo::historyModel()
|
|
|
|
|
{
|
|
|
|
|
if (m_model == nullptr)
|
|
|
|
|
m_model.reset(new WalletHistoryModel(m_wallet, this));
|
|
|
|
|
return m_model.get();
|
|
|
|
|
}
|
2020-10-19 14:05:38 +02:00
|
|
|
|
|
|
|
|
void AccountInfo::setDefaultWallet(bool isDefault)
|
|
|
|
|
{
|
|
|
|
|
auto segment =m_wallet->segment();
|
|
|
|
|
if (!segment)
|
|
|
|
|
return;
|
|
|
|
|
if (segment->priority() == isDefault ? PrivacySegment::First : PrivacySegment::Normal)
|
|
|
|
|
return;
|
|
|
|
|
segment->setPriority(isDefault ? PrivacySegment::First : PrivacySegment::Normal);
|
|
|
|
|
emit isDefaultWalletChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AccountInfo::isDefaultWallet()
|
|
|
|
|
{
|
|
|
|
|
auto segment =m_wallet->segment();
|
|
|
|
|
if (!segment)
|
|
|
|
|
return false;
|
|
|
|
|
return segment->priority() == PrivacySegment::First;
|
|
|
|
|
}
|
2020-12-17 23:12:39 +01:00
|
|
|
|
2021-04-21 15:17:08 +02:00
|
|
|
bool AccountInfo::userOwnedWallet()
|
|
|
|
|
{
|
|
|
|
|
return m_wallet->userOwnedWallet();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-07 20:10:09 +01:00
|
|
|
QList<QObject *> AccountInfo::paymentRequests() const
|
|
|
|
|
{
|
|
|
|
|
QList<QObject*> answer;
|
2021-04-21 15:17:08 +02:00
|
|
|
for (auto *pr : m_wallet->paymentRequests()) {
|
2021-01-07 20:10:09 +01:00
|
|
|
answer.append(pr);
|
|
|
|
|
}
|
|
|
|
|
return answer;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 23:12:39 +01:00
|
|
|
TransactionInfo* AccountInfo::txInfo(int walletIndex, QObject *parent)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(parent);
|
|
|
|
|
auto info = new TransactionInfo(parent);
|
|
|
|
|
m_wallet->fetchTransactionInfo(info, walletIndex);
|
|
|
|
|
return info;
|
|
|
|
|
}
|
2021-01-05 00:25:23 +01:00
|
|
|
|
|
|
|
|
QObject *AccountInfo::createPaymentRequest(QObject *parent)
|
|
|
|
|
{
|
|
|
|
|
return new PaymentRequest(m_wallet, parent);
|
|
|
|
|
}
|
2021-05-05 14:27:45 +02:00
|
|
|
|
|
|
|
|
bool AccountInfo::isSingleAddressAccount() const
|
|
|
|
|
{
|
|
|
|
|
return m_wallet->isSingleAddressWallet();
|
|
|
|
|
}
|