Files
pay/PortfolioDataProvider.h
T

165 lines
4.8 KiB
C++
Raw Permalink Normal View History

2020-05-24 13:20:03 +02:00
/*
* This file is part of the Flowee project
* Copyright (C) 2020 Tom Zander <tomz@freedommail.ch>
*
* 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 PORTFOLIODATAPROVIDER_H
#define PORTFOLIODATAPROVIDER_H
#include <QObject>
#include "Wallet.h"
#include "WalletHistoryModel.h"
2020-06-12 23:37:32 +02:00
#include "BitcoinValue.h"
2020-05-24 13:20:03 +02:00
#include <TransactionBuilder.h>
#include <BroadcastTxData.h>
2020-05-24 13:20:03 +02:00
class AccountInfo : public QObject
{
Q_OBJECT
2020-06-12 20:53:01 +02:00
/// The wallet amount
Q_PROPERTY(double balance READ balance NOTIFY utxosChanged)
2020-05-24 13:20:03 +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)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(WalletHistoryModel* transactions READ historyModel CONSTANT)
public:
AccountInfo(Wallet *wallet, QObject *parent = nullptr);
/// the wallet-ID (aka the privacysegments segment-id). Application-unique.
int id() const;
/// return the current balance
2020-06-12 20:53:01 +02:00
double balance() const;
2020-05-24 13:20:03 +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;
WalletHistoryModel* historyModel();
signals:
void utxosChanged();
void nameChanged();
private:
Wallet *m_wallet;
std::unique_ptr<WalletHistoryModel> m_model;
};
2020-06-08 14:37:29 +02:00
class Payment : public QObject
{
Q_OBJECT
Q_PROPERTY(int feePerByte READ feePerByte WRITE setFeePerByte NOTIFY feePerByteChanged)
2020-06-12 23:37:32 +02:00
Q_PROPERTY(double paymentAmount READ paymentAmount WRITE setPaymentAmount NOTIFY amountChanged)
2020-06-08 14:37:29 +02:00
Q_PROPERTY(QString targetAddress READ targetAddress WRITE setTargetAddress NOTIFY targetAddressChanged)
2020-06-22 12:16:16 +02:00
// cleaned up and re-formatted
2020-06-12 23:37:32 +02:00
Q_PROPERTY(QString formattedTargetAddress READ formattedTargetAddress NOTIFY targetAddressChanged)
2020-06-13 19:22:08 +02:00
Q_PROPERTY(QString txid READ txid NOTIFY txCreated)
Q_PROPERTY(int assignedFee READ assignedFee NOTIFY txCreated)
Q_PROPERTY(int txSize READ txSize NOTIFY txCreated)
2020-06-08 14:37:29 +02:00
public:
2020-06-12 23:37:32 +02:00
Payment(Wallet *wallet, qint64 amountToPay);
2020-06-08 14:37:29 +02:00
void setFeePerByte(int sats);
int feePerByte();
2020-06-12 23:37:32 +02:00
void setPaymentAmount(double amount);
double paymentAmount();
2020-06-08 14:37:29 +02:00
/// this method throws if its not a proper address.
/// @see FloweePay::identifyString()
void setTargetAddress(const QString &address);
QString targetAddress();
2020-06-12 23:37:32 +02:00
QString formattedTargetAddress();
2020-06-08 14:37:29 +02:00
2020-06-13 19:22:08 +02:00
Q_INVOKABLE void approveAndSign();
Q_INVOKABLE void sendTx();
/// return the txid, should there be a transaction (otherwise empty string)
QString txid() const;
int assignedFee() const;
int txSize() const;
2020-06-08 14:37:29 +02:00
Wallet *wallet() const;
2020-06-13 19:22:08 +02:00
private slots:
void sentToPeer();
void txRejected(short reason, const QString &message);
2020-06-08 14:37:29 +02:00
signals:
void feePerByteChanged();
void amountChanged();
void targetAddressChanged();
/// notify how many peers we relayed the transaction to.
void sent(int count);
2020-06-08 14:37:29 +02:00
2020-06-13 19:22:08 +02:00
void txCreated();
2020-06-08 14:37:29 +02:00
private:
Wallet *m_wallet;
2020-06-13 19:22:08 +02:00
Tx m_tx;
int m_fee = 1; // in sats per byte
int m_assignedFee = 0;
2020-06-08 14:37:29 +02:00
qint64 m_paymentAmount;
QString m_address;
2020-06-12 23:37:32 +02:00
QString m_formattedTarget;
std::shared_ptr<BroadcastTxData> m_infoObject;
short m_sentPeerCount = 0;
short m_rejectedPeerCount = 0;
2020-06-08 14:37:29 +02:00
};
2020-05-24 13:20:03 +02:00
class PortfolioDataProvider : public QObject
{
Q_OBJECT
Q_PROPERTY(QList<AccountInfo*> accounts READ accounts NOTIFY accountsChanged)
Q_PROPERTY(AccountInfo* current READ current WRITE setCurrent NOTIFY currentChanged)
public:
explicit PortfolioDataProvider(QObject *parent = nullptr);
QList<AccountInfo*> accounts() const;
AccountInfo *current() const;
void setCurrent(AccountInfo *item);
2020-06-12 23:37:32 +02:00
Q_INVOKABLE QObject* startPayToAddress(const QString &address, BitcoinValue *bitcoinValue);
2020-06-08 14:37:29 +02:00
void selectDefaultWallet();
2020-05-24 13:20:03 +02:00
public slots:
void addWalletAccount(Wallet *wallet);
signals:
void accountsChanged();
void currentChanged();
private:
QList<Wallet*> m_accounts;
QList<AccountInfo*> m_accountInfos;
int m_currentAccount = -1;
};
#endif