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/>.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef ACCOUNTINFO_H
|
|
|
|
|
#define ACCOUNTINFO_H
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include "WalletHistoryModel.h"
|
2021-07-31 17:19:34 +02:00
|
|
|
#include "Wallet.h"
|
2020-12-17 23:12:39 +01:00
|
|
|
#include "TransactionInfo.h"
|
2021-01-05 00:25:23 +01:00
|
|
|
#include <PaymentRequest.h>
|
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
|
|
|
|
2021-07-31 17:19:34 +02:00
|
|
|
class WalletSecret : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
/// The wallet-internal ID
|
|
|
|
|
Q_PROPERTY(int id READ id CONSTANT)
|
|
|
|
|
/// If this has been used yet.
|
|
|
|
|
Q_PROPERTY(bool used READ used WRITE setUsed NOTIFY usedChanged)
|
|
|
|
|
/// When used, was it used to sign with Schnorr
|
|
|
|
|
Q_PROPERTY(bool usedSchnorr READ usedSchnorr WRITE setUsedSchnorr NOTIFY usedSchnorrChanged)
|
|
|
|
|
/// The human readable address
|
|
|
|
|
Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged)
|
|
|
|
|
/// the amount of satoshis currently associated with this secret
|
|
|
|
|
Q_PROPERTY(qint64 saldo READ saldo WRITE setSaldo NOTIFY saldoChanged)
|
|
|
|
|
public:
|
|
|
|
|
explicit WalletSecret(int id, QObject *parent = nullptr);
|
|
|
|
|
|
|
|
|
|
int id() const;
|
|
|
|
|
|
|
|
|
|
bool used() const;
|
|
|
|
|
void setUsed(bool newUsed);
|
|
|
|
|
|
|
|
|
|
bool usedSchnorr() const;
|
|
|
|
|
void setUsedSchnorr(bool newUsedSchnorr);
|
|
|
|
|
|
|
|
|
|
const QString &address() const;
|
|
|
|
|
void setAddress(const QString &newAddress);
|
|
|
|
|
|
|
|
|
|
qint64 saldo() const;
|
|
|
|
|
void setSaldo(qint64 newSaldo);
|
|
|
|
|
|
|
|
|
|
// \internal
|
|
|
|
|
void populate(const Wallet::WalletSecret &secret, qint64 saldo);
|
|
|
|
|
|
|
|
|
|
Q_INVOKABLE QString fetchPrivateKey() const;
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void usedChanged();
|
|
|
|
|
void usedSchnorrChanged();
|
|
|
|
|
void addressChanged();
|
|
|
|
|
void saldoChanged();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const int m_id;
|
|
|
|
|
bool m_used = false;
|
|
|
|
|
bool m_usedSchnorr = false;
|
|
|
|
|
QString m_address;
|
|
|
|
|
qint64 m_saldo = 0;
|
|
|
|
|
};
|
|
|
|
|
|
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)
|
2020-10-14 15:12:33 +02:00
|
|
|
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
|
|
|
|
Q_PROPERTY(WalletHistoryModel* transactions READ historyModel CONSTANT)
|
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-01-07 20:10:09 +01:00
|
|
|
Q_PROPERTY(QList<QObject*> paymentRequests READ paymentRequests NOTIFY paymentRequestsChanged)
|
2021-07-31 17:19:34 +02:00
|
|
|
Q_PROPERTY(QList<WalletSecret *> walletSecrets READ walletSecrets NOTIFY walletSecretsChanged)
|
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;
|
|
|
|
|
|
2020-10-14 15:12:33 +02:00
|
|
|
WalletHistoryModel* historyModel();
|
|
|
|
|
|
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
|
|
|
*/
|
2021-01-05 00:25:23 +01:00
|
|
|
Q_INVOKABLE QObject* createPaymentRequest(QObject *parent);
|
2020-12-17 23:12:39 +01:00
|
|
|
|
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-07-31 17:19:34 +02:00
|
|
|
const QList<WalletSecret *> &walletSecrets();
|
|
|
|
|
|
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();
|
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-07-31 17:19:34 +02:00
|
|
|
void walletSecretsChanged();
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void updateWalletSecret(int id);
|
2020-10-14 15:12:33 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Wallet *m_wallet;
|
|
|
|
|
std::unique_ptr<WalletHistoryModel> m_model;
|
2021-07-31 17:19:34 +02:00
|
|
|
QList<WalletSecret*> m_walletSecrets;
|
|
|
|
|
|
|
|
|
|
friend class WalletSecret;
|
2020-10-14 15:12:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|