2020-10-07 10:36:04 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Copyright (c) 2020, The Monero Project.
|
|
|
|
|
|
|
|
#ifndef FEATHER_APPCONTEXT_H
|
|
|
|
#define FEATHER_APPCONTEXT_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
#include "utils/tails.h"
|
|
|
|
#include "utils/prices.h"
|
|
|
|
#include "utils/networking.h"
|
|
|
|
#include "utils/tor.h"
|
|
|
|
#include "utils/xmrto.h"
|
2020-10-17 21:14:56 +00:00
|
|
|
#include "utils/xmrig.h"
|
2020-10-07 10:36:04 +00:00
|
|
|
#include "utils/wsclient.h"
|
|
|
|
#include "utils/txfiathistory.h"
|
|
|
|
#include "widgets/RedditPost.h"
|
|
|
|
#include "widgets/CCSEntry.h"
|
|
|
|
#include "utils/seeds.h"
|
|
|
|
#include "utils/nodes.h"
|
|
|
|
|
|
|
|
#include "libwalletqt/WalletManager.h"
|
|
|
|
#include "utils/keysfiles.h"
|
|
|
|
#include "PendingTransaction.h"
|
|
|
|
|
|
|
|
#define SUBADDRESS_LOOKAHEAD_MINOR 200
|
|
|
|
|
|
|
|
|
|
|
|
class AppContext : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AppContext(QCommandLineParser *cmdargs);
|
|
|
|
~AppContext();
|
|
|
|
bool isTails = false;
|
|
|
|
bool isWhonix = false;
|
|
|
|
bool isDebug = false;
|
2020-12-14 00:59:32 +00:00
|
|
|
|
|
|
|
// Donation config
|
|
|
|
const QString donationAddress = "47ntfT2Z5384zku39pTM6hGcnLnvpRYW2Azm87GiAAH2bcTidtq278TL6HmwyL8yjMeERqGEBs3cqC8vvHPJd1cWQrGC65f";
|
|
|
|
const int donationAmount = 25; // euro
|
|
|
|
bool donationSending = false;
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
QCommandLineParser *cmdargs;
|
|
|
|
|
|
|
|
QString coinName = "monero";
|
|
|
|
bool isTorSocks = false;
|
|
|
|
QString homeDir;
|
|
|
|
QString accountName;
|
|
|
|
QString configRoot;
|
|
|
|
QString configDirectory;
|
|
|
|
QString defaultWalletDir;
|
|
|
|
QString defaultWalletDirRoot;
|
|
|
|
QString tmpTxDescription;
|
|
|
|
|
|
|
|
QString walletPath;
|
|
|
|
QString walletPassword = "";
|
2020-10-14 20:12:32 +00:00
|
|
|
bool walletViewOnly = false;
|
2020-10-07 10:36:04 +00:00
|
|
|
NetworkType::Type networkType;
|
|
|
|
|
|
|
|
QString applicationPath;
|
|
|
|
|
|
|
|
static void createConfigDirectory(const QString &dir) ;
|
|
|
|
|
2020-12-24 13:34:37 +00:00
|
|
|
QMap<QString, int> heights;
|
2020-10-07 10:36:04 +00:00
|
|
|
QMap<NetworkType::Type, RestoreHeightLookup*> restoreHeights;
|
2020-12-24 13:34:37 +00:00
|
|
|
const quint64 kdfRounds = 1;
|
2020-10-07 10:36:04 +00:00
|
|
|
PendingTransaction::Priority tx_priority = PendingTransaction::Priority::Priority_Low;
|
|
|
|
quint32 tx_mixin = static_cast<const quint32 &>(10);
|
2020-10-12 22:01:06 +00:00
|
|
|
QString seedLanguage = "English"; // 14 word `monero-seed` only has English
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
QNetworkAccessManager *network;
|
|
|
|
QNetworkAccessManager *networkClearnet;
|
|
|
|
QNetworkProxy *networkProxy;
|
|
|
|
|
|
|
|
Tor *tor;
|
|
|
|
WSClient *ws;
|
|
|
|
XmrTo *XMRTo;
|
2020-10-17 21:14:56 +00:00
|
|
|
XmRig *XMRig;
|
2020-10-07 10:36:04 +00:00
|
|
|
Nodes *nodes;
|
|
|
|
static Prices *prices;
|
|
|
|
static WalletKeysFilesModel *wallets;
|
|
|
|
static double balance;
|
|
|
|
static QMap<QString, QString> txDescriptionCache;
|
2020-12-14 22:07:23 +00:00
|
|
|
static QMap<QString, QString> txCache;
|
2020-10-07 10:36:04 +00:00
|
|
|
static TxFiatHistory *txFiatHistory;
|
|
|
|
|
|
|
|
// libwalletqt
|
|
|
|
bool refreshed = false;
|
|
|
|
WalletManager *walletManager;
|
|
|
|
Wallet *currentWallet = nullptr;
|
|
|
|
void createWallet(FeatherSeed seed, const QString &path, const QString &password);
|
2020-10-12 22:01:06 +00:00
|
|
|
void createWalletViewOnly(const QString &path, const QString &password, const QString &address, const QString &viewkey, const QString &spendkey, quint64 restoreHeight);
|
|
|
|
void createWalletFinish(const QString &password);
|
2020-10-07 10:36:04 +00:00
|
|
|
void syncStatusUpdated(quint64 height, quint64 target);
|
|
|
|
void updateBalance();
|
|
|
|
void initTor();
|
|
|
|
void initRestoreHeights();
|
|
|
|
void initWS();
|
|
|
|
void donateBeg();
|
|
|
|
void walletClose(bool emitClosedSignal = true);
|
|
|
|
void storeWallet();
|
|
|
|
void refreshModels();
|
2020-10-14 20:12:32 +00:00
|
|
|
void setWindowTitle(bool mining = false);
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void onOpenWallet(const QString& path, const QString &password);
|
|
|
|
void onCreateTransaction(const QString &address, const double amount, const QString &description, bool all);
|
|
|
|
void onCreateTransaction(XmrToOrder *order);
|
|
|
|
void onCancelTransaction(PendingTransaction *tx, const QString &address);
|
|
|
|
void onSweepOutput(const QString &keyImage, QString address, bool churn, int outputs) const;
|
|
|
|
void onCreateTransactionError(const QString &msg);
|
|
|
|
void onOpenAliasResolve(const QString &openAlias);
|
2020-12-24 13:34:37 +00:00
|
|
|
void onSetRestoreHeight(quint64 height);
|
2020-10-07 10:36:04 +00:00
|
|
|
void onPreferredFiatCurrencyChanged(const QString &symbol);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void onWSNodes(const QJsonArray &nodes);
|
|
|
|
void onWSMessage(const QJsonObject& msg);
|
|
|
|
void onWSCCS(const QJsonArray &ccs_data);
|
|
|
|
void onWSReddit(const QJsonArray& reddit_data);
|
|
|
|
|
|
|
|
void onMoneySpent(const QString &txId, quint64 amount);
|
|
|
|
void onMoneyReceived(const QString &txId, quint64 amount);
|
|
|
|
void onUnconfirmedMoneyReceived(const QString &txId, quint64 amount);
|
|
|
|
void onWalletUpdate();
|
2020-11-23 16:57:38 +00:00
|
|
|
void onWalletRefreshed(bool success);
|
2020-10-07 10:36:04 +00:00
|
|
|
void onWalletOpened(Wallet *wallet);
|
|
|
|
void onWalletNewBlock(quint64 blockheight, quint64 targetHeight);
|
|
|
|
void onHeightRefreshed(quint64 walletHeight, quint64 daemonHeight, quint64 targetHeight);
|
|
|
|
void onTransactionCreated(PendingTransaction *tx, const QString &address, const QString &paymentId, quint32 mixin);
|
|
|
|
void onTransactionCommitted(bool status, PendingTransaction *t, const QStringList& txid);
|
|
|
|
void onConnectionStatusChanged(int status);
|
|
|
|
|
|
|
|
signals:
|
2020-12-25 14:20:39 +00:00
|
|
|
void balanceUpdated(quint64 balance, quint64 spendable);
|
2020-10-07 10:36:04 +00:00
|
|
|
void blockchainSync(int height, int target);
|
|
|
|
void refreshSync(int height, int target);
|
|
|
|
void synchronized();
|
2020-12-24 13:34:37 +00:00
|
|
|
void blockHeightWSUpdated(QMap<QString, int> heights);
|
2020-10-07 10:36:04 +00:00
|
|
|
void walletSynchronized();
|
|
|
|
void walletOpened();
|
|
|
|
void walletClosed();
|
|
|
|
void walletCreatedError(const QString &msg);
|
|
|
|
void walletCreated(Wallet *wallet);
|
|
|
|
void walletOpenedError(QString msg);
|
2020-10-21 06:45:25 +00:00
|
|
|
void walletOpenPasswordNeeded(bool invalidPassword, QString path);
|
2020-10-07 10:36:04 +00:00
|
|
|
void transactionCommitted(bool status, PendingTransaction *tx, const QStringList& txid);
|
|
|
|
void createTransactionError(QString message);
|
|
|
|
void createTransactionCancelled(QString address, double amount);
|
|
|
|
void createTransactionSuccess(PendingTransaction *tx, const QString &address, const quint32 &mixin);
|
|
|
|
void redditUpdated(QList<QSharedPointer<RedditPost>> &posts);
|
|
|
|
void nodesUpdated(QList<QSharedPointer<FeatherNode>> &nodes);
|
|
|
|
void ccsUpdated(QList<QSharedPointer<CCSEntry>> &entries);
|
|
|
|
void nodeSourceChanged(NodeSource nodeSource);
|
2020-10-14 20:12:32 +00:00
|
|
|
void XMRigDownloads(const QJsonObject &data);
|
2020-10-07 10:36:04 +00:00
|
|
|
void setCustomNodes(QList<FeatherNode> nodes);
|
|
|
|
void ccsEmpty();
|
|
|
|
void openAliasResolveError(const QString &msg);
|
|
|
|
void openAliasResolved(const QString &address, const QString &openAlias);
|
|
|
|
void setRestoreHeightError(const QString &msg);
|
2020-12-24 13:34:37 +00:00
|
|
|
void customRestoreHeightSet(int height);
|
2020-10-07 10:36:04 +00:00
|
|
|
void closeApplication();
|
|
|
|
void donationNag();
|
|
|
|
void initiateTransaction();
|
|
|
|
void endTransaction();
|
|
|
|
void walletClosing();
|
2020-10-12 22:01:06 +00:00
|
|
|
void setTitle(const QString &title); // set window title
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
private:
|
2020-12-24 13:34:37 +00:00
|
|
|
const int m_donationBoundary = 15;
|
2020-10-07 10:36:04 +00:00
|
|
|
UtilsNetworking *m_utilsNetworkingNodes;
|
|
|
|
QTimer *m_storeTimer = new QTimer(this);
|
2020-11-14 21:40:10 +00:00
|
|
|
QUrl m_wsUrl = QUrl(QStringLiteral("ws://7e6egbawekbkxzkv4244pqeqgoo4axko2imgjbedwnn6s5yb6b7oliqd.onion/ws"));
|
2020-10-07 10:36:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //FEATHER_APPCONTEXT_H
|