Don't use unsigned ints

remotes/1691844314220217825/master
tobtoht 3 years ago
parent 136f877778
commit 14e3422423
Signed by untrusted user: tobtoht
GPG Key ID: 1CADD27F41F45C3C

@ -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.";

@ -66,9 +66,9 @@ public:
static void createConfigDirectory(const QString &dir) ;
QMap<QString, unsigned int> heights;
QMap<QString, int> heights;
QMap<NetworkType::Type, RestoreHeightLookup*> restoreHeights;
const unsigned int kdfRounds = 1;
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
@ -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<QString, unsigned int> heights);
void blockHeightWSUpdated(QMap<QString, int> 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"));

@ -24,7 +24,7 @@ RestoreDialog::RestoreDialog(AppContext *ctx, QWidget *parent)
}
}
unsigned int RestoreDialog::getHeight() {
int RestoreDialog::getHeight() {
return ui->restoreHeightWidget->getHeight();
}

@ -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:

@ -434,7 +434,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);

@ -5,7 +5,7 @@
#include <utils/nodes.h>
#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"))

@ -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<FeatherNode> m_nodes;
QIcon m_offline;
QIcon m_online;
unsigned int m_nodeSource;
int m_nodeSource;
};
#endif //FEATHER_NODEMODEL_H

@ -19,44 +19,44 @@
struct RestoreHeightLookup {
NetworkType::Type type;
QMap<unsigned int, unsigned int> data;
QMap<int, int> 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<unsigned int> values = this->data.keys();
int blockTime = 120;
int blocksPerDay = 86400 / blockTime;
int blockCalcClearance = blocksPerDay * 5;
QList<int> 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<unsigned int, unsigned int>::iterator i;
unsigned int timestamp = 0;
QMap<int, int>::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<unsigned int, unsigned int> _data;
QMap<int, int> _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) {

@ -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));

@ -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<QString, double> m_database;
unsigned int m_genesis_timestamp;
int m_genesis_timestamp;
};
#endif //FEATHER_TXFIATHISTORY_H

@ -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,

@ -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();

@ -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<unsigned int> blockDates = m_restoreHeightLookup->data.keys();
int now = std::time(nullptr);
QList<int> 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() {

@ -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);

@ -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;

@ -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(" ");

@ -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;

@ -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();

Loading…
Cancel
Save