// Copyright 2019-2020 The Hush developers // GPLv3 #ifndef RPCCLIENT_H #define RPCCLIENT_H #include "precompiled.h" #include "camount.h" #include "datamodel.h" #include "balancestablemodel.h" #include "txtablemodel.h" #include "ui_mainwindow.h" #include "mainwindow.h" #include "liteinterface.h" #include "connection.h" #include "chatmodel.h" #include "Chat/Chat.h" #include "Model/ContactRequestChatItem.h" #include "Model/ContactItem.h" #include "contactmodel.h" using json = nlohmann::json; struct WatchedTx { QString opid; Tx tx; std::function completed; std::function error; }; class Controller { public: Controller(MainWindow* main); ~Controller(); DataModel* getModel() { return model; } Connection* getConnection() { return zrpc->getConnection(); } void setConnection(Connection* c); void refresh(bool force = false); void refreshAddresses(); int getLag(); void setLag(int lag); int _lag; void checkForUpdate(bool silent = true); void refreshHUSHPrice(); void refreshEURPrice(); void refreshBTCPrice(); void refreshCNYPrice(); void refreshRUBPrice(); void refreshCADPrice(); void refreshSGDPrice(); void refreshCHFPrice(); void refreshINRPrice(); void refreshGBPPrice(); void refreshAUDPrice(); void refreshUSDVolume(); void refreshEURVolume(); void refreshBTCVolume(); void refreshCNYVolume(); void refreshRUBVolume(); void refreshCADVolume(); void refreshSGDVolume(); void refreshCHFVolume(); void refreshINRVolume(); void refreshGBPVolume(); void refreshAUDVolume(); void refreshUSDCAP(); void refreshEURCAP(); void refreshBTCCAP(); void refreshCNYCAP(); void refreshRUBCAP(); void refreshCADCAP(); void refreshSGDCAP(); void refreshCHFCAP(); void refreshINRCAP(); void refreshGBPCAP(); void refreshAUDCAP(); void refreshChat(QListView *listWidget, QLabel *label); void refreshContacts(QListView *listWidget); void executeStandardUITransaction(Tx tx); void executeTransaction(Tx tx, bool isChatMessage, const std::function submitted, const std::function error); void fillTxJsonParams(json& params, Tx tx, bool isChatMessage); const TxTableModel* getTransactionsModel() { return transactionsTableModel; } void shutdownhushd(); void noConnection(); bool isEmbedded() { return ehushd != nullptr; } void fetchAndProcessUnspentNotes(); void encryptWallet(QString password, const std::function& cb) { zrpc->encryptWallet(password, cb); } void removeWalletEncryption(QString password, const std::function& cb) { zrpc->removeWalletEncryption(password, cb); } void saveWallet(const std::function& cb) { zrpc->saveWallet(cb); } void supplyUpdate(); void clearWallet(const std::function& cb) { zrpc->clearWallet(cb); } void shield(const std::function& cb) { zrpc->shield(cb); } void createNewZaddr(bool sapling, const std::function& cb) { unlockIfEncrypted([=] () { zrpc->createNewZaddr(sapling, cb); }, [=](){}); } void createNewTaddr(const std::function& cb) { unlockIfEncrypted([=] () { zrpc->createNewTaddr(cb); }, [=](){}); } void createNewSietchZaddr(const std::function& cb) { unlockIfEncrypted([=] () { zrpc->createNewSietchZaddr(cb); }, [=](){}); } void fetchPrivKey(QString addr, const std::function& cb) { unlockIfEncrypted([=] () { zrpc->fetchPrivKey(addr, cb); }, [=]() { cb({ {"error", "Failed to unlock wallet"} }); }); } void fetchAllPrivKeys(const std::function cb) { unlockIfEncrypted([=] () { zrpc->fetchAllPrivKeys(cb); }, [=]() { cb({ {"error", "Failed to unlock wallet"} }); }); } void fetchSeed(const std::function cb) { unlockIfEncrypted([=] () { zrpc->fetchSeed(cb); }, [=]() { cb({ {"error", "Failed to unlock wallet"} }); }); } void importZPrivKey(QString addr,const std::function& cb) { unlockIfEncrypted([=] () { zrpc->importZPrivKey(addr,cb); }, [=](){}); } void importTPrivKey(QString addr,const std::function& cb) { unlockIfEncrypted([=] () { zrpc->importTPrivKey(addr,cb); }, [=](){}); } QString getDefaultSaplingAddress(); QString getDefaultTAddress(); private: void processInfo(const json&); void refreshBalances(); void refreshTransactions(); void processUnspent (const json& reply, QMap* newBalances, QList* newUnspentOutputs); void updateUI (bool anyUnconfirmed); void updateUIBalances (); void getInfoThenRefresh (bool force); void unlockIfEncrypted (std::function cb, std::function error); QProcess* ehushd = nullptr; TxTableModel* transactionsTableModel = nullptr; BalancesTableModel* balancesTableModel = nullptr; DataModel* model; LiteInterface* zrpc; QTimer* timer; QTimer* txTimer; QTimer* priceTimer; Ui::MainWindow* ui; MainWindow* main; // Current balance in the UI. If this number updates, then refresh the UI QString currentBalance; QString sietch; }; #endif // RPCCLIENT_H