2024-10-02 23:04:38 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
|
|
|
|
* Copyright (C) 2024 Tom Zander <tom@flowee.org>
|
|
|
|
|
*
|
|
|
|
|
* 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 QMLSWEEPHANDLER_H
|
|
|
|
|
#define QMLSWEEPHANDLER_H
|
|
|
|
|
|
2024-10-03 17:55:26 +02:00
|
|
|
|
2024-10-05 21:13:14 +02:00
|
|
|
#include <FloweePay.h>
|
|
|
|
|
#include <utils/TransactionBuilder.h>
|
|
|
|
|
#include <TxInfoObject.h>
|
|
|
|
|
#include <utils/primitives/PrivateKey.h>
|
|
|
|
|
#include <utils/streaming/ConstBuffer.h>
|
2024-10-04 16:56:34 +02:00
|
|
|
#include "TransactionsFetcher.h"
|
2024-10-05 21:13:14 +02:00
|
|
|
#include <AccountInfo.h>
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
2024-10-02 23:04:38 +02:00
|
|
|
|
2024-10-03 14:29:05 +02:00
|
|
|
class TransactionsFetcher;
|
2024-10-04 16:56:34 +02:00
|
|
|
class AccountInfo;
|
|
|
|
|
|
2024-10-02 23:04:38 +02:00
|
|
|
class QMLSweepHandler : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PROPERTY(QString privKey READ privKey WRITE setPrivKey NOTIFY privKeyChanged FINAL)
|
|
|
|
|
Q_PROPERTY(Error error READ error NOTIFY errorChanged FINAL)
|
2024-10-04 16:56:34 +02:00
|
|
|
Q_PROPERTY(AccountInfo *account READ currentAccount WRITE setCurrentAccount NOTIFY currentAccountChanged)
|
2024-10-05 21:13:14 +02:00
|
|
|
Q_PROPERTY(FloweePay::BroadcastStatus broadcastStatus READ broadcastStatus NOTIFY broadcastStatusChanged)
|
2024-10-06 14:07:33 +02:00
|
|
|
Q_PROPERTY(QString sweepAddress READ sweepAddress WRITE setSweepAddress NOTIFY sweepAddressChanged FINAL)
|
2024-10-06 00:17:04 +02:00
|
|
|
Q_PROPERTY(QString targetAddress READ targetAddress WRITE setTargetAddress NOTIFY targetAddressChanged FINAL)
|
|
|
|
|
Q_PROPERTY(bool prepared READ prepared WRITE setPrepared NOTIFY preparedChanged FINAL)
|
|
|
|
|
Q_PROPERTY(double sweepTotal READ sweepTotal NOTIFY sweepTotalChanged FINAL)
|
2024-10-06 14:07:33 +02:00
|
|
|
Q_PROPERTY(int numTokensFound READ numTokensFound NOTIFY numTokensFoundChanged FINAL)
|
|
|
|
|
Q_PROPERTY(int numOutputsFound READ numOutputsFound NOTIFY numOutputsFoundChanged FINAL)
|
2024-10-14 19:55:53 +02:00
|
|
|
/// progress in 0 ... 1000
|
|
|
|
|
Q_PROPERTY(int downloadProgress READ downloadProgress NOTIFY downloadProgressChanged FINAL)
|
2024-10-02 23:04:38 +02:00
|
|
|
public:
|
|
|
|
|
QMLSweepHandler(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
|
|
enum Error {
|
|
|
|
|
NoError,
|
|
|
|
|
InvalidInput,
|
2024-10-03 14:29:05 +02:00
|
|
|
NoBackendFound, // no indexer services
|
2024-10-04 16:56:34 +02:00
|
|
|
FileError,
|
|
|
|
|
DataInconsistency // specifically the data we got from the indexer.
|
2024-10-02 23:04:38 +02:00
|
|
|
};
|
2024-10-06 22:36:10 +02:00
|
|
|
Q_ENUM(Error)
|
2024-10-02 23:04:38 +02:00
|
|
|
|
|
|
|
|
QString privKey() const;
|
|
|
|
|
void setPrivKey(const QString &newPrivKey);
|
|
|
|
|
|
|
|
|
|
Error error() const;
|
|
|
|
|
void setError(Error newError);
|
|
|
|
|
|
2024-10-04 16:56:34 +02:00
|
|
|
AccountInfo *currentAccount() const;
|
|
|
|
|
void setCurrentAccount(AccountInfo *account);
|
|
|
|
|
|
|
|
|
|
Q_INVOKABLE void markUserApproved();
|
|
|
|
|
|
2024-10-05 21:13:14 +02:00
|
|
|
FloweePay::BroadcastStatus broadcastStatus() const;
|
|
|
|
|
|
2024-10-06 00:17:04 +02:00
|
|
|
QString targetAddress() const;
|
|
|
|
|
void setTargetAddress(const QString &newTargetAddress);
|
|
|
|
|
|
|
|
|
|
bool prepared() const;
|
|
|
|
|
void setPrepared(bool newPrepared);
|
|
|
|
|
|
|
|
|
|
double sweepTotal() const;
|
|
|
|
|
void setSweepTotal(double newSweepTotal);
|
|
|
|
|
|
2024-10-06 14:07:33 +02:00
|
|
|
int numTokensFound() const;
|
|
|
|
|
void setNumTokensFound(int newNumTokensFound);
|
|
|
|
|
|
|
|
|
|
int numOutputsFound() const;
|
|
|
|
|
void setNumOutputsFound(int newNumOutputsFound);
|
|
|
|
|
|
|
|
|
|
QString sweepAddress() const;
|
|
|
|
|
void setSweepAddress(const QString &newSweepAddress);
|
|
|
|
|
|
2024-10-14 19:55:53 +02:00
|
|
|
int downloadProgress() const;
|
|
|
|
|
void setDownloadProgress(int newDownloadProgress);
|
|
|
|
|
|
2024-10-02 23:04:38 +02:00
|
|
|
signals:
|
|
|
|
|
void privKeyChanged();
|
|
|
|
|
void errorChanged();
|
2024-10-04 16:56:34 +02:00
|
|
|
void currentAccountChanged();
|
2024-10-05 21:13:14 +02:00
|
|
|
void broadcastStatusChanged();
|
2024-10-06 00:17:04 +02:00
|
|
|
void targetAddressChanged();
|
|
|
|
|
void preparedChanged();
|
|
|
|
|
void sweepTotalChanged();
|
2024-10-06 14:07:33 +02:00
|
|
|
void numTokensFoundChanged();
|
|
|
|
|
void numOutputsFoundChanged();
|
|
|
|
|
void sweepAddressChanged();
|
2024-10-02 23:04:38 +02:00
|
|
|
|
2024-10-14 19:55:53 +02:00
|
|
|
void downloadProgressChanged();
|
|
|
|
|
|
2024-10-02 23:04:38 +02:00
|
|
|
private slots:
|
|
|
|
|
void start();
|
2024-10-03 17:55:26 +02:00
|
|
|
void startTxBuilder(const QList<TransactionsFetcher::Output> &result);
|
2024-10-02 23:04:38 +02:00
|
|
|
|
|
|
|
|
private:
|
2024-10-04 16:56:34 +02:00
|
|
|
AccountInfo *m_account = nullptr;
|
2024-10-02 23:04:38 +02:00
|
|
|
QString m_privKey;
|
2024-10-06 14:07:33 +02:00
|
|
|
QString m_sweepAddress;
|
2024-10-06 00:17:04 +02:00
|
|
|
QString m_targetAddress;
|
2024-10-02 23:04:38 +02:00
|
|
|
Streaming::ConstBuffer m_addressHash;
|
|
|
|
|
Error m_error = NoError;
|
2024-10-04 16:56:34 +02:00
|
|
|
PrivateKey m_key;
|
|
|
|
|
TransactionBuilder m_builder;
|
2024-10-03 14:29:05 +02:00
|
|
|
TransactionsFetcher *m_fetcher;
|
2024-10-05 21:13:14 +02:00
|
|
|
std::shared_ptr<TxInfoObject> m_infoObject;
|
2024-10-06 00:17:04 +02:00
|
|
|
bool m_prepared = false; // tx is prepared
|
|
|
|
|
bool m_txBroadcastStarted = false;
|
|
|
|
|
double m_sweepTotal = 0;
|
2024-10-06 14:07:33 +02:00
|
|
|
|
|
|
|
|
int m_numTokensFound = 0;
|
|
|
|
|
int m_numOutputsFound = 0;
|
2024-10-14 19:55:53 +02:00
|
|
|
int m_downloadProgress = 0; // from 0 to 1000 percent.
|
2024-10-02 23:04:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|