wowlet/src/appcontext.h

247 lines
9.0 KiB
C
Raw Normal View History

// SPDX-License-Identifier: BSD-3-Clause
2020-12-26 19:56:06 +00:00
// Copyright (c) 2020-2021, The Monero Project.
2021-03-30 10:52:29 +01:00
#ifndef WOWLET_APPCONTEXT_H
#define WOWLET_APPCONTEXT_H
#include <QObject>
#include <QProcess>
#include <QNetworkAccessManager>
#include <QTimer>
#include "utils/tails.h"
2021-01-21 01:38:21 +00:00
#include "utils/whonix.h"
#include "utils/prices.h"
#include "utils/networking.h"
#include "utils/tor.h"
#include "utils/xmrig.h"
#include "utils/wsclient.h"
#include "utils/txfiathistory.h"
2021-03-30 10:52:29 +01:00
#include "utils/WowletSeed.h"
#include "widgets/RedditPost.h"
#include "widgets/ForumPost.h"
#include "widgets/CCSEntry.h"
2021-01-20 21:13:51 +00:00
#include "utils/RestoreHeightLookup.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);
2020-12-28 04:39:20 +00:00
~AppContext() override;
bool isTails = false;
bool isWhonix = false;
bool isAndroid = false;
bool isLinux = false;
bool isMac = false;
bool isWindows = false;
bool isDebug = false;
static bool isQML;
bool androidDebug = false;
2020-12-14 00:59:32 +00:00
// Donation config
2021-02-20 07:56:00 +00:00
const QString donationAddress = "Wo3MWeKwtA918DU4c69hVSNgejdWFCRCuWjShRY66mJkU2Hv58eygJWDJS1MNa2Ge5M1WjUkGHuLqHkweDxwZZU42d16v94mP";
2020-12-14 00:59:32 +00:00
const int donationAmount = 25; // euro
QCommandLineParser *cmdargs;
2020-12-21 20:34:36 +00:00
QString coinName = "wownero";
bool isTorSocks = false;
QString pathGenericData;
QString homeDir;
QString accountName;
QString configRoot;
QString configDirectory;
2021-04-13 10:39:12 +01:00
QString configDirectoryVR;
QString defaultWalletDir;
QString defaultWalletDirRoot;
QString tmpTxDescription;
// https://git.wownero.com/wowlet/wowlet-backend/
QString backendHost = "6wku2m4zrv6j666crlo7lzofv6ud6enzllyhou3ijeigpukymi37caad.onion";
unsigned int backendPort = 80;
bool backendTLS = false;
QString backendWSUrl;
QString backendHTTPUrl;
QString walletPath;
QString walletPassword = "";
QString walletName;
bool walletViewOnly = false;
NetworkType::Type networkType;
Q_PROPERTY(QString walletName MEMBER walletName);
QString applicationPath;
static void createConfigDirectory(const QString &dir) ;
2020-12-24 13:34:37 +00:00
QMap<QString, int> heights;
QMap<NetworkType::Type, RestoreHeightLookup*> restoreHeights;
2020-12-24 13:34:37 +00:00
const quint64 kdfRounds = 1;
PendingTransaction::Priority tx_priority = PendingTransaction::Priority::Priority_Low;
quint32 tx_mixin = static_cast<const quint32 &>(10);
QString seedLanguage = "English"; // 14 word `monero-seed` only has English
2021-04-08 02:40:44 +01:00
// turn this on if you want to auto commit tx's after they have
// been created. Caution while using this setting is advised. This
// probably also breaks the default QtWidgets GUI. It is meant for
// alternative users of AppContext.
bool autoCommitTx = false;
QNetworkAccessManager *network;
QNetworkAccessManager *networkClearnet;
2020-12-28 04:39:20 +00:00
QNetworkProxy *networkProxy{};
2020-12-28 04:39:20 +00:00
Tor *tor{};
WSClient *ws;
XmRig *XMRig;
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;
static TxFiatHistory *txFiatHistory;
QJsonArray yellowPagesData;
QJsonObject versionPending;
// libwalletqt
bool refreshed = false;
WalletManager *walletManager;
Wallet *currentWallet = nullptr;
2021-03-30 10:52:29 +01:00
void createWallet(WowletSeed seed, const QString &path, const QString &password);
Q_INVOKABLE void createWalletWithoutSpecifyingSeed(const QString &name, const QString &password);
void createWalletViewOnly(const QString &path, const QString &password, const QString &address, const QString &viewkey, const QString &spendkey, quint64 restoreHeight);
void createWalletFinish(const QString &password);
void syncStatusUpdated(quint64 height, quint64 target);
void updateBalance();
Q_INVOKABLE void initTor();
Q_INVOKABLE void initWS();
void initRestoreHeights();
void refreshModels();
void setWindowTitle(bool mining = false);
2021-01-19 22:39:31 +00:00
// Closes the currently opened wallet
2021-04-06 01:20:42 +01:00
Q_INVOKABLE void closeWallet(bool emitClosedSignal = true, bool storeWallet = false);
2021-01-19 22:39:31 +00:00
void storeWallet();
Q_INVOKABLE QVariantList listWallets() {
m_walletKeysFilesModel->refresh();
QVariantList list;
for(const WalletKeysFiles &wallet: m_walletKeysFilesModel->listWallets())
list << wallet.toVariant();
return list;
}
Q_INVOKABLE QString displayAmount(quint64 amount) {
return Utils::balanceFormat(amount);
}
public slots:
Q_INVOKABLE void onOpenWallet(const QString& path, const QString &password);
void onCreateTransaction(QString address, quint64 amount, const QString description, bool all);
2021-01-26 23:55:27 +00:00
void onCreateTransactionMultiDest(const QVector<QString> &addresses, const QVector<quint64> &amounts, const QString &description);
void onCancelTransaction(PendingTransaction *tx, const QVector<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);
void onPreferredFiatCurrencyChanged(const QString &symbol);
2021-04-06 01:20:42 +01:00
Q_INVOKABLE void onAskReceivingPIN();
Q_INVOKABLE void onLookupReceivingPIN(QString pin);
2021-04-08 02:40:44 +01:00
Q_INVOKABLE QString getAddress(quint32 accountIndex, quint32 addressIndex);
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 onWSForum(const QJsonArray& forum_data);
void onMoneySpent(const QString &txId, quint64 amount);
void onMoneyReceived(const QString &txId, quint64 amount);
void onUnconfirmedMoneyReceived(const QString &txId, quint64 amount);
void onWalletUpdate();
void onWalletRefreshed(bool success);
void onWalletOpened(Wallet *wallet);
void onWalletNewBlock(quint64 blockheight, quint64 targetHeight);
void onHeightRefreshed(quint64 walletHeight, quint64 daemonHeight, quint64 targetHeight);
2021-01-26 23:55:27 +00:00
void onTransactionCreated(PendingTransaction *tx, const QVector<QString> &address);
void onTransactionCommitted(bool status, PendingTransaction *t, const QStringList& txid);
signals:
2021-01-19 22:39:31 +00:00
// Emitted just before the wallet is closed
void walletAboutToClose();
// Emitted after a wallet has been closed
void walletClosed();
2020-12-25 14:20:39 +00:00
void balanceUpdated(quint64 balance, quint64 spendable);
void balanceUpdatedFormatted(QString fmt);
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-12-30 03:58:17 +00:00
void walletRefreshed();
void walletOpened(Wallet *wallet);
void walletCreatedError(const QString &msg);
void walletCreated(Wallet *wallet);
void walletOpenedError(QString msg);
2020-10-21 07:45:25 +01:00
void walletOpenPasswordNeeded(bool invalidPassword, QString path);
void transactionCommitted(bool status, PendingTransaction *tx, const QStringList& txid);
void createTransactionError(QString message);
2021-01-26 23:55:27 +00:00
void createTransactionCancelled(const QVector<QString> &address, double amount);
void createTransactionSuccess(PendingTransaction *tx, const QVector<QString> &address);
void wsConnected();
void wsDisconnected();
void redditUpdated(QList<QSharedPointer<RedditPost>> &posts);
void forumUpdated(QList<QSharedPointer<ForumPost>> &posts);
2021-03-30 10:52:29 +01:00
void nodesUpdated(QList<QSharedPointer<WowletNode>> &nodes);
void ccsUpdated(QList<QSharedPointer<CCSEntry>> &entries);
void suchWowUpdated(const QJsonArray &such_data);
void yellowUpdated();
void nodeSourceChanged(NodeSource nodeSource);
void XMRigDownloads(const QJsonObject &data);
void WownerodDownloads(const QJsonObject &data);
2021-04-06 01:20:42 +01:00
void pinLookupReceived(QString address, QString pin);
void pinLookupErrorReceived();
void pinReceived(QString pin);
2021-03-30 10:52:29 +01:00
void setCustomNodes(QList<WowletNode> nodes);
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);
void closeApplication();
void donationNag();
void initiateTransaction();
void endTransaction();
void setTitle(const QString &title); // set window title
void versionOutdated(QString version_string, QJsonObject data);
private:
WalletKeysFilesModel *m_walletKeysFilesModel;
2020-12-24 13:34:37 +00:00
const int m_donationBoundary = 15;
2020-12-28 04:39:20 +00:00
QTimer m_storeTimer;
QTimer m_hibernateTimer;
std::chrono::seconds m_hibernateDetectInterval{300};
std::chrono::time_point<std::chrono::steady_clock> m_hibernatePreviousTime;
void setupPathsUnix();
void setupPathsWindows();
void setupPathsAndroid();
void setupPathsTails();
};
2021-03-30 10:52:29 +01:00
#endif //WOWLET_APPCONTEXT_H