diff --git a/src/appcontext.cpp b/src/appcontext.cpp index 92f7b0f..638705b 100644 --- a/src/appcontext.cpp +++ b/src/appcontext.cpp @@ -134,11 +134,11 @@ AppContext::AppContext(QCommandLineParser *cmdargs) { auto genesis_timestamp = this->restoreHeights[NetworkType::Type::MAINNET]->data.firstKey(); AppContext::txFiatHistory = new TxFiatHistory(genesis_timestamp, this->configDirectory); connect(this->ws, &WSClient::connectionEstablished, AppContext::txFiatHistory, &TxFiatHistory::onUpdateDatabase); - connect(AppContext::txFiatHistory, &TxFiatHistory::requestYear, [=](unsigned int year){ + connect(AppContext::txFiatHistory, &TxFiatHistory::requestYear, [=](int year){ QByteArray data = QString(R"({"cmd": "txFiatHistory", "data": {"year": %1}})").arg(year).toUtf8(); this->ws->sendMsg(data); }); - connect(AppContext::txFiatHistory, &TxFiatHistory::requestYearMonth, [=](unsigned int year, unsigned int month) { + connect(AppContext::txFiatHistory, &TxFiatHistory::requestYearMonth, [=](int year, int month) { QByteArray data = QString(R"({"cmd": "txFiatHistory", "data": {"year": %1, "month": %2}})").arg(year).arg(month).toUtf8(); this->ws->sendMsg(data); }); @@ -378,22 +378,22 @@ void AppContext::onWSMessage(const QJsonObject &msg) { auto changed = false; if(!this->heights.contains("mainnet")) { - this->heights["mainnet"] = (unsigned int) mainnet; + this->heights["mainnet"] = mainnet; changed = true; } else { if (mainnet > this->heights["mainnet"]) { - this->heights["mainnet"] = (unsigned int) mainnet; + this->heights["mainnet"] = mainnet; changed = true; } } if(!this->heights.contains("stagenet")) { - this->heights["stagenet"] = (unsigned int) stagenet; + this->heights["stagenet"] = stagenet; changed = true; } else { if (stagenet > this->heights["stagenet"]) { - this->heights["stagenet"] = (unsigned int) stagenet; + this->heights["stagenet"] = stagenet; changed = true; } } @@ -605,7 +605,7 @@ void AppContext::initRestoreHeights() { restoreHeights[NetworkType::MAINNET] = RestoreHeightLookup::fromFile(":/assets/restore_heights_monero_mainnet.txt", NetworkType::MAINNET); } -void AppContext::onSetRestoreHeight(unsigned int height){ +void AppContext::onSetRestoreHeight(quint64 height){ auto seed = this->currentWallet->getCacheAttribute("feather.seed"); if(!seed.isEmpty()) { const auto msg = "This wallet has a 14 word mnemonic seed which has the restore height embedded."; diff --git a/src/appcontext.h b/src/appcontext.h index 6670b5e..71d80f6 100644 --- a/src/appcontext.h +++ b/src/appcontext.h @@ -66,9 +66,9 @@ public: static void createConfigDirectory(const QString &dir) ; - QMap heights; + QMap heights; QMap restoreHeights; - const unsigned int kdfRounds = 1; + const quint64 kdfRounds = 1; PendingTransaction::Priority tx_priority = PendingTransaction::Priority::Priority_Low; quint32 tx_mixin = static_cast(10); QString seedLanguage = "English"; // 14 word `monero-seed` only has English @@ -90,7 +90,6 @@ public: static TxFiatHistory *txFiatHistory; // libwalletqt - unsigned int blockHeight = 0; bool refreshed = false; WalletManager *walletManager; Wallet *currentWallet = nullptr; @@ -116,7 +115,7 @@ public slots: void onSweepOutput(const QString &keyImage, QString address, bool churn, int outputs) const; void onCreateTransactionError(const QString &msg); void onOpenAliasResolve(const QString &openAlias); - void onSetRestoreHeight(unsigned int height); + void onSetRestoreHeight(quint64 height); void onPreferredFiatCurrencyChanged(const QString &symbol); private slots: @@ -142,7 +141,7 @@ signals: void blockchainSync(int height, int target); void refreshSync(int height, int target); void synchronized(); - void blockHeightWSUpdated(QMap heights); + void blockHeightWSUpdated(QMap heights); void walletSynchronized(); void walletOpened(); void walletClosed(); @@ -164,7 +163,7 @@ signals: void openAliasResolveError(const QString &msg); void openAliasResolved(const QString &address, const QString &openAlias); void setRestoreHeightError(const QString &msg); - void customRestoreHeightSet(unsigned int height); + void customRestoreHeightSet(int height); void closeApplication(); void donationNag(); void initiateTransaction(); @@ -173,7 +172,7 @@ signals: void setTitle(const QString &title); // set window title private: - const unsigned int m_donationBoundary = 15; + const int m_donationBoundary = 15; UtilsNetworking *m_utilsNetworkingNodes; QTimer *m_storeTimer = new QTimer(this); QUrl m_wsUrl = QUrl(QStringLiteral("ws://7e6egbawekbkxzkv4244pqeqgoo4axko2imgjbedwnn6s5yb6b7oliqd.onion/ws")); diff --git a/src/dialog/restoredialog.cpp b/src/dialog/restoredialog.cpp index e6363bb..48d6867 100644 --- a/src/dialog/restoredialog.cpp +++ b/src/dialog/restoredialog.cpp @@ -24,7 +24,7 @@ RestoreDialog::RestoreDialog(AppContext *ctx, QWidget *parent) } } -unsigned int RestoreDialog::getHeight() { +int RestoreDialog::getHeight() { return ui->restoreHeightWidget->getHeight(); } diff --git a/src/dialog/restoredialog.h b/src/dialog/restoredialog.h index d45ae05..60d62e3 100644 --- a/src/dialog/restoredialog.h +++ b/src/dialog/restoredialog.h @@ -24,7 +24,7 @@ Q_OBJECT public: explicit RestoreDialog(AppContext *ctx, QWidget *parent = nullptr); void initRestoreHeights(RestoreHeightLookup *lookup); - unsigned int getHeight(); + int getHeight(); ~RestoreDialog() override; signals: diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 92846d0..d33cd97 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -451,7 +451,7 @@ void MainWindow::initMenu() { // set restore height connect(ui->actionChange_restore_height, &QAction::triggered, this, &MainWindow::showRestoreHeightDialog); - connect(m_ctx, &AppContext::customRestoreHeightSet, [=](unsigned int height){ + connect(m_ctx, &AppContext::customRestoreHeightSet, [=](int height){ auto msg = QString("The restore height for this wallet has been set to %1. " "Please re-open the wallet. Feather will now quit.").arg(height); QMessageBox::information(this, "Cannot set custom restore height", msg); diff --git a/src/model/NodeModel.cpp b/src/model/NodeModel.cpp index 60ff93e..504a195 100644 --- a/src/model/NodeModel.cpp +++ b/src/model/NodeModel.cpp @@ -5,7 +5,7 @@ #include #include "appcontext.h" -NodeModel::NodeModel(unsigned int nodeSource, QObject *parent) +NodeModel::NodeModel(int nodeSource, QObject *parent) : QAbstractTableModel(parent) , m_nodeSource(nodeSource) , m_offline(QIcon(":/assets/images/expired_icon.png")) diff --git a/src/model/NodeModel.h b/src/model/NodeModel.h index ea4a42e..c128d62 100644 --- a/src/model/NodeModel.h +++ b/src/model/NodeModel.h @@ -19,7 +19,7 @@ public: COUNT }; - explicit NodeModel(unsigned int nodeSource, QObject *parent = nullptr); + explicit NodeModel(int nodeSource, QObject *parent = nullptr); int rowCount(const QModelIndex &parent) const override; int columnCount(const QModelIndex &parent) const override; @@ -34,7 +34,7 @@ private: QList m_nodes; QIcon m_offline; QIcon m_online; - unsigned int m_nodeSource; + int m_nodeSource; }; #endif //FEATHER_NODEMODEL_H diff --git a/src/utils/seeds.h b/src/utils/seeds.h index aedc518..13dd7e3 100644 --- a/src/utils/seeds.h +++ b/src/utils/seeds.h @@ -19,44 +19,44 @@ struct RestoreHeightLookup { NetworkType::Type type; - QMap data; + QMap data; explicit RestoreHeightLookup(NetworkType::Type type) : type(type) {} - unsigned int dateToRestoreHeight(unsigned int date) { + int dateToRestoreHeight(int date) { // restore height based on a given timestamp using a lookup // table. If it cannot find the date in the lookup table, it // will calculate the blockheight based off the last known // date: ((now - lastKnownDate) / blockTime) - clearance if(this->type == NetworkType::TESTNET) return 1; - unsigned int blockTime = 120; - unsigned int blocksPerDay = 86400 / blockTime; - unsigned int blockCalcClearance = blocksPerDay * 5; - QList values = this->data.keys(); + int blockTime = 120; + int blocksPerDay = 86400 / blockTime; + int blockCalcClearance = blocksPerDay * 5; + QList values = this->data.keys(); if(date <= values.at(0)) return this->data[values.at(0)]; - for(unsigned int i = 0; i != values.count(); i++) { + for(int i = 0; i != values.count(); i++) { if(values[i] > date) { return i - 1 < 0 ? this->data[values[i]] : this->data[values[i-1]] - blockCalcClearance; } } // lookup failed, calculate blockheight from last known checkpoint - unsigned int lastBlockHeightTime = values.at(values.count() - 1); - unsigned int lastBlockHeight = this->data[lastBlockHeightTime]; - unsigned int deltaTime = date - lastBlockHeightTime; - unsigned int deltaBlocks = deltaTime / blockTime; - unsigned int blockHeight = (lastBlockHeight + deltaBlocks) - blockCalcClearance; + int lastBlockHeightTime = values.at(values.count() - 1); + int lastBlockHeight = this->data[lastBlockHeightTime]; + int deltaTime = date - lastBlockHeightTime; + int deltaBlocks = deltaTime / blockTime; + int blockHeight = (lastBlockHeight + deltaBlocks) - blockCalcClearance; qDebug() << "Calculated blockheight: " << blockHeight << " from epoch " << date; return blockHeight; } - unsigned int restoreHeightToDate(unsigned int height) { + int restoreHeightToDate(int height) { // @TODO: most likely inefficient, refactor - QMap::iterator i; - unsigned int timestamp = 0; + QMap::iterator i; + int timestamp = 0; for (i = this->data.begin(); i != this->data.end(); ++i) { - unsigned int ts = i.key(); + int ts = i.key(); if (i.value() > height) return timestamp; timestamp = ts; @@ -68,7 +68,7 @@ struct RestoreHeightLookup { // initialize this class using a lookup table, e.g `:/assets/restore_heights_monero_mainnet.txt`/ auto rtn = new RestoreHeightLookup(type); auto data = Utils::barrayToString(Utils::fileOpen(fn)); - QMap _data; + QMap _data; for(const auto &line: data.split('\n')) { if(line.trimmed().isEmpty()) continue; auto spl = line.trimmed().split(':'); @@ -82,7 +82,7 @@ struct FeatherSeed { QString mnemonicSeed; QString spendKey; time_t time = 0; - unsigned int restoreHeight = 0; + int restoreHeight = 0; RestoreHeightLookup *lookup = nullptr; QString language; std::string coinName; @@ -124,7 +124,7 @@ struct FeatherSeed { return rtn; } - Wallet *writeWallet(WalletManager *manager, NetworkType::Type type, const QString &path, const QString &password, unsigned int kdfRounds) { + Wallet *writeWallet(WalletManager *manager, NetworkType::Type type, const QString &path, const QString &password, quint64 kdfRounds) { // writes both 14/25 word mnemonic seeds. Wallet *wallet = nullptr; if(this->lookup == nullptr) return wallet; @@ -136,25 +136,25 @@ struct FeatherSeed { this->restoreHeight = _seed.restoreHeight; this->spendKey = _seed.spendKey; } - wallet = manager->createDeterministicWalletFromSpendKey(path, password, this->language, type, this->spendKey, this->restoreHeight, (quint64)kdfRounds); + wallet = manager->createDeterministicWalletFromSpendKey(path, password, this->language, type, this->spendKey, this->restoreHeight, kdfRounds); wallet->setCacheAttribute("feather.seed", this->mnemonicSeed); } else { - wallet = manager->recoveryWallet(path, password, this->mnemonicSeed, "", type, this->restoreHeight, (quint64) kdfRounds); + wallet = manager->recoveryWallet(path, password, this->mnemonicSeed, "", type, this->restoreHeight, kdfRounds); } wallet->setPassword(password); return wallet; } - unsigned int setRestoreHeight() { + int setRestoreHeight() { if(this->lookup == nullptr) return 1; if(this->time == 0) return 1; - this->restoreHeight = this->lookup->dateToRestoreHeight((unsigned int)this->time); + this->restoreHeight = this->lookup->dateToRestoreHeight(this->time); return this->restoreHeight; } - unsigned int setRestoreHeight(unsigned int height) { - auto now = (unsigned int)std::time(nullptr); + int setRestoreHeight(int height) { + auto now = std::time(nullptr); auto nowClearance = 3600 * 24; auto currentBlockHeight = this->lookup->dateToRestoreHeight(now - nowClearance); if(height >= currentBlockHeight + nowClearance) { diff --git a/src/utils/txfiathistory.cpp b/src/utils/txfiathistory.cpp index 8d82271..40e2033 100644 --- a/src/utils/txfiathistory.cpp +++ b/src/utils/txfiathistory.cpp @@ -7,7 +7,7 @@ #include "txfiathistory.h" #include "utils/utils.h" -TxFiatHistory::TxFiatHistory(unsigned int genesis_timestamp, const QString &configDirectory, QObject *parent) : +TxFiatHistory::TxFiatHistory(int genesis_timestamp, const QString &configDirectory, QObject *parent) : QObject(parent), m_genesis_timestamp(genesis_timestamp), m_configDirectory(configDirectory) { @@ -15,7 +15,7 @@ TxFiatHistory::TxFiatHistory(unsigned int genesis_timestamp, const QString &conf this->loadDatabase(); } -double TxFiatHistory::get(unsigned int timestamp) { +double TxFiatHistory::get(int timestamp) { QDateTime ts; ts.setTime_t(timestamp); auto key = ts.toString("yyyyMMdd"); @@ -59,7 +59,7 @@ void TxFiatHistory::onUpdateDatabase() { auto now = QDate::currentDate(); auto nowKey = now.toString("yyyyMMdd"); - unsigned int year = genesis.toString("yyyy").toUInt(); + int year = genesis.toString("yyyy").toInt(); auto yearCurrent = now.year(); // if current year is genesis year we'll refresh regardless. @@ -71,7 +71,7 @@ void TxFiatHistory::onUpdateDatabase() { // keep local fiatTxHistory database up to date, loop for missing dates for(year; year != yearCurrent + 1; year += 1){ - for(unsigned int month = 1; month != 13; month++) { + for(int month = 1; month != 13; month++) { if(year == yearCurrent && month == now.month() && now.day() == 1) break; QDateTime _now; _now.setDate(QDate(year, month, 1)); diff --git a/src/utils/txfiathistory.h b/src/utils/txfiathistory.h index 632c581..5370bf1 100644 --- a/src/utils/txfiathistory.h +++ b/src/utils/txfiathistory.h @@ -6,17 +6,17 @@ class TxFiatHistory : public QObject { Q_OBJECT public: - explicit TxFiatHistory(unsigned int genesis_timestamp, const QString &configDirectory, QObject *parent = nullptr); + explicit TxFiatHistory(int genesis_timestamp, const QString &configDirectory, QObject *parent = nullptr); double get(const QString &date); - double get(unsigned int timestamp); + double get(int timestamp); public slots: void onUpdateDatabase(); void onWSData(const QJsonObject &data); signals: - void requestYear(unsigned int year); - void requestYearMonth(unsigned int year, unsigned int month); + void requestYear(int year); + void requestYearMonth(int year, int month); private: void loadDatabase(); @@ -25,7 +25,7 @@ private: QString m_configDirectory; bool m_initialized = false; QMap m_database; - unsigned int m_genesis_timestamp; + int m_genesis_timestamp; }; #endif //FEATHER_TXFIATHISTORY_H diff --git a/src/utils/xmrig.cpp b/src/utils/xmrig.cpp index 702f868..de353cc 100644 --- a/src/utils/xmrig.cpp +++ b/src/utils/xmrig.cpp @@ -33,7 +33,7 @@ void XmRig::stop() { } void XmRig::start(const QString &path, - unsigned int threads, + int threads, const QString &address, const QString &username, const QString &password, diff --git a/src/utils/xmrig.h b/src/utils/xmrig.h index 0835947..34ad6cf 100644 --- a/src/utils/xmrig.h +++ b/src/utils/xmrig.h @@ -23,7 +23,7 @@ public: explicit XmRig(const QString &configDir, QObject *parent = nullptr); void prepare(); - void start(const QString &path, unsigned int threads, const QString &address, const QString &username, const QString &password, bool tor = false, bool tls = true); + void start(const QString &path, int threads, const QString &address, const QString &username, const QString &password, bool tor = false, bool tls = true); void stop(); bool unpackBins(); diff --git a/src/widgets/restoreheightwidget.cpp b/src/widgets/restoreheightwidget.cpp index e9fa4a8..3d8a88a 100644 --- a/src/widgets/restoreheightwidget.cpp +++ b/src/widgets/restoreheightwidget.cpp @@ -36,8 +36,8 @@ void RestoreHeightWidget::hideSlider(){ void RestoreHeightWidget::initRestoreHeights(RestoreHeightLookup *lookup) { // init slider m_restoreHeightLookup = lookup; - auto now = (unsigned int)std::time(nullptr); - QList blockDates = m_restoreHeightLookup->data.keys(); + int now = std::time(nullptr); + QList blockDates = m_restoreHeightLookup->data.keys(); ui->restoreSlider->setMinimum(blockDates[0]); ui->restoreSlider->setMaximum(now); connect(ui->restoreSlider, &QSlider::valueChanged, this, &RestoreHeightWidget::onValueChanged); @@ -45,14 +45,14 @@ void RestoreHeightWidget::initRestoreHeights(RestoreHeightLookup *lookup) { void RestoreHeightWidget::onValueChanged(int date) { QDateTime timestamp; - timestamp.setTime_t((unsigned int) date); + timestamp.setTime_t(date); ui->label_restoreHeightDate->setText(timestamp.toString("yyyy-MM-dd")); - auto blockHeight = m_restoreHeightLookup->dateToRestoreHeight((unsigned int) date); + auto blockHeight = m_restoreHeightLookup->dateToRestoreHeight(date); ui->lineEdit_restoreHeight->setText(QString::number(blockHeight)); } -unsigned int RestoreHeightWidget::getHeight() { - return ui->lineEdit_restoreHeight->text().toUInt(); +int RestoreHeightWidget::getHeight() { + return ui->lineEdit_restoreHeight->text().toInt(); } RestoreHeightWidget::~RestoreHeightWidget() { diff --git a/src/widgets/restoreheightwidget.h b/src/widgets/restoreheightwidget.h index 7235943..9ed0d8d 100644 --- a/src/widgets/restoreheightwidget.h +++ b/src/widgets/restoreheightwidget.h @@ -20,9 +20,9 @@ class RestoreHeightWidget : public QWidget public: explicit RestoreHeightWidget(QWidget *parent = nullptr); void initRestoreHeights(RestoreHeightLookup *lookup); - unsigned int getHeight(); + int getHeight(); void hideSlider(); - ~RestoreHeightWidget(); + ~RestoreHeightWidget() override; private slots: void onValueChanged(int date); diff --git a/src/wizard/createwalletseed.h b/src/wizard/createwalletseed.h index 5f8389e..dcd64c4 100644 --- a/src/wizard/createwalletseed.h +++ b/src/wizard/createwalletseed.h @@ -40,7 +40,7 @@ private: Ui::CreateWalletSeedPage *ui; QString m_mnemonic; - unsigned int m_restoreHeight; + int m_restoreHeight; bool m_roulette = false; int m_rouletteSpin = 15; diff --git a/src/wizard/restorewallet.cpp b/src/wizard/restorewallet.cpp index 385dc1b..b5cda94 100644 --- a/src/wizard/restorewallet.cpp +++ b/src/wizard/restorewallet.cpp @@ -31,7 +31,7 @@ RestorePage::RestorePage(AppContext *ctx, QWidget *parent) : auto data = Utils::fileOpen(":/assets/mnemonic_25_english.txt"); for(const auto &seed_word: data.split('\n')) m_words25 << seed_word; - for(unsigned int i = 0; i != 2048; i++) + for(int i = 0; i != 2048; i++) m_words14 << QString::fromStdString(wordlist::english.get_word(i)); // @@ -109,7 +109,7 @@ void RestorePage::cleanupPage() const {} bool RestorePage::validatePage() { ui->label_errorString->hide(); auto errStyle = "QTextEdit{border: 1px solid red;}"; - unsigned int restoreHeight = ui->restoreHeightWidget->getHeight(); + int restoreHeight = ui->restoreHeightWidget->getHeight(); auto seed = ui->seedEdit->toPlainText().replace("\n", "").replace("\r", "").trimmed(); auto seedSplit = seed.split(" "); diff --git a/src/wizard/restorewallet.h b/src/wizard/restorewallet.h index 3a3049d..9f0d8e0 100644 --- a/src/wizard/restorewallet.h +++ b/src/wizard/restorewallet.h @@ -33,7 +33,7 @@ private: QLabel *topLabel; Ui::RestorePage *ui; - unsigned int m_mode = 14; + int m_mode = 14; QStringList m_words14; QStringList m_words25; QStringListModel *m_completer14Model = nullptr; diff --git a/src/wizard/viewonlywallet.cpp b/src/wizard/viewonlywallet.cpp index d2ddce0..2c6d8cf 100644 --- a/src/wizard/viewonlywallet.cpp +++ b/src/wizard/viewonlywallet.cpp @@ -72,7 +72,7 @@ bool ViewOnlyPage::validatePage() { ui->lineEdit_viewkey->setStyleSheet(""); ui->label_errorString->hide(); - unsigned int restoreHeight = ui->restoreHeightWidget->getHeight(); + int restoreHeight = ui->restoreHeightWidget->getHeight(); auto spendkey = ui->lineEdit_spendkey->text().trimmed(); auto viewkey = ui->lineEdit_viewkey->text().trimmed(); auto address = ui->lineEdit_address->text().trimmed();