Browse Source

Merge pull request #26 from DenioD/denio

denio to dev
pull/14/head
Denio 5 years ago
committed by GitHub
parent
commit
271aca4377
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. BIN
      Silentdragonlite
  2. 37
      Silentdragonlite_resource.rc
  3. 6
      lib/Cargo.lock
  4. 2
      lib/Cargo.toml
  5. 3
      silentdragon-lite.pro
  6. 4
      src/connection.cpp
  7. 145
      src/controller.cpp
  8. 59
      src/controller.h
  9. 1
      src/datamodel.cpp
  10. 30
      src/datamodel.h
  11. 165
      src/encryption.ui
  12. 37
      src/liteinterface.cpp
  13. 6
      src/liteinterface.h
  14. 215
      src/mainwindow.cpp
  15. 5
      src/mainwindow.h
  16. 29
      src/mainwindow.ui
  17. 14
      src/sendtab.cpp
  18. 14
      src/settings.h
  19. 2
      src/version.h

BIN
Silentdragonlite

Binary file not shown.

37
Silentdragonlite_resource.rc

@ -0,0 +1,37 @@
#include <windows.h>
IDI_ICON1 ICON DISCARDABLE "/home/denio/SilentDragonLite/res/icon.ico"
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,0,0,0
PRODUCTVERSION 0,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "\0"
VALUE "FileDescription", "\0"
VALUE "FileVersion", "0.0.0.0\0"
VALUE "LegalCopyright", "\0"
VALUE "OriginalFilename", "Silentdragonlite.exe\0"
VALUE "ProductName", "Silentdragonlite\0"
VALUE "ProductVersion", "0.0.0.0\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1200
END
END
/* End of Version info */

