Files
pay/AccountInfo.h
T

182 lines
6.8 KiB
C++
Raw Permalink Normal View History

2020-10-14 15:12:33 +02:00
/*
* This file is part of the Flowee project
2022-04-06 18:18:49 +02:00
* Copyright (C) 2020-2022 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/>.
*/
#ifndef ACCOUNTINFO_H
#define ACCOUNTINFO_H
#include <QObject>
2021-10-31 15:19:35 +01:00
#include "PaymentRequest.h"
#include "TransactionInfo.h"
#include "Wallet.h"
2020-10-14 15:12:33 +02:00
#include "WalletHistoryModel.h"
2021-10-29 18:20:42 +02:00
#include "WalletSecretsModel.h"
#include "qtimer.h"
2021-10-31 15:19:35 +01:00
#include <QDateTime>
2020-10-14 15:12:33 +02:00
#include <memory>
2020-12-17 23:12:39 +01:00
class TransactionInfo;
2020-10-14 15:12:33 +02:00
class AccountInfo : public QObject
{
Q_OBJECT
/// The wallet amount
2020-11-06 22:15:03 +01:00
Q_PROPERTY(double balanceConfirmed READ balanceConfirmed NOTIFY balanceChanged)
Q_PROPERTY(double balanceUnconfirmed READ balanceUnconfirmed NOTIFY balanceChanged)
Q_PROPERTY(double balanceImmature READ balanceImmature NOTIFY balanceChanged)
2020-10-14 15:12:33 +02:00
Q_PROPERTY(int unspentOutputCount READ unspentOutputCount NOTIFY utxosChanged)
Q_PROPERTY(int historicalOutputCount READ historicalOutputCount NOTIFY utxosChanged)
Q_PROPERTY(int id READ id CONSTANT)
2020-10-17 17:34:40 +02:00
Q_PROPERTY(int lastBlockSynched READ lastBlockSynched NOTIFY lastBlockSynchedChanged)
2021-11-03 13:58:31 +01:00
Q_PROPERTY(QDateTime lastBlockSynchedTime READ lastBlockSynchedTime NOTIFY lastBlockSynchedChanged)
2022-04-06 18:18:49 +02:00
/// Return a user-readable indication of the amount of time 'behind' this account is
Q_PROPERTY(QString timeBehind READ timeBehind NOTIFY lastBlockSynchedChanged)
2020-10-14 15:12:33 +02:00
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(WalletHistoryModel* transactions READ historyModel NOTIFY modelsChanged)
Q_PROPERTY(WalletSecretsModel* secrets READ secretsModel NOTIFY modelsChanged)
2020-10-19 14:05:38 +02:00
Q_PROPERTY(bool isDefaultWallet READ isDefaultWallet WRITE setDefaultWallet NOTIFY isDefaultWalletChanged)
2021-04-21 15:17:08 +02:00
Q_PROPERTY(bool isUserOwned READ userOwnedWallet NOTIFY userOwnedChanged)
2021-05-05 14:27:45 +02:00
Q_PROPERTY(bool isSingleAddressAccount READ isSingleAddressAccount CONSTANT)
2021-10-29 18:20:42 +02:00
Q_PROPERTY(bool isHDWallet READ isHDWallet CONSTANT)
2021-12-04 11:25:27 +01:00
Q_PROPERTY(bool isArchived READ isArchived WRITE setIsArchived NOTIFY isArchivedChanged)
2021-01-07 20:10:09 +01:00
Q_PROPERTY(QList<QObject*> paymentRequests READ paymentRequests NOTIFY paymentRequestsChanged)
2021-10-21 17:04:20 +02:00
Q_PROPERTY(QString mnemonic READ hdWalletMnemonic CONSTANT)
Q_PROPERTY(QString hdDerivationPath READ hdDerivationPath CONSTANT)
2021-10-31 15:19:35 +01:00
Q_PROPERTY(QDateTime lastMinedTransaction READ lastMinedTransaction NOTIFY balanceChanged)
Q_PROPERTY(bool hasFreshTransactions READ hasFreshTransactions WRITE setHasFreshTransactions NOTIFY hasFreshTransactionsChanged)
Q_PROPERTY(bool needsPinToPay READ needsPinToPay NOTIFY encryptionChanged)
Q_PROPERTY(bool needsPinToOpen READ needsPinToOpen NOTIFY encryptionChanged)
Q_PROPERTY(bool isDecrypted READ isDecrypted NOTIFY encryptionChanged)
2020-10-14 15:12:33 +02:00
public:
AccountInfo(Wallet *wallet, QObject *parent = nullptr);
/// the wallet-ID (aka the privacysegments segment-id). Application-unique.
int id() const;
2020-11-06 22:15:03 +01:00
/// return the current balance, but only confirmed and spendable
double balanceConfirmed() const;
/// return the unconfirmed balance, only not yet confirmed outputs are counted
double balanceUnconfirmed() const;
/// Return the balanace of coinbases we are not allowed to spend yet
double balanceImmature() const;
2020-10-14 15:12:33 +02:00
/// return the amount of UTXOs that hold money
int unspentOutputCount() const;
/// return the amount of UTXOs ever created for this account.
int historicalOutputCount() const;
void setName(const QString &name);
QString name() const;
2020-10-17 17:34:40 +02:00
int lastBlockSynched() const;
2021-11-03 13:58:31 +01:00
QDateTime lastBlockSynchedTime() const;
2022-04-06 18:18:49 +02:00
QString timeBehind() const;
2020-10-17 17:34:40 +02:00
2020-10-14 15:12:33 +02:00
WalletHistoryModel* historyModel();
2021-10-29 18:20:42 +02:00
WalletSecretsModel* secretsModel();
2020-10-14 15:12:33 +02:00
2021-07-14 15:54:10 +02:00
/**
* Sets a wallet to be the first to open (aka default) wallet.
*/
2020-10-19 14:05:38 +02:00
void setDefaultWallet(bool isDefault);
2021-07-14 15:54:10 +02:00
/// returns if a wallet is the main, first, wallet
2020-10-19 14:05:38 +02:00
bool isDefaultWallet();
2021-04-21 15:17:08 +02:00
// maps to Wallet::userOwnedWallet
bool userOwnedWallet();
2021-01-07 20:10:09 +01:00
/**
* All payment requests that are created for this account.
*/
QList<QObject*> paymentRequests() const;
2020-12-17 23:12:39 +01:00
Q_INVOKABLE TransactionInfo* txInfo(int walletIndex, QObject *parent);
2021-01-07 20:10:09 +01:00
/**
* Start a new payment-request
2021-01-13 17:41:29 +01:00
* QML callers should pass a panel as parent, preferably one that is loaded.
2021-01-07 20:10:09 +01:00
*/
Q_INVOKABLE QObject* createPaymentRequest(QObject *parent);
2020-12-17 23:12:39 +01:00
Q_INVOKABLE void encryptPinToPay(const QString &password);
Q_INVOKABLE void encryptPinToOpen(const QString &password);
2022-05-18 20:16:34 +02:00
Q_INVOKABLE bool decrypt(const QString &password);
2022-07-14 14:43:38 +02:00
/// Remove all secrets from the encrypted wallet.
Q_INVOKABLE void closeWallet();
2021-04-21 17:17:47 +02:00
Wallet *wallet() const {
return m_wallet;
}
2021-05-05 14:27:45 +02:00
bool isSingleAddressAccount() const;
2021-10-31 15:19:35 +01:00
/// return true if the wallet is based on a master key and mnemonic seed.
2021-10-29 18:20:42 +02:00
bool isHDWallet() const;
2021-10-31 15:19:35 +01:00
/// Return the mnemonic seed that is the basis of this wallet.
2021-10-21 17:04:20 +02:00
QString hdWalletMnemonic() const;
2021-10-31 15:19:35 +01:00
/// Return the derivation base path that is the basis of this wallet.
2021-10-21 17:04:20 +02:00
QString hdDerivationPath() const;
2021-10-31 15:19:35 +01:00
/// Return the model that shares more info about the wallets private keys
2021-10-30 15:23:43 +02:00
WalletSecretsModel *secretsModel() const;
2021-07-31 17:19:34 +02:00
2021-10-31 15:19:35 +01:00
/// Returns the date of the last timestamped transaction
QDateTime lastMinedTransaction() const;
2021-12-04 11:25:27 +01:00
bool isArchived() const;
void setIsArchived(bool newIsArchived);
bool hasFreshTransactions() const;
void setHasFreshTransactions(bool fresh);
bool needsPinToPay() const;
bool needsPinToOpen() const;
bool isDecrypted() const;
2020-10-14 15:12:33 +02:00
signals:
2020-11-06 22:15:03 +01:00
void balanceChanged();
2020-10-14 15:12:33 +02:00
void utxosChanged();
void nameChanged();
2020-10-17 17:34:40 +02:00
void lastBlockSynchedChanged();
2022-04-06 18:18:49 +02:00
void timeBehindChanged();
2020-10-19 14:05:38 +02:00
void isDefaultWalletChanged();
2021-01-07 20:10:09 +01:00
void paymentRequestsChanged();
2021-04-21 15:17:08 +02:00
void userOwnedChanged();
2021-12-04 11:25:27 +01:00
void isArchivedChanged();
void hasFreshTransactionsChanged();
void encryptionChanged();
void modelsChanged();
private slots:
// callback from wallet
void balanceHasChanged();
void walletEncryptionChanged();
2021-07-31 17:19:34 +02:00
2020-10-14 15:12:33 +02:00
private:
Wallet * const m_wallet;
QTimer *m_closeWalletTimer = nullptr;
2020-10-14 15:12:33 +02:00
std::unique_ptr<WalletHistoryModel> m_model;
2021-10-29 18:20:42 +02:00
std::unique_ptr<WalletSecretsModel> m_secretsModel;
int m_lastTxHeight = -1; ///< last seen tx blockheight.
bool m_hasFreshTransactions = false;
2021-07-31 17:19:34 +02:00
friend class WalletSecret;
2020-10-14 15:12:33 +02:00
};
#endif