Browse Source

Remove unnecessary settings

pull/14/head
Aditya Kulkarni 5 years ago
parent
commit
a75f7cb40c
  1. 4
      lib/Cargo.lock
  2. 10
      src/connection.cpp
  3. 5
      src/controller.cpp
  4. 9
      src/main.cpp
  5. 83
      src/mainwindow.cpp
  6. 87
      src/settings.cpp
  7. 18
      src/settings.h
  8. 188
      src/settings.ui

4
lib/Cargo.lock

@ -1051,7 +1051,7 @@ version = "0.1.0"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"zecwalletlitelib 0.1.0",
"zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=865a72442db4ee1862fa776514da4a4a1c935b94)",
]
[[package]]
@ -2266,6 +2266,7 @@ dependencies = [
[[package]]
name = "zecwalletlitelib"
version = "0.1.0"
source = "git+https://github.com/adityapk00/zecwallet-light-cli?rev=865a72442db4ee1862fa776514da4a4a1c935b94#865a72442db4ee1862fa776514da4a4a1c935b94"
dependencies = [
"base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bellman 0.1.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)",
@ -2561,3 +2562,4 @@ dependencies = [
"checksum zcash_client_backend 0.0.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)" = "<none>"
"checksum zcash_primitives 0.0.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)" = "<none>"
"checksum zcash_proofs 0.0.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)" = "<none>"
"checksum zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=865a72442db4ee1862fa776514da4a4a1c935b94)" = "<none>"

10
src/connection.cpp

@ -43,10 +43,10 @@ void ConnectionLoader::doAutoConnect() {
auto config = std::shared_ptr<ConnectionConfig>(new ConnectionConfig());
config->dangerous = true;
config->server = QString("https://127.0.0.1:9067");
config->server = Settings::getInstance()->getSettings().server;
// Initialize the library
main->logger->write(QObject::tr("Attempting to initialize"));
main->logger->write(QObject::tr("Attempting to initialize library with ") + config->server);
// Check to see if there's an existing wallet
if (litelib_wallet_exists(Settings::getChainName().toStdString().c_str())) {
@ -172,15 +172,11 @@ void Executor::run() {
QString reply = litelib_process_response(resp);
qDebug() << "Reply=" << reply;
qDebug() << "RPC Reply=" << reply;
auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false);
if (parsed.is_discarded() || parsed.is_null()) {
emit handleError(reply);
} else {
const bool isGuiThread =
QThread::currentThread() == QCoreApplication::instance()->thread();
qDebug() << "executing RPC: isGUI=" << isGuiThread;
emit responseReady(parsed);
}
}

5
src/controller.cpp

@ -66,11 +66,6 @@ void Controller::setConnection(Connection* c) {
ui->statusBar->showMessage("Ready!");
// See if we need to remove the reindex/rescan flags from the zcash.conf file
auto zcashConfLocation = Settings::getInstance()->getZcashdConfLocation();
Settings::removeFromZcashConf(zcashConfLocation, "rescan");
Settings::removeFromZcashConf(zcashConfLocation, "reindex");
// If we're allowed to get the Zec Price, get the prices
if (Settings::getInstance()->getAllowFetchPrices())
refreshZECPrice();

9
src/main.cpp

@ -150,11 +150,6 @@ public:
parser.setApplicationDescription("Shielded desktop light wallet for Zcash");
parser.addHelpOption();
// Add an option to specify the conf file
QCommandLineOption confOption(QStringList() << "conf", "Use the zcash.conf specified instead of looking for the default one.",
"confFile");
parser.addOption(confOption);
// Positional argument will specify a zcash payment URI
parser.addPositionalArgument("zcashURI", "An optional zcash URI to pay");
@ -208,10 +203,6 @@ public:
Settings::getInstance()->setUseEmbedded(false);
// Check to see if a conf location was specified
if (parser.isSet(confOption)) {
Settings::getInstance()->setUsingZcashConf(parser.value(confOption));
}
w = new MainWindow();
w->setWindowTitle("Zecwallet Lightclient v" + QString(APP_VERSION));

83
src/mainwindow.cpp

@ -272,41 +272,10 @@ void MainWindow::setupSettingsModal() {
// Fetch prices
settings.chkFetchPrices->setChecked(Settings::getInstance()->getAllowFetchPrices());
// Use Tor
bool isUsingTor = false;
if (rpc->getConnection() != nullptr) {
isUsingTor = !rpc->getConnection()->config->proxy.isEmpty();
}
settings.chkTor->setChecked(isUsingTor);
// Connection Settings
QIntValidator validator(0, 65535);
settings.port->setValidator(&validator);
// If values are coming from zcash.conf, then disable all the fields
auto zcashConfLocation = Settings::getInstance()->getZcashdConfLocation();
if (!zcashConfLocation.isEmpty()) {
settings.confMsg->setText("Settings are being read from \n" + zcashConfLocation);
settings.hostname->setEnabled(false);
settings.port->setEnabled(false);
settings.rpcuser->setEnabled(false);
settings.rpcpassword->setEnabled(false);
}
else {
settings.confMsg->setText("No local zcash.conf found. Please configure connection manually.");
settings.hostname->setEnabled(true);
settings.port->setEnabled(true);
settings.rpcuser->setEnabled(true);
settings.rpcpassword->setEnabled(true);
}
// Load current values into the dialog
auto conf = Settings::getInstance()->getSettings();
settings.hostname->setText(conf.host);
settings.port->setText(conf.port);
settings.rpcuser->setText(conf.rpcuser);
settings.rpcpassword->setText(conf.rpcpassword);
settings.txtServer->setText(conf.server);
// Connection tab by default
settings.tabWidget->setCurrentIndex(0);
@ -315,9 +284,6 @@ void MainWindow::setupSettingsModal() {
if (!rpc->isEmbedded()) {
settings.chkRescan->setEnabled(false);
settings.chkRescan->setToolTip(tr("You're using an external zcashd. Please restart zcashd with -rescan"));
settings.chkReindex->setEnabled(false);
settings.chkReindex->setToolTip(tr("You're using an external zcashd. Please restart zcashd with -reindex"));
}
if (settingsDialog.exec() == QDialog::Accepted) {
@ -327,56 +293,17 @@ void MainWindow::setupSettingsModal() {
// Allow fetching prices
Settings::getInstance()->setAllowFetchPrices(settings.chkFetchPrices->isChecked());
if (!isUsingTor && settings.chkTor->isChecked()) {
// If "use tor" was previously unchecked and now checked
Settings::addToZcashConf(zcashConfLocation, "proxy=127.0.0.1:9050");
rpc->getConnection()->config->proxy = "proxy=127.0.0.1:9050";
QMessageBox::information(this, tr("Enable Tor"),
tr("Connection over Tor has been enabled. To use this feature, you need to restart ZecWallet."),
QMessageBox::Ok);
}
if (isUsingTor && !settings.chkTor->isChecked()) {
// If "use tor" was previously checked and now is unchecked
Settings::removeFromZcashConf(zcashConfLocation, "proxy");
rpc->getConnection()->config->proxy.clear();
QMessageBox::information(this, tr("Disable Tor"),
tr("Connection over Tor has been disabled. To fully disconnect from Tor, you need to restart ZecWallet."),
QMessageBox::Ok);
}
// Save the server
Settings::getInstance()->saveSettings(settings.txtServer->text().trimmed());
if (zcashConfLocation.isEmpty()) {
if (false /* connection needs reloading?*/) {
// Save settings
Settings::getInstance()->saveSettings(
settings.hostname->text(),
settings.port->text(),
settings.rpcuser->text(),
settings.rpcpassword->text());
Settings::getInstance()->saveSettings(settings.txtServer->text());
auto cl = new ConnectionLoader(this, rpc);
cl->loadConnection();
}
// Check to see if rescan or reindex have been enabled
bool showRestartInfo = false;
if (settings.chkRescan->isChecked()) {
Settings::addToZcashConf(zcashConfLocation, "rescan=1");
showRestartInfo = true;
}
if (settings.chkReindex->isChecked()) {
Settings::addToZcashConf(zcashConfLocation, "reindex=1");
showRestartInfo = true;
}
if (showRestartInfo) {
auto desc = tr("ZecWallet needs to restart to rescan/reindex. ZecWallet will now close, please restart ZecWallet to continue");
QMessageBox::information(this, tr("Restart ZecWallet"), desc, QMessageBox::Ok);
QTimer::singleShot(1, [=]() { this->close(); });
}
}
});
}

87
src/settings.cpp

@ -18,33 +18,24 @@ Config Settings::getSettings() {
// Load from the QT Settings.
QSettings s;
auto host = s.value("connection/host").toString();
auto port = s.value("connection/port").toString();
auto username = s.value("connection/rpcuser").toString();
auto password = s.value("connection/rpcpassword").toString();
auto server = s.value("connection/server").toString();
if (server.trimmed().isEmpty()) {
server = Settings::getDefaultServer();
}
return Config{host, port, username, password};
return Config{server};
}
void Settings::saveSettings(const QString& host, const QString& port, const QString& username, const QString& password) {
void Settings::saveSettings(const QString& server) {
QSettings s;
s.setValue("connection/host", host);
s.setValue("connection/port", port);
s.setValue("connection/rpcuser", username);
s.setValue("connection/rpcpassword", password);
s.setValue("connection/server", server);
s.sync();
// re-init to load correct settings
init();
}
void Settings::setUsingZcashConf(QString confLocation) {
if (!confLocation.isEmpty())
_confLocation = confLocation;
}
bool Settings::isTestnet() {
return _isTestnet;
}
@ -161,6 +152,10 @@ void Settings::saveRestoreTableHeader(QTableView* table, QDialog* d, QString tab
});
}
QString Settings::getDefaultServer() {
return "https://lightd-main.zecwallet.co:443/";
}
void Settings::openAddressInExplorer(QString address) {
QString url;
if (Settings::getInstance()->isTestnet()) {
@ -257,70 +252,10 @@ QString Settings::getDonationAddr() {
}
bool Settings::addToZcashConf(QString confLocation, QString line) {
QFile file(confLocation);
if (!file.open(QIODevice::ReadWrite | QIODevice::Append))
return false;
QTextStream out(&file);
out << line << "\n";
file.close();
return true;
}
bool Settings::removeFromZcashConf(QString confLocation, QString option) {
if (confLocation.isEmpty())
return false;
// To remove an option, we'll create a new file, and copy over everything but the option.
QFile file(confLocation);
if (!file.open(QIODevice::ReadOnly))
return false;
QList<QString> lines;
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
auto s = line.indexOf("=");
QString name = line.left(s).trimmed().toLower();
if (name != option) {
lines.append(line);
}
}
file.close();
QFile newfile(confLocation);
if (!newfile.open(QIODevice::ReadWrite | QIODevice::Truncate))
return false;
QTextStream out(&newfile);
for (QString line : lines) {
out << line << endl;
}
newfile.close();
return true;
}
double Settings::getMinerFee() {
return 10000;
}
double Settings::getZboardAmount() {
return 0.0001;
}
QString Settings::getZboardAddr() {
if (Settings::getInstance()->isTestnet()) {
return getDonationAddr();
}
else {
return "zs10m00rvkhfm4f7n23e4sxsx275r7ptnggx39ygl0vy46j9mdll5c97gl6dxgpk0njuptg2mn9w5s";
}
}
bool Settings::isValidSaplingPrivateKey(QString pk) {
if (isTestnet()) {
QRegExp zspkey("^secret-extended-key-test[0-9a-z]{278}$", Qt::CaseInsensitive);

18
src/settings.h

@ -4,10 +4,7 @@
#include "precompiled.h"
struct Config {
QString host;
QString port;
QString rpcuser;
QString rpcpassword;
QString server;
};
struct ToFields;
@ -29,7 +26,7 @@ public:
static Settings* getInstance();
Config getSettings();
void saveSettings(const QString& host, const QString& port, const QString& username, const QString& password);
void saveSettings(const QString& server);
bool isTestnet();
void setTestnet(bool isTestnet);
@ -65,9 +62,6 @@ public:
bool isSaplingActive();
void setUsingZcashConf(QString confLocation);
const QString& getZcashdConfLocation() { return _confLocation; }
void setZECPrice(double p) { zecPrice = p; }
double getZECPrice();
@ -98,9 +92,8 @@ public:
static QString getTokenName();
static QString getDonationAddr();
static QString getDefaultServer();
static double getMinerFee();
static double getZboardAmount();
static QString getZboardAddr();
static int getMaxMobileAppTxns() { return 30; }
@ -108,9 +101,6 @@ public:
static bool isValidAddress(QString addr);
static bool addToZcashConf(QString confLocation, QString line);
static bool removeFromZcashConf(QString confLocation, QString option);
static QString getChainName() { return QString("test"); }
static const QString labelRegExp;
@ -126,7 +116,6 @@ private:
static Settings* instance;
QString _confLocation;
QString _executable;
bool _isTestnet = false;
bool _isSyncing = false;
@ -134,7 +123,6 @@ private:
int _zcashdVersion = 0;
bool _useEmbedded = false;
bool _headless = false;
int _peerConnections = 0;
double zecPrice = 0.0;
};

188
src/settings.ui

@ -26,11 +26,11 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>zcashd connection</string>
<string>Connection</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
@ -43,13 +43,6 @@
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="minimumSize">
@ -59,69 +52,17 @@
</size>
</property>
<property name="text">
<string>Host</string>
<string>Server</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="hostname">
<widget class="QLineEdit" name="txtServer">
<property name="placeholderText">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="port">
<property name="placeholderText">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>RPC Username</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="rpcuser"/>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>RPC Password</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="rpcpassword"/>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2"/>
</item>
@ -145,7 +86,7 @@
<string>Options</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="8" column="1">
<item row="6" column="1">
<widget class="QComboBox" name="comboBoxTheme">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
@ -175,41 +116,28 @@
</item>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="label_8">
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="chkFetchPrices">
<property name="text">
<string>Connect to github on startup to check for updates</string>
<string>Fetch ZEC / USD prices</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="chkFetchPrices">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="chkCheckUpdates">
<property name="text">
<string>Fetch ZEC / USD prices</string>
<string>Check github for updates at startup</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="chkTor">
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Connect via Tor</string>
<string>Connect to github on startup to check for updates</string>
</property>
</widget>
</item>
<item row="8" column="0">
<item row="6" column="0">
<widget class="QLabel" name="label_20">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
@ -225,14 +153,20 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="chkCheckUpdates">
<property name="text">
<string>Check github for updates at startup</string>
<item row="8" column="0" colspan="2">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="9" column="0" colspan="2">
<item row="7" column="0" colspan="2">
<widget class="Line" name="line_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
@ -245,23 +179,13 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Connect to the internet to fetch ZEC prices</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="lblTor">
<property name="text">
<string>Connect to the Tor network via SOCKS proxy running on 127.0.0.1:9050. Please note that you'll have to install and run the Tor service externally.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
@ -270,37 +194,6 @@
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="5" column="0">
<widget class="QCheckBox" name="chkReindex">
<property name="text">
<string>Reindex</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Rescan the blockchain for any missing wallet transactions and to correct your wallet balance. This may take several hours. You need to restart ZecWallet for this to take effect</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="chkRescan">
<property name="text">
<string>Rescan</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="9" column="0">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -314,33 +207,26 @@
</spacer>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string/>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_11">
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Rebuild the entire blockchain from the genesis block, by rescanning all the block files. This may take several hours to days, depending on your hardware. You need to restart ZecWallet for this to take effect</string>
<string>Rescan the blockchain for any missing wallet transactions and to correct your wallet balance. This may take several hours. You need to restart ZecWallet for this to take effect</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_13">
<item row="0" column="0">
<widget class="QCheckBox" name="chkRescan">
<property name="text">
<string/>
<string>Rescan</string>
</property>
</widget>
</item>

Loading…
Cancel
Save