error handlings
This commit is contained in:
BIN
Silentdragonlite
BIN
Silentdragonlite
Binary file not shown.
6
lib/Cargo.lock
generated
6
lib/Cargo.lock
generated
@@ -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=58839270ace26bf08d351375d0d945c2dd5527f9)",
|
||||
"silentdragonlitelib 0.1.0 (git+https://github.com/DenioD/silentdragonlite-cli?rev=a25b4bcc5f6d576d0519a0893331a7dc1b1bf017)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1467,7 +1467,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "silentdragonlitelib"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/DenioD/silentdragonlite-cli?rev=58839270ace26bf08d351375d0d945c2dd5527f9#58839270ace26bf08d351375d0d945c2dd5527f9"
|
||||
source = "git+https://github.com/DenioD/silentdragonlite-cli?rev=a25b4bcc5f6d576d0519a0893331a7dc1b1bf017#a25b4bcc5f6d576d0519a0893331a7dc1b1bf017"
|
||||
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=58839270ace26bf08d351375d0d945c2dd5527f9)" = "<none>"
|
||||
"checksum silentdragonlitelib 0.1.0 (git+https://github.com/DenioD/silentdragonlite-cli?rev=a25b4bcc5f6d576d0519a0893331a7dc1b1bf017)" = "<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"
|
||||
|
||||
@@ -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 = "58839270ace26bf08d351375d0d945c2dd5527f9" }
|
||||
silentdragonlitelib = { git = "https://github.com/DenioD/silentdragonlite-cli", rev = "a25b4bcc5f6d576d0519a0893331a7dc1b1bf017" }
|
||||
|
||||
@@ -466,12 +466,16 @@ void Controller::unlockIfEncrypted(std::function<void(void)> cb, std::function<v
|
||||
main->tr("Your wallet is encrypted.\nPlease enter your wallet password"), QLineEdit::Password);
|
||||
|
||||
if (password.isEmpty()) {
|
||||
QMessageBox::critical(main, main->tr("Wallet Decryption Failed"),
|
||||
main->tr("Please enter a valid password"),
|
||||
QMessageBox::Ok
|
||||
);
|
||||
error();
|
||||
return;
|
||||
}
|
||||
|
||||
zrpc->unlockWallet(password, [=](json reply) {
|
||||
if (isJsonSuccess(reply)) {
|
||||
if (isJsonResultSuccess(reply)) {
|
||||
cb();
|
||||
|
||||
// Refresh the wallet so the encryption status is now in sync.
|
||||
|
||||
@@ -267,10 +267,10 @@ void MainWindow::encryptWallet() {
|
||||
|
||||
if (d.exec() == QDialog::Accepted) {
|
||||
rpc->encryptWallet(ed.txtPassword->text(), [=](json res) {
|
||||
if (isJsonSuccess(res)) {
|
||||
if (isJsonResultSuccess(res)) {
|
||||
// Save the wallet
|
||||
rpc->saveWallet([=] (json reply) {
|
||||
if (isJsonSuccess(reply)) {
|
||||
if (isJsonResultSuccess(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
|
||||
@@ -318,10 +318,10 @@ void MainWindow::removeWalletEncryption() {
|
||||
}
|
||||
|
||||
rpc->removeWalletEncryption(password, [=] (json res) {
|
||||
if (isJsonSuccess(res)) {
|
||||
if (isJsonResultSuccess(res)) {
|
||||
// Save the wallet
|
||||
rpc->saveWallet([=] (json reply) {
|
||||
if(isJsonSuccess(reply)) {
|
||||
if(isJsonResultSuccess(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
|
||||
@@ -667,55 +667,47 @@ void MainWindow::exportSeed() {
|
||||
if (!rpc->getConnection())
|
||||
return;
|
||||
|
||||
|
||||
QDialog d(this);
|
||||
Ui_PrivKey pui;
|
||||
pui.setupUi(&d);
|
||||
|
||||
// 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();
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
if (isJsonError(reply)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QDialog d(this);
|
||||
Ui_PrivKey pui;
|
||||
pui.setupUi(&d);
|
||||
|
||||
// Make the window big by default
|
||||
auto ps = this->geometry();
|
||||
QMargins margin = QMargins() + 50;
|
||||
d.setGeometry(ps.marginsRemoved(margin));
|
||||
|
||||
Settings::saveRestore(&d);
|
||||
|
||||
pui.privKeyTxt->setReadOnly(true);
|
||||
pui.privKeyTxt->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap);
|
||||
pui.privKeyTxt->setPlainText(QString::fromStdString(reply.dump()));
|
||||
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(true);
|
||||
});
|
||||
|
||||
pui.helpLbl->setText(tr("This is your wallet seed. Please back it up carefully and safely."));
|
||||
|
||||
|
||||
d.exec();
|
||||
// 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();
|
||||
});
|
||||
|
||||
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(true);
|
||||
|
||||
d.exec();
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::exportAllKeys() {
|
||||
@@ -728,57 +720,51 @@ void MainWindow::exportKeys(QString addr) {
|
||||
|
||||
bool allKeys = addr.isEmpty() ? true : false;
|
||||
|
||||
QDialog d(this);
|
||||
Ui_PrivKey pui;
|
||||
pui.setupUi(&d);
|
||||
|
||||
// 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("Loading..."));
|
||||
pui.privKeyTxt->setReadOnly(true);
|
||||
pui.privKeyTxt->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap);
|
||||
|
||||
if (allKeys)
|
||||
pui.helpLbl->setText(tr("These are all the private keys for all the addresses in your wallet"));
|
||||
else
|
||||
pui.helpLbl->setText(tr("Private key for ") + addr);
|
||||
|
||||
// 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"),
|
||||
allKeys ? "hush-all-privatekeys.txt" : "hush-privatekey.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();
|
||||
});
|
||||
|
||||
// Call the API
|
||||
auto isDialogAlive = std::make_shared<bool>(true);
|
||||
|
||||
auto fnUpdateUIWithKeys = [=](json reply) {
|
||||
// Check to see if we are still showing.
|
||||
if (! *(isDialogAlive.get()) ) return;
|
||||
if (isJsonError(reply)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reply.is_discarded() || !reply.is_array()) {
|
||||
pui.privKeyTxt->setPlainText(tr("Error loading private keys: ") + QString::fromStdString(reply.dump()));
|
||||
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
|
||||
|
||||
QMessageBox::critical(this, tr("Error getting private keys"),
|
||||
tr("Error loading private keys: ") + QString::fromStdString(reply.dump()),
|
||||
QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
|
||||
QDialog d(this);
|
||||
Ui_PrivKey pui;
|
||||
pui.setupUi(&d);
|
||||
|
||||
// Make the window big by default
|
||||
auto ps = this->geometry();
|
||||
QMargins margin = QMargins() + 50;
|
||||
d.setGeometry(ps.marginsRemoved(margin));
|
||||
|
||||
Settings::saveRestore(&d);
|
||||
|
||||
pui.privKeyTxt->setReadOnly(true);
|
||||
pui.privKeyTxt->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap);
|
||||
|
||||
if (allKeys)
|
||||
pui.helpLbl->setText(tr("These are all the private keys for all the addresses in your wallet"));
|
||||
else
|
||||
pui.helpLbl->setText(tr("Private key for ") + addr);
|
||||
|
||||
|
||||
// Wire up save button
|
||||
QObject::connect(pui.buttonBox->button(QDialogButtonBox::Save), &QPushButton::clicked, [=] () {
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
|
||||
allKeys ? "zcash-all-privatekeys.txt" : "zcash-privatekey.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();
|
||||
});
|
||||
|
||||
QString allKeysTxt;
|
||||
for (auto i : reply.get<json::array_t>()) {
|
||||
allKeysTxt = allKeysTxt % QString::fromStdString(i["private_key"]) % " # addr=" % QString::fromStdString(i["address"]) % "\n";
|
||||
@@ -786,6 +772,8 @@ void MainWindow::exportKeys(QString addr) {
|
||||
|
||||
pui.privKeyTxt->setPlainText(allKeysTxt);
|
||||
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(true);
|
||||
|
||||
d.exec();
|
||||
};
|
||||
|
||||
if (allKeys) {
|
||||
@@ -793,10 +781,7 @@ void MainWindow::exportKeys(QString addr) {
|
||||
}
|
||||
else {
|
||||
rpc->fetchPrivKey(addr, fnUpdateUIWithKeys);
|
||||
}
|
||||
|
||||
d.exec();
|
||||
*isDialogAlive = false;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setupBalancesTab() {
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok|QDialogButtonBox::Save</set>
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Save</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -122,14 +122,13 @@ private:
|
||||
};
|
||||
|
||||
|
||||
inline bool isJsonSuccess(const json& res) {
|
||||
inline bool isJsonResultSuccess(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";
|
||||
return res.find("error") != res.end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user