6
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)",
"silentdragonlitelib 0.1.0 (git+https://github.com/DenioD/silentdragonlite-cli?rev=0b09f20990195a2a44bce871cd0bb293eaf38b33)",
"silentdragonlitelib 0.1.0 (git+https://github.com/DenioD/silentdragonlite-cli?rev=58839270ace26bf08d351375d0d945c2dd5527f9)",
]
[[package]]
@ -1467,7 +1467,7 @@ dependencies = [
[[package]]
name = "silentdragonlitelib"
version = "0.1.0"
source = "git+https://github.com/DenioD/silentdragonlite-cli?rev=0b09f20990195a2a44bce871cd0bb293eaf38b33#0b09f20990195a2a44bce871cd0bb293eaf38b33"
source = "git+https://github.com/DenioD/silentdragonlite-cli?rev=58839270ace26bf08d351375d0d945c2dd5527f9#58839270ace26bf08d351375d0d945c2dd5527f9"
dependencies = [
"base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bellman 0.1.0 (git+https://github.com/DenioD/librustzcash.git?rev=caaee693c47c2ee9ecd1e1546b8fe3c714f342bc)",
@ -2481,7 +2481,7 @@ dependencies = [
"checksum serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "2f72eb2a68a7dc3f9a691bfda9305a1c017a6215e5a4545c258500d2099a37c2"
"checksum serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)" = "691b17f19fc1ec9d94ec0b5864859290dff279dbd7b03f017afda54eb36c3c35"
"checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d"
"checksum silentdragonlitelib 0.1.0 (git+https://github.com/DenioD/silentdragonlite-cli?rev=0b09f20990195a2a44bce871cd0bb293eaf38b33)" = "<none>"
"checksum silentdragonlitelib 0.1.0 (git+https://github.com/DenioD/silentdragonlite-cli?rev=58839270ace26bf08d351375d0d945c2dd5527f9)" = "<none>"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7"
"checksum sodiumoxide 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585232e78a4fc18133eef9946d3080befdf68b906c51b621531c37e91787fa2b"

2
lib/Cargo.toml

@ -11,4 +11,4 @@ crate-type = ["staticlib"]
[dependencies]
libc = "0.2.58"
lazy_static = "1.4.0"
silentdragonlitelib = { git = "https://github.com/DenioD/silentdragonlite-cli", rev = "0b09f20990195a2a44bce871cd0bb293eaf38b33" }
silentdragonlitelib = { git = "https://github.com/DenioD/silentdragonlite-cli", rev = "58839270ace26bf08d351375d0d945c2dd5527f9" }

3
silentdragon-lite.pro

@ -93,6 +93,7 @@ HEADERS += \
lib/silentdragonlitelib.h
FORMS += \
src/encryption.ui \
src/mainwindow.ui \
src/migration.ui \
src/newseed.ui \
@ -147,6 +148,8 @@ else:win32: librust.target = $$PWD/lib/target/x86_64-pc-windows-gnu/release/s
unix: librust.commands = $(MAKE) -C $$PWD/lib
else:win32: librust.commands = $(MAKE) -C $$PWD/lib winrelease
librust.depends = lib/Cargo.toml lib/src/lib.rs
librustclean.commands = "rm -rf $$PWD/lib/target"
distclean.depends += librustclean

4
src/connection.cpp

@ -174,7 +174,7 @@ void Executor::run() {
QString reply = litelib_process_response(resp);
qDebug() << "RPC 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);
@ -213,7 +213,7 @@ void Connection::doRPC(const QString cmd, const QString args, const std::functio
return;
}
qDebug() << "Doing RPC: " << cmd;
//qDebug() << "Doing RPC: " << cmd;
// Create a runner.
auto runner = new Executor(cmd, args);

145
src/controller.cpp

@ -162,8 +162,6 @@ void Controller::getInfoThenRefresh(bool force) {
model->setLatestBlock(curBlock);
ui->blockHeight->setText(QString::number(curBlock));
qDebug() << "Refreshing. Full update: " << doUpdate;
// Connected, so display checkmark.
auto tooltip = Settings::getInstance()->getSettings().server + "\n" + QString::fromStdString(reply.dump());
QIcon i(":/icons/res/connected.gif");
@ -185,6 +183,14 @@ void Controller::getInfoThenRefresh(bool force) {
// See if recurring payments needs anything
Recurring::getInstance()->processPending(main);
// Check if the wallet is locked/encrypted
zrpc->fetchWalletEncryptionStatus([=] (const json& reply) {
bool isEncrypted = reply["encrypted"].get<json::boolean_t>();
bool isLocked = reply["locked"].get<json::boolean_t>();
model->setEncryptionStatus(isEncrypted, isLocked);
});
if ( doUpdate ) {
// Something changed, so refresh everything.
refreshBalances();
@ -273,6 +279,34 @@ void Controller::processUnspent(const json& reply, QMap<QString, CAmount>* balan
processFn(reply["pending_utxos"].get<json::array_t>());
};
void Controller::updateUIBalances() {
CAmount balT = getModel()->getBalT();
CAmount balZ = getModel()->getBalZ();
CAmount balVerified = getModel()->getBalVerified();
// Reduce the BalanceZ by the pending outgoing amount. We're adding
// here because totalPending is already negative for outgoing txns.
balZ = balZ + getModel()->getTotalPending();
CAmount balTotal = balT + balZ;
CAmount balAvailable = balT + balVerified;
// Balances table
ui->balSheilded ->setText(balZ.toDecimalhushString());
ui->balVerified ->setText(balVerified.toDecimalhushString());
ui->balTransparent->setText(balT.toDecimalhushString());
ui->balTotal ->setText(balTotal.toDecimalhushString());
ui->balSheilded ->setToolTip(balZ.toDecimalUSDString());
ui->balVerified ->setToolTip(balVerified.toDecimalUSDString());
ui->balTransparent->setToolTip(balT.toDecimalUSDString());
ui->balTotal ->setToolTip(balTotal.toDecimalUSDString());
// Send tab
ui->txtAvailablehush->setText(balAvailable.toDecimalhushString());
ui->txtAvailableUSD->setText(balAvailable.toDecimalUSDString());
}
void Controller::refreshBalances() {
if (!zrpc->haveConnection())
return noConnection();
@ -283,29 +317,18 @@ void Controller::refreshBalances() {
CAmount balZ = CAmount::fromqint64(reply["zbalance"].get<json::number_unsigned_t>());
CAmount balVerified = CAmount::fromqint64(reply["verified_zbalance"].get<json::number_unsigned_t>());
CAmount balTotal = balT + balZ;
CAmount balAvailable = balT + balVerified;
model->setBalT(balT);
model->setBalZ(balZ);
model->setBalVerified(balVerified);
// This is for the websockets
AppDataModel::getInstance()->setBalances(balT, balZ);
// This is for the datamodel
CAmount balAvailable = balT + balVerified;
model->setAvailableBalance(balAvailable);
// Balances table
ui->balSheilded ->setText(balZ.toDecimalhushString());
ui->balVerified ->setText(balVerified.toDecimalhushString());
ui->balTransparent->setText(balT.toDecimalhushString());
ui->balTotal ->setText(balTotal.toDecimalhushString());
ui->balSheilded ->setToolTip(balZ.toDecimalUSDString());
ui->balVerified ->setToolTip(balVerified.toDecimalUSDString());
ui->balTransparent->setToolTip(balT.toDecimalUSDString());
ui->balTotal ->setToolTip(balTotal.toDecimalUSDString());
// Send tab
ui->txtAvailablehush->setText(balAvailable.toDecimalhushString());
ui->txtAvailableUSD->setText(balAvailable.toDecimalUSDString());
updateUIBalances();
});
// 2. Get the UTXOs
@ -414,11 +437,59 @@ void Controller::refreshTransactions() {
}
// Calculate the total unspent amount that's pending. This will need to be
// shown in the UI so the user can keep track of pending funds
CAmount totalPending;
for (auto txitem : txdata) {
if (txitem.confirmations == 0) {
for (auto item: txitem.items) {
totalPending = totalPending + item.amount;
}
}
}
getModel()->setTotalPending(totalPending);
// Update UI Balance
updateUIBalances();
// Update model data, which updates the table view
transactionsTableModel->replaceData(txdata);
});
}
// If the wallet is encrpyted and locked, we need to unlock it
void Controller::unlockIfEncrypted(std::function<void(void)> cb, std::function<void(void)> error) {
auto encStatus = getModel()->getEncryptionStatus();
if (encStatus.first && encStatus.second) {
// Wallet is encrypted and locked. Ask for the password and unlock.
QString password = QInputDialog::getText(main, main->tr("Wallet Password"),
main->tr("Your wallet is encrypted.\nPlease enter your wallet password"), QLineEdit::Password);
if (password.isEmpty()) {
error();
return;
}
zrpc->unlockWallet(password, [=](json reply) {
if (isJsonSuccess(reply)) {
cb();
// Refresh the wallet so the encryption status is now in sync.
refresh(true);
} else {
QMessageBox::critical(main, main->tr("Wallet Decryption Failed"),
QString::fromStdString(reply["error"].get<json::string_t>()),
QMessageBox::Ok
);
error();
}
});
} else {
// Not locked, so just call the function
cb();
}
}
/**
* Execute a transaction with the standard UI. i.e., standard status bar message and standard error
* handling
@ -444,21 +515,25 @@ void Controller::executeStandardUITransaction(Tx tx) {
void Controller::executeTransaction(Tx tx,
const std::function<void(QString txid)> submitted,
const std::function<void(QString txid, QString errStr)> error) {
// First, create the json params
json params = json::array();
fillTxJsonParams(params, tx);
std::cout << std::setw(2) << params << std::endl;
zrpc->sendTransaction(QString::fromStdString(params.dump()), [=](const json& reply) {
if (reply.find("txid") == reply.end()) {
error("", "Couldn't understand Response: " + QString::fromStdString(reply.dump()));
} else {
QString txid = QString::fromStdString(reply["txid"].get<json::string_t>());
submitted(txid);
}
},
[=](QString errStr) {
error("", errStr);
unlockIfEncrypted([=] () {
// First, create the json params
json params = json::array();
fillTxJsonParams(params, tx);
std::cout << std::setw(2) << params << std::endl;
zrpc->sendTransaction(QString::fromStdString(params.dump()), [=](const json& reply) {
if (reply.find("txid") == reply.end()) {
error("", "Couldn't understand Response: " + QString::fromStdString(reply.dump()));
} else {
QString txid = QString::fromStdString(reply["txid"].get<json::string_t>());
submitted(txid);
}
},
[=](QString errStr) {
error("", errStr);
});
}, [=]() {
error("", main->tr("Failed to unlock wallet"));
});
}
@ -467,7 +542,7 @@ void Controller::checkForUpdate(bool silent) {
if (!zrpc->haveConnection())
return noConnection();
QUrl cmcURL("https://api.github.com/repos/MyHush/SilentDragonLite/releases");
QUrl cmcURL("https://api.github.com/repos/DenioD/SilentDragonLite/releases");
QNetworkRequest req;
req.setUrl(cmcURL);
@ -515,7 +590,7 @@ void Controller::checkForUpdate(bool silent) {
.arg(currentVersion.toString()),
QMessageBox::Yes, QMessageBox::Cancel);
if (ans == QMessageBox::Yes) {
QDesktopServices::openUrl(QUrl("https://github.com/MyHush/SilentDragonLite/releases"));
QDesktopServices::openUrl(QUrl("https://github.com/DenioD/SilentDragonLite/releases"));
} else {
// If the user selects cancel, don't bother them again for this version
s.setValue("update/lastversion", maxVersion.toString());

59
src/controller.h

@ -37,8 +37,7 @@ public:
void checkForUpdate(bool silent = true);
void refreshZECPrice();
//void getZboardTopics(std::function<void(QMap<QString, QString>)> cb);
void executeStandardUITransaction(Tx tx);
void executeTransaction(Tx tx,
@ -53,11 +52,52 @@ public:
void noConnection();
bool isEmbedded() { return ehushd != nullptr; }
void createNewZaddr(bool sapling, const std::function<void(json)>& cb) { zrpc->createNewZaddr(sapling, cb); }
void createNewTaddr(const std::function<void(json)>& cb) { zrpc->createNewTaddr(cb); }
void fetchPrivKey(QString addr, const std::function<void(json)>& cb) { zrpc->fetchPrivKey(addr, cb); }
void fetchAllPrivKeys(const std::function<void(json)> cb) { zrpc->fetchAllPrivKeys(cb); }
void encryptWallet(QString password, const std::function<void(json)>& cb) {
zrpc->encryptWallet(password, cb);
}
void removeWalletEncryption(QString password, const std::function<void(json)>& cb) {
zrpc->removeWalletEncryption(password, cb); }
void saveWallet(const std::function<void(json)>& cb) { zrpc->saveWallet(cb); }
void createNewZaddr(bool sapling, const std::function<void(json)>& cb) {
unlockIfEncrypted([=] () {
zrpc->createNewZaddr(sapling, cb);
}, [=](){});
}
void createNewTaddr(const std::function<void(json)>& cb) {
unlockIfEncrypted([=] () {
zrpc->createNewTaddr(cb);
}, [=](){});
}
void fetchPrivKey(QString addr, const std::function<void(json)>& cb) {
unlockIfEncrypted([=] () {
zrpc->fetchPrivKey(addr, cb);
},
[=]() {
cb({ {"error", "Failed to unlock wallet"} });
});
}
void fetchAllPrivKeys(const std::function<void(json)> cb) {
unlockIfEncrypted([=] () {
zrpc->fetchAllPrivKeys(cb);
},
[=]() {
cb({ {"error", "Failed to unlock wallet"} });
});
}
void fetchSeed(const std::function<void(json)> cb) {
unlockIfEncrypted([=] () {
zrpc->fetchSeed(cb);
},
[=]() {
cb({ {"error", "Failed to unlock wallet"} });
});
}
// void importZPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb) { zrpc->importZPrivKey(addr, rescan, cb); }
// void importTPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb) { zrpc->importTPrivKey(addr, rescan, cb); }
@ -72,8 +112,11 @@ private:
void processUnspent (const json& reply, QMap<QString, CAmount>* newBalances, QList<UnspentOutput>* newUnspentOutputs);
void updateUI (bool anyUnconfirmed);
void updateUIBalances ();
void getInfoThenRefresh (bool force);
void getInfoThenRefresh(bool force);
void unlockIfEncrypted (std::function<void(void)> cb, std::function<void(void)> error);
QProcess* ehushd = nullptr;

1
src/datamodel.cpp

@ -24,6 +24,7 @@ DataModel::~DataModel() {
}
void DataModel::setLatestBlock(int blockHeight) {
QReadLocker locker(lock);
this->latestBlock = blockHeight;
}

30
src/datamodel.h

@ -26,7 +26,10 @@ public:
void markAddressUsed(QString address);
void setLatestBlock(int blockHeight);
int getLatestBlock() { return this->latestBlock; }
int getLatestBlock() { QReadLocker locker(lock); return this->latestBlock; }
void setEncryptionStatus(bool encrypted, bool locked) { this->isEncrypted = encrypted; this->isLocked = locked; }
QPair<bool, bool> getEncryptionStatus() { return qMakePair(this->isEncrypted, this->isLocked); }
const QList<QString> getAllZAddresses() { QReadLocker locker(lock); return *zaddresses; }
const QList<QString> getAllTAddresses() { QReadLocker locker(lock); return *taddresses; }
@ -34,14 +37,29 @@ public:
const QMap<QString, CAmount> getAllBalances() { QReadLocker locker(lock); return *balances; }
const QMap<QString, bool> getUsedAddresses() { QReadLocker locker(lock); return *usedAddresses; }
CAmount getAvailableBalance() { return availableBalance; }
void setAvailableBalance(CAmount a) { this->availableBalance = a; }
CAmount getAvailableBalance() { QReadLocker locker(lock); return availableBalance; }
void setAvailableBalance(CAmount a) { QReadLocker locker(lock); this->availableBalance = a; }
CAmount getBalT() { QReadLocker locker(lock); return balT; }
void setBalT(CAmount a) { QReadLocker locker(lock); this->balT = a; }
CAmount getBalZ() { QReadLocker locker(lock); return balZ; }
void setBalZ(CAmount a) { QReadLocker locker(lock); this->balZ = a; }
CAmount getBalVerified() { QReadLocker locker(lock); return balVerified; }
void setBalVerified(CAmount a) { QReadLocker locker(lock); this->balVerified = a; }
CAmount getTotalPending() { QReadLocker locker(lock); return totalPending; }
void setTotalPending(CAmount a) { QReadLocker locker(lock); this->totalPending = a; }
DataModel();
~DataModel();
private:
int latestBlock;
bool isEncrypted = false;
bool isLocked = false;
QList<UnspentOutput>* utxos = nullptr;
QMap<QString, CAmount>* balances = nullptr;
QMap<QString, bool>* usedAddresses = nullptr;
@ -49,9 +67,13 @@ private:
QList<QString>* taddresses = nullptr;
CAmount availableBalance;
CAmount totalPending; // Outgoing pending is -ve
QReadWriteLock* lock;
CAmount balT;
CAmount balZ;
CAmount balVerified;
QReadWriteLock* lock;
};
#endif // DATAMODEL_H

165
src/encryption.ui

@ -0,0 +1,165 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>encryptionDialog</class>
<widget class="QDialog" name="encryptionDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Encrypt Your Wallet</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0" colspan="2">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Encryption Password:</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Confirm Password:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="txtConfirmPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="lblPasswordMatch">
<property name="styleSheet">
<string notr="true">color: red;</string>
</property>
<property name="text">
<string>Passwords don't match</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="txtPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>WARNING: If you forget your password, the only way to recover the wallet is from the seed phrase.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" 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="2" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<tabstops>
<tabstop>txtPassword</tabstop>
<tabstop>txtConfirmPassword</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>encryptionDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>encryptionDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

37
src/liteinterface.cpp

@ -56,6 +56,13 @@ void LiteInterface::fetchPrivKey(QString addr, const std::function<void(json)>&
conn->doRPCWithDefaultErrorHandling("export", addr, cb);
}
void LiteInterface::fetchSeed(const std::function<void(json)>& cb) {
if (conn == nullptr)
return;
conn->doRPCWithDefaultErrorHandling("seed", "", cb);
}
void LiteInterface::fetchBalance(const std::function<void(json)>& cb) {
if (conn == nullptr)
return;
@ -77,6 +84,36 @@ void LiteInterface::saveWallet(const std::function<void(json)>& cb) {
conn->doRPCWithDefaultErrorHandling("save", "", cb);
}
void LiteInterface::unlockWallet(QString password, const std::function<void(json)>& cb) {
if (conn == nullptr)
return;
conn->doRPCWithDefaultErrorHandling("unlock", password, cb);
}
void LiteInterface::fetchWalletEncryptionStatus(const std::function<void(json)>& cb) {
if (conn == nullptr)
return;
conn->doRPCWithDefaultErrorHandling("encryptionstatus", "", cb);
}
void LiteInterface::encryptWallet(QString password, const std::function<void(json)>& cb) {
if (conn == nullptr)
return;
conn->doRPCWithDefaultErrorHandling("encrypt", password, cb);
}
void LiteInterface::removeWalletEncryption(QString password, const std::function<void(json)>& cb) {
if (conn == nullptr)
return;
conn->doRPCWithDefaultErrorHandling("decrypt", password, cb);
}
void LiteInterface::sendTransaction(QString params, const std::function<void(json)>& cb,
const std::function<void(QString)>& err) {
if (conn == nullptr)

6
src/liteinterface.h

@ -53,9 +53,15 @@ public:
void fetchPrivKey(QString addr, const std::function<void(json)>& cb);
void fetchAllPrivKeys(const std::function<void(json)>);
void fetchSeed(const std::function<void(json)>&);
void saveWallet(const std::function<void(json)>& cb);
void fetchWalletEncryptionStatus(const std::function<void(json)>& cb);
void encryptWallet(QString password, const std::function<void(json)>& cb);
void unlockWallet(QString password, const std::function<void(json)>& cb);
void removeWalletEncryption(QString password, const std::function<void(json)>& cb);
//void importZPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb);
//void importTPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb);

215
src/mainwindow.cpp

@ -1,6 +1,7 @@
#include "mainwindow.h"
#include "addressbook.h"
#include "viewalladdresses.h"
#include "ui_encryption.h"
#include "ui_mainwindow.h"
#include "ui_mobileappconnector.h"
#include "ui_addressbook.h"
@ -22,8 +23,6 @@ MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
// Include css
QString theme_name;
try
@ -59,7 +58,7 @@ MainWindow::MainWindow(QWidget *parent) :
// File a bug
QObject::connect(ui->actionFile_a_bug, &QAction::triggered, [=]() {
QDesktopServices::openUrl(QUrl("https://github.com/MyHush/silentdragonlite/issues/new"));
QDesktopServices::openUrl(QUrl("https://github.com/DenioD/SilentDragonLite/issues/new"));
});
// Set up check for updates action
@ -83,11 +82,20 @@ MainWindow::MainWindow(QWidget *parent) :
payhushURI();
});
// Wallet encryption
QObject::connect(ui->actionEncrypt_Wallet, &QAction::triggered, [=]() {
encryptWallet();
});
QObject::connect(ui->actionRemove_Wallet_Encryption, &QAction::triggered, [=]() {
removeWalletEncryption();
});
// Export All Private Keys
QObject::connect(ui->actionExport_All_Private_Keys, &QAction::triggered, this, &MainWindow::exportAllKeys);
// Backup wallet.dat
QObject::connect(ui->actionBackup_wallet_dat, &QAction::triggered, this, &MainWindow::backupWalletDat);
QObject::connect(ui->actionExport_Seed, &QAction::triggered, this, &MainWindow::exportSeed);
// Export transactions
QObject::connect(ui->actionExport_transactions, &QAction::triggered, this, &MainWindow::exportTransactions);
@ -215,6 +223,128 @@ void MainWindow::closeEvent(QCloseEvent* event) {
QMainWindow::closeEvent(event);
}
void MainWindow::encryptWallet() {
// Check if wallet is already encrypted
auto encStatus = rpc->getModel()->getEncryptionStatus();
if (encStatus.first) {
QMessageBox::information(this, tr("Wallet is already encrypted"),
tr("Your wallet is already encrypted with a password.\nPlease use 'Remove Wallet Encryption' if you want to remove the wallet encryption."),
QMessageBox::Ok
);
return;
}
QDialog d(this);
Ui_encryptionDialog ed;
ed.setupUi(&d);
// Handle edits on the password box
auto fnPasswordEdited = [=](const QString&) {
// Enable the OK button if the passwords match.
if (!ed.txtPassword->text().isEmpty() &&
ed.txtPassword->text() == ed.txtConfirmPassword->text()) {
ed.lblPasswordMatch->setText("");
ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
} else {
ed.lblPasswordMatch->setText(tr("Passwords don't match"));
ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
}
};
QObject::connect(ed.txtConfirmPassword, &QLineEdit::textChanged, fnPasswordEdited);
QObject::connect(ed.txtPassword, &QLineEdit::textChanged, fnPasswordEdited);
ed.txtPassword->setText("");
ed.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
auto fnShowError = [=](QString title, const json& res) {
QMessageBox::critical(this, title,
tr("Error was:\n") + QString::fromStdString(res.dump()),
QMessageBox::Ok
);
};
if (d.exec() == QDialog::Accepted) {
rpc->encryptWallet(ed.txtPassword->text(), [=](json res) {
if (isJsonSuccess(res)) {
// Save the wallet
rpc->saveWallet([=] (json reply) {
if (isJsonSuccess(reply)) {
QMessageBox::information(this, tr("Wallet Encrypted"),
tr("Your wallet was successfully encrypted! The password will be needed to send funds or export private keys."),
QMessageBox::Ok
);
} else {
fnShowError(tr("Wallet Encryption Failed"), reply);
}
});
// And then refresh the UI
rpc->refresh(true);
} else {
fnShowError(tr("Wallet Encryption Failed"), res);
}
});
}
}
void MainWindow::removeWalletEncryption() {
// Check if wallet is already encrypted
auto encStatus = rpc->getModel()->getEncryptionStatus();
if (!encStatus.first) {
QMessageBox::information(this, tr("Wallet is not encrypted"),
tr("Your wallet is not encrypted with a password."),
QMessageBox::Ok
);
return;
}
bool ok;
QString password = QInputDialog::getText(this, tr("Wallet Password"),
tr("Please enter your wallet password"), QLineEdit::Password, "", &ok);
// If cancel was pressed, just return
if (!ok) {
return;
}
if (password.isEmpty()) {
QMessageBox::critical(this, tr("Wallet Decryption Failed"),
tr("Please enter a password to decrypt your wallet!"),
QMessageBox::Ok
);
return;
}
rpc->removeWalletEncryption(password, [=] (json res) {
if (isJsonSuccess(res)) {
// Save the wallet
rpc->saveWallet([=] (json reply) {
if(isJsonSuccess(reply)) {
QMessageBox::information(this, tr("Wallet Encryption Removed"),
tr("Your wallet was successfully decrypted! You will no longer need a password to send funds or export private keys."),
QMessageBox::Ok
);
} else {
QMessageBox::critical(this, tr("Wallet Decryption Failed"),
QString::fromStdString(reply["error"].get<json::string_t>()),
QMessageBox::Ok
);
}
});
// And then refresh the UI
rpc->refresh(true);
} else {
QMessageBox::critical(this, tr("Wallet Decryption Failed"),
QString::fromStdString(res["error"].get<json::string_t>()),
QMessageBox::Ok
);
}
});
}
void MainWindow::setupStatusBar() {
// Status Bar
loadingLabel = new QLabel();
@ -531,44 +661,71 @@ void MainWindow::exportTransactions() {
}
/**
* Backup the wallet.dat file. This is kind of a hack, since it has to read from the filesystem rather than an RPC call
* This might fail for various reasons - Remote hushd, non-standard locations, custom params passed to hushd, many others
* Export the seed phrase.
*/
void MainWindow::backupWalletDat() {
void MainWindow::exportSeed() {
if (!rpc->getConnection())
return;
}
// QDir hushdir(rpc->getConnection()->config->hushDir);
// QString backupDefaultName = "hush-wallet-backup-" + QDateTime::currentDateTime().toString("yyyyMMdd") + ".dat";
// if (Settings::getInstance()->isTestnet()) {
// hushdir.cd("testnet3");
// backupDefaultName = "testnet-" + backupDefaultName;
// }
// QFile wallet(hushdir.filePath("wallet.dat"));
// if (!wallet.exists()) {
// QMessageBox::critical(this, tr("No wallet.dat"), tr("Couldn't find the wallet.dat on this computer") + "\n" +
// tr("You need to back it up from the machine hushd is running on"), QMessageBox::Ok);
// return;
// }
QDialog d(this);
Ui_PrivKey pui;
pui.setupUi(&d);
// QUrl backupName = QFileDialog::getSaveFileUrl(this, tr("Backup wallet.dat"), backupDefaultName, "Data file (*.dat)");
// if (backupName.isEmpty())
// return;
// Make the window big by default
auto ps = this->geometry();
QMargins margin = QMargins() + 50;
d.setGeometry(ps.marginsRemoved(margin));
Settings::saveRestore(&d);
pui.privKeyTxt->setPlainText(tr("This might take several minutes. Loading..."));
pui.privKeyTxt->setReadOnly(true);
pui.privKeyTxt->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap);
pui.helpLbl->setText(tr("This is your wallet seed. Please back it up carefully and safely."));
// Disable the save button until it finishes loading
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
pui.buttonBox->button(QDialogButtonBox::Ok)->setVisible(false);
// Wire up save button
QObject::connect(pui.buttonBox->button(QDialogButtonBox::Save), &QPushButton::clicked, [=] () {
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
"zcash-seed.txt");
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("Unable to open file"), file.errorString());
return;
}
QTextStream out(&file);
out << pui.privKeyTxt->toPlainText();
});
// if (!wallet.copy(backupName.toLocalFile())) {
// QMessageBox::critical(this, tr("Couldn't backup"), tr("Couldn't backup the wallet.dat file.") +
// tr("You need to back it up manually."), QMessageBox::Ok);
// }
rpc->fetchSeed([=](json reply) {
if (isJsonError(reply)) {
pui.privKeyTxt->setPlainText(tr("Error loading wallet seed: ") + QString::fromStdString(reply["error"]));
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
return;
}
pui.privKeyTxt->setPlainText(QString::fromStdString(reply.dump()));
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(true);
});
d.exec();
}
void MainWindow::exportAllKeys() {
exportKeys("");
}
void MainWindow::exportKeys(QString addr) {
if (!rpc->getConnection())
return;
bool allKeys = addr.isEmpty() ? true : false;
QDialog d(this);
@ -616,7 +773,7 @@ void MainWindow::exportKeys(QString addr) {
if (! *(isDialogAlive.get()) ) return;
if (reply.is_discarded() || !reply.is_array()) {
pui.privKeyTxt->setPlainText(tr("Error loading private keys"));
pui.privKeyTxt->setPlainText(tr("Error loading private keys: ") + QString::fromStdString(reply.dump()));
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
return;

5
src/mainwindow.h

@ -96,6 +96,9 @@ private:
Tx createTxFromSendPage();
bool confirmTx(Tx tx, RecurringPaymentInfo* rpi);
void encryptWallet();
void removeWalletEncryption();
void cancelButton();
void sendButton();
void addAddressSection();
@ -119,7 +122,7 @@ private:
void importPrivKey();
void exportAllKeys();
void exportKeys(QString addr = "");
void backupWalletDat();
void exportSeed();
void exportTransactions();
void doImport(QList<QString>* keys);

29
src/mainwindow.ui

@ -85,7 +85,7 @@
</font>
</property>
<property name="text">
<string>Verified</string>
<string>Notarized</string>
</property>
</widget>
</item>
@ -324,7 +324,7 @@
</font>
</property>
<property name="text">
<string>Total verified funds available:</string>
<string>Total notarized funds available:</string>
</property>
</widget>
</item>
@ -392,8 +392,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1162</width>
<height>344</height>
<width>1226</width>
<height>504</height>
</rect>
</property>
<layout class="QVBoxLayout" name="sendToLayout">
@ -1088,7 +1088,7 @@
<x>0</x>
<y>0</y>
<width>1274</width>
<height>39</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -1099,7 +1099,7 @@
<addaction name="actionPay_URI"/>
<addaction name="separator"/>
<addaction name="actionExport_All_Private_Keys"/>
<addaction name="actionBackup_wallet_dat"/>
<addaction name="actionExport_Seed"/>
<addaction name="separator"/>
<addaction name="actionExport_transactions"/>
<addaction name="separator"/>
@ -1129,6 +1129,9 @@
<addaction name="action_Address_Book"/>
<addaction name="actionSettings"/>
<addaction name="action_Recurring_Payments"/>
<addaction name="separator"/>
<addaction name="actionEncrypt_Wallet"/>
<addaction name="actionRemove_Wallet_Encryption"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menu_Edit"/>
@ -1187,9 +1190,9 @@
<string>Ctrl+B</string>
</property>
</action>
<action name="actionBackup_wallet_dat">
<action name="actionExport_Seed">
<property name="text">
<string>&amp;Backup wallet.dat</string>
<string>&amp;Export seed phrase</string>
</property>
</action>
<action name="actionExport_transactions">
@ -1225,6 +1228,16 @@
<string>File a bug...</string>
</property>
</action>
<action name="actionEncrypt_Wallet">
<property name="text">
<string>Encrypt Wallet</string>
</property>
</action>
<action name="actionRemove_Wallet_Encryption">
<property name="text">
<string>Remove Wallet Encryption</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

14
src/sendtab.cpp

@ -616,6 +616,7 @@ void MainWindow::sendButton() {
Tx tx = createTxFromSendPage();
QString error = doSendTxValidations(tx);
if (!error.isEmpty()) {
// Something went wrong, so show an error and exit
QMessageBox msg(QMessageBox::Critical, tr("Transaction Error"), error,
@ -709,6 +710,9 @@ void MainWindow::sendButton() {
}
QString MainWindow::doSendTxValidations(Tx tx) {
// Check to see if we have enough verified funds to send the Tx.
CAmount total;
for (auto toAddr : tx.toAddrs) {
if (!Settings::isValidAddress(toAddr.addr)) {
QString addr = (toAddr.addr.length() > 100 ? toAddr.addr.left(100) + "..." : toAddr.addr);
@ -720,6 +724,16 @@ QString MainWindow::doSendTxValidations(Tx tx) {
if (toAddr.amount.toqint64() < 0) {
return QString(tr("Amount for address '%1' is invalid!").arg(toAddr.addr));
}
total = total + toAddr.amount;
}
total = total + tx.fee;
auto available = rpc->getModel()->getAvailableBalance();
if (available < total) {
return tr("Not enough available funds to send this transaction\n\nHave: %1\nNeed: %2\n\nNote: Funds need 5 confirmations before they can be spent")
.arg(available.toDecimalhushString(), total.toDecimalhushString());
}
return "";

14
src/settings.h

@ -4,6 +4,8 @@
#include "precompiled.h"
#include "camount.h"
using json = nlohmann::json;
struct Config {
QString server;
};
@ -119,4 +121,16 @@ private:
double ZECPrice = 0.0;
};
inline bool isJsonSuccess(const json& res) {
return res.find("result") != res.end() &&
QString::fromStdString(res["result"].get<json::string_t>()) == "success";
}
inline bool isJsonError(const json& res) {
return res.find("result") != res.end() &&
QString::fromStdString(res["result"].get<json::string_t>()) == "error";
}
#endif // SETTINGS_H

2
src/version.h

@ -1 +1 @@
#define APP_VERSION "1.0-beta1"
#define APP_VERSION "1.0"

Loading…
Cancel
Save