2024-12-24 15:09:20 +01:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
2025-01-01 17:36:58 +01:00
|
|
|
* Copyright (C) 2024-2025 Tom Zander <tom@flowee.org>
|
2024-12-24 15:09:20 +01: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 TRANSFERMANAGER_H
|
|
|
|
|
#define TRANSFERMANAGER_H
|
|
|
|
|
|
2025-01-09 17:35:57 +01:00
|
|
|
#include "NumberModel.h"
|
|
|
|
|
|
2025-01-01 17:36:58 +01:00
|
|
|
#include <FloweePay.h>
|
2024-12-24 15:09:20 +01:00
|
|
|
#include <AccountInfo.h>
|
2025-01-01 17:36:58 +01:00
|
|
|
|
2024-12-26 23:27:24 +01:00
|
|
|
#include <utils/primitives/PublicKey.h>
|
2024-12-24 15:09:20 +01:00
|
|
|
|
2024-12-29 19:13:22 +01:00
|
|
|
class PreviewTx;
|
|
|
|
|
|
2024-12-24 15:09:20 +01:00
|
|
|
class QMLTransferManager : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2024-12-26 23:27:24 +01:00
|
|
|
Q_PROPERTY(AccountInfo *fromAccount READ fromAccount WRITE setFromAccount NOTIFY fromAccountChanged FINAL)
|
|
|
|
|
Q_PROPERTY(AccountInfo *toAccount READ toAccount WRITE setToAccount NOTIFY toAccountChanged FINAL)
|
|
|
|
|
Q_PROPERTY(QList<QObject *> transactions READ transactions NOTIFY transactionsChanged FINAL)
|
|
|
|
|
Q_PROPERTY(int addressCount READ addressCount NOTIFY addressCountChanged FINAL)
|
|
|
|
|
Q_PROPERTY(int coinCount READ coinCount NOTIFY coinCountChanged FINAL)
|
2024-12-29 19:13:22 +01:00
|
|
|
Q_PROPERTY(int unsentTxCount READ unsentTxCount NOTIFY unsentTxCountChanged FINAL)
|
|
|
|
|
Q_PROPERTY(bool inputsOk READ inputsOk NOTIFY inputsOkChanged FINAL)
|
2025-01-09 17:35:57 +01:00
|
|
|
Q_PROPERTY(NumberModel* outputModel READ outputModel FINAL)
|
2024-12-24 15:09:20 +01:00
|
|
|
public:
|
|
|
|
|
QMLTransferManager(QObject *parent = nullptr);
|
|
|
|
|
|
2024-12-26 23:27:24 +01:00
|
|
|
AccountInfo *fromAccount() const;
|
|
|
|
|
void setFromAccount(AccountInfo *newFromAccount);
|
|
|
|
|
|
|
|
|
|
AccountInfo *toAccount() const;
|
|
|
|
|
void setToAccount(AccountInfo *newToAccount);
|
|
|
|
|
|
|
|
|
|
// num of addresss on the 'from' account
|
|
|
|
|
int addressCount() const;
|
|
|
|
|
// total num of coins on the 'from' account
|
|
|
|
|
int coinCount() const;
|
|
|
|
|
|
2024-12-29 19:13:22 +01:00
|
|
|
/// how many items in the transactions, which have not yet been approved.
|
|
|
|
|
int unsentTxCount() const;
|
|
|
|
|
|
|
|
|
|
bool inputsOk() const;
|
2024-12-26 23:27:24 +01:00
|
|
|
|
|
|
|
|
Q_INVOKABLE void prepare();
|
2024-12-29 19:13:22 +01:00
|
|
|
Q_INVOKABLE void send(QObject *previewTx);
|
|
|
|
|
Q_INVOKABLE void sendAll();
|
2024-12-26 23:27:24 +01:00
|
|
|
|
|
|
|
|
QList<QObject *> transactions() const;
|
|
|
|
|
|
2025-01-09 17:35:57 +01:00
|
|
|
NumberModel *outputModel();
|
|
|
|
|
|
2024-12-26 23:27:24 +01:00
|
|
|
signals:
|
|
|
|
|
void fromAccountChanged();
|
|
|
|
|
void toAccountChanged();
|
|
|
|
|
void addressCountChanged();
|
|
|
|
|
void coinCountChanged();
|
2024-12-29 19:13:22 +01:00
|
|
|
void inputsOkChanged();
|
2024-12-26 23:27:24 +01:00
|
|
|
void transactionsChanged();
|
2024-12-29 19:13:22 +01:00
|
|
|
void unsentTxCountChanged();
|
2024-12-24 15:09:20 +01:00
|
|
|
|
|
|
|
|
private:
|
2024-12-26 23:27:24 +01:00
|
|
|
void setAddressCount(int newAddressCount);
|
|
|
|
|
void setCoinCount(int newCoinCount);
|
2025-01-06 18:00:20 +01:00
|
|
|
void freePreparedTransactions();
|
2024-12-29 19:13:22 +01:00
|
|
|
Tx createTx(PreviewTx *tx);
|
2024-12-26 23:27:24 +01:00
|
|
|
|
2024-12-24 15:09:20 +01:00
|
|
|
AccountInfo *m_fromAccount = nullptr;
|
|
|
|
|
AccountInfo *m_toAccount = nullptr;
|
2024-12-26 23:27:24 +01:00
|
|
|
int m_addressCount = 0;
|
|
|
|
|
int m_coinCount = 0;
|
|
|
|
|
bool m_prepareRunning = false;
|
|
|
|
|
QList<QObject*> m_transactions; // PreviewTx instances
|
2025-01-09 17:35:57 +01:00
|
|
|
NumberModel *m_model = nullptr;
|
2024-12-26 23:27:24 +01:00
|
|
|
};
|
|
|
|
|
|
2025-01-09 17:35:57 +01:00
|
|
|
|
2024-12-26 23:27:24 +01:00
|
|
|
class Address : public QObject {
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PROPERTY(QString address READ address CONSTANT FINAL)
|
|
|
|
|
Q_PROPERTY(QString cloakedAddress READ cloakedAddress CONSTANT FINAL)
|
|
|
|
|
public:
|
|
|
|
|
explicit Address(const QString &address, const QString &cloaked, QObject *parent);
|
|
|
|
|
|
|
|
|
|
QString address() const;
|
|
|
|
|
QString cloakedAddress() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QString m_address;
|
|
|
|
|
QString m_cloaked;
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-09 17:35:57 +01:00
|
|
|
|
2024-12-26 23:27:24 +01:00
|
|
|
class PreviewTx : public QObject {
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PROPERTY(int64_t value READ value CONSTANT FINAL)
|
|
|
|
|
Q_PROPERTY(int inputCount READ inputCount CONSTANT FINAL)
|
|
|
|
|
Q_PROPERTY(QObject* from READ from CONSTANT FINAL)
|
2024-12-29 19:13:22 +01:00
|
|
|
Q_PROPERTY(bool sent READ sent NOTIFY sentChanged FINAL)
|
2025-01-01 17:36:58 +01:00
|
|
|
Q_PROPERTY(FloweePay::BroadcastStatus broadcastStatus READ broadcastStatus NOTIFY broadcastStatusChanged FINAL)
|
2025-01-09 17:35:57 +01:00
|
|
|
Q_PROPERTY(int outputCount READ outputCount WRITE setOutputCount NOTIFY outputCountChanged FINAL)
|
2024-12-26 23:27:24 +01:00
|
|
|
public:
|
|
|
|
|
PreviewTx(QObject *parent = nullptr);
|
|
|
|
|
|
2024-12-29 19:13:22 +01:00
|
|
|
bool sent() const;
|
|
|
|
|
|
2024-12-26 23:27:24 +01:00
|
|
|
int64_t value() const;
|
|
|
|
|
QObject *from() const;
|
|
|
|
|
int inputCount() const;
|
|
|
|
|
|
|
|
|
|
int64_t m_value = 0;
|
|
|
|
|
Address *m_from = nullptr;
|
2024-12-29 19:13:22 +01:00
|
|
|
bool m_sent = false;
|
2024-12-26 23:27:24 +01:00
|
|
|
|
|
|
|
|
std::vector<Wallet::OutputRef> m_utxos;
|
2024-12-29 19:13:22 +01:00
|
|
|
|
2025-01-01 17:36:58 +01:00
|
|
|
void setFinalTx(const std::shared_ptr<TxInfoObject> &finalTx);
|
|
|
|
|
|
|
|
|
|
FloweePay::BroadcastStatus broadcastStatus() const;
|
2025-01-06 18:00:20 +01:00
|
|
|
|
2025-01-09 17:35:57 +01:00
|
|
|
int outputCount() const;
|
|
|
|
|
void setOutputCount(int c);
|
|
|
|
|
|
2024-12-29 19:13:22 +01:00
|
|
|
signals:
|
|
|
|
|
void sentChanged();
|
2025-01-01 17:36:58 +01:00
|
|
|
void broadcastStatusChanged();
|
2025-01-09 17:35:57 +01:00
|
|
|
void outputCountChanged();
|
2025-01-01 17:36:58 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// the one we created
|
|
|
|
|
std::shared_ptr<TxInfoObject> m_finalTx;
|
2025-01-09 17:35:57 +01:00
|
|
|
int m_outputCount = 1;
|
2024-12-24 15:09:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|