diff --git a/silentdragon-lite.pro b/silentdragon-lite.pro index 094d7f4..77544e2 100644 --- a/silentdragon-lite.pro +++ b/silentdragon-lite.pro @@ -131,6 +131,7 @@ FORMS += \ src/newwallet.ui \ src/recurringpayments.ui \ src/restoreseed.ui \ + src/seedrestore.ui \ src/sendHushTransactionChat.ui \ src/settings.ui \ src/about.ui \ diff --git a/src/controller.cpp b/src/controller.cpp index cb3d9f3..a33a38f 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -638,7 +638,7 @@ void Controller::getInfoThenRefresh(bool force) refreshAddresses(); // This calls refreshZSentTransactions() and refreshReceivedZTrans() refreshTransactions(); } - + refreshBalances(); int lag = longestchain - notarized ; this->setLag(lag); }, [=](QString err) { @@ -730,7 +730,7 @@ void Controller::processUnspent(const QJsonValue& reply, QMap* QString qsAddr = it["address"].toString(); int block = it["created_in_block"].toInt(); QString txid = it["created_in_txid"].toString(); - CAmount amount = CAmount::fromqint64(it["value"].toInt()); + CAmount amount = CAmount::fromqint64(it["value"].toDouble()); bool spendable = it["unconfirmed_spent"].isNull() && it["spent"].isNull(); // TODO: Wait for 1 confirmations bool pending = !it["unconfirmed_spent"].isNull(); @@ -741,7 +741,7 @@ void Controller::processUnspent(const QJsonValue& reply, QMap* if (spendable) { (*balancesMap)[qsAddr] = (*balancesMap)[qsAddr] + - CAmount::fromqint64(it["value"].toInt()); + CAmount::fromqint64(it["value"].toDouble()); } } }; @@ -906,9 +906,9 @@ void Controller::refreshBalances() // 1. Get the Balances zrpc->fetchBalance([=] (QJsonValue reply) { - CAmount balT = CAmount::fromqint64(reply["tbalance"].toInt()); - CAmount balZ = CAmount::fromqint64(reply["zbalance"].toInt()); - CAmount balVerified = CAmount::fromqint64(reply["verified_zbalance"].toInt()); + CAmount balT = CAmount::fromqint64(reply["tbalance"].toDouble()); + CAmount balZ = CAmount::fromqint64(reply["zbalance"].toDouble()); + CAmount balVerified = CAmount::fromqint64(reply["verified_zbalance"].toDouble()); model->setBalT(balT); model->setBalZ(balZ); @@ -985,7 +985,7 @@ void Controller::refreshTransactions() { address = o.toObject()["address"].toString(); // Sent items are -ve - CAmount amount = CAmount::fromqint64(-1* o.toObject()["value"].toInt()); + CAmount amount = CAmount::fromqint64(-1* o.toObject()["value"].toDouble()); // Check for Memos @@ -1169,7 +1169,7 @@ void Controller::refreshTransactions() { ); DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item); - updateUIBalances(); + // updateUIBalances(); } } @@ -1194,18 +1194,18 @@ void Controller::refreshTransactions() { } else { - // Incoming Transaction + + { // Incoming Transaction address = (it.toObject()["address"].isNull() ? "" : it.toObject()["address"].toString()); model->markAddressUsed(address); QString memo; - if (!it.toObject()["memo"].isNull()) { + if (!it.toObject()["memo"].isNull()) memo = it.toObject()["memo"].toString(); - } items.push_back(TransactionItemDetail{ address, - CAmount::fromqint64(it.toObject()["amount"].toInt()), + CAmount::fromqint64(it.toObject()["amount"].toDouble()), memo }); @@ -1214,7 +1214,14 @@ void Controller::refreshTransactions() { }; txdata.push_back(tx); - + } + + address = (it.toObject()["address"].isNull() ? "" : it.toObject()["address"].toString()); + model->markAddressUsed(address); + + QString memo; + if (!it.toObject()["memo"].isNull()) + memo = it.toObject()["memo"].toString(); QString type; QString publickey; QString headerbytes; @@ -1470,8 +1477,9 @@ void Controller::refreshTransactions() { chat->renderChatBox(ui, ui->listChat,ui->memoSizeChat); ui->listChat->verticalScrollBar()->setValue( ui->listChat->verticalScrollBar()->maximum()); - + }); + } void Controller::refreshChat(QListView *listWidget, QLabel *label) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 68157ec..84aa862 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -26,6 +26,7 @@ #include "requestdialog.h" #include "ui_startupencryption.h" #include "ui_removeencryption.h" +#include "ui_seedrestore.h" #include "websockets.h" #include "sodium.h" #include "sodium/crypto_generichash_blake2b.h" @@ -162,17 +163,124 @@ MainWindow::MainWindow(QWidget *parent) : // Rescan QObject::connect(ui->actionRescan, &QAction::triggered, [=]() { - // To rescan, we clear the wallet state, and then reload the connection + + QFile file(dirwalletenc); + QFile file1(dirwallet); + + if(fileExists(dirwalletenc)) + + { + file.remove(); + file1.remove(); + } + + + Ui_Restore restoreSeed; + QDialog dialog(this); + restoreSeed.setupUi(&dialog); + Settings::saveRestore(&dialog); + + + rpc->fetchSeed([&](QJsonValue reply) { + if (isJsonError(reply)) { + return; + } + + restoreSeed.seed->setReadOnly(true); + restoreSeed.seed->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap); + QString seedJson = QLatin1String(QJsonDocument(reply.toObject()).toJson(QJsonDocument::Compact)); + int startPos = seedJson.indexOf("seed") +7; + int endPos = seedJson.indexOf("}") -1; + int length = endPos - startPos; + QString seed = seedJson.mid(startPos, length); + restoreSeed.seed->setPlainText(seed); + + int startPosB = seedJson.indexOf("birthday") +10; + int endPosB = seedJson.indexOf("seed") -2; + int lengthB = endPosB - startPosB; + QString birthday = seedJson.mid(startPosB, lengthB); + restoreSeed.birthday->setPlainText(birthday); + }); + + QObject::connect(restoreSeed.restore, &QPushButton::clicked, [&](){ + + QString seed = restoreSeed.seed->toPlainText(); + if (seed.trimmed().split(" ").length() != 24) { + QMessageBox::warning(this, tr("Failed to restore wallet"), + tr("SilentDragonLite needs 24 words to restore wallet"), + QMessageBox::Ok); + return false; + } + + + // 2. Validate birthday + QString birthday_str = restoreSeed.birthday->toPlainText(); + bool ok; + qint64 birthday = birthday_str.toUInt(&ok); + if (!ok) { + QMessageBox::warning(this, tr("Failed to parse wallet birthday"), + tr("Couldn't understand wallet birthday. This should be a block height from where to rescan the wallet. You can leave it as '0' if you don't know what it should be."), + QMessageBox::Ok); + return false; + } + + + QString number_str = restoreSeed.quantity->text(); + qint64 number = number_str.toUInt(); + + auto config = std::shared_ptr(new ConnectionConfig()); + config->server = Settings::getInstance()->getSettings().server; + // 3. Attempt to restore wallet with the seed phrase + { + char* resp = litelib_initialize_new_from_phrase(config->server.toStdString().c_str(), + seed.toStdString().c_str(), birthday, number); + QString reply = litelib_process_response(resp); + + if (reply.toUpper().trimmed() != "OK") { + QMessageBox::warning(this, tr("Failed to restore wallet"), + tr("Couldn't restore the wallet") + "\n" + reply, + QMessageBox::Ok); + + } + } + + // 4. Finally attempt to save the wallet + { + char* resp = litelib_execute("save", ""); + QString reply = litelib_process_response(resp); + + QByteArray ba_reply = reply.toUtf8(); + QJsonDocument jd_reply = QJsonDocument::fromJson(ba_reply); + QJsonObject parsed = jd_reply.object(); + + if (parsed.isEmpty() || parsed["result"].isNull()) { + QMessageBox::warning(this, tr("Failed to save wallet"), + tr("Couldn't save the wallet") + "\n" + reply, + QMessageBox::Ok); + + } else {} + + dialog.close(); + // To rescan, we clear the wallet state, and then reload the connection // This will start a sync, and show the scanning status. this->getRPC()->clearWallet([=] (auto) { // Save the wallet this->getRPC()->saveWallet([=] (auto) { // Then reload the connection. The ConnectionLoader deletes itself. - auto cl = new ConnectionLoader(this, rpc); + auto cl = new ConnectionLoader(this, rpc); cl->loadConnection(); - }); - }); - }); + }); + }); + + + } + + }); + + // }); + + dialog.exec(); +}); // Address Book QObject::connect(ui->action_Address_Book, &QAction::triggered, this, &MainWindow::addressBook); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 8f3e13a..4e62995 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -6,7 +6,7 @@ 0 0 - 1282 + 1308 779 @@ -59,7 +59,7 @@ - 5 + 0 @@ -428,7 +428,7 @@ 0 0 - 1234 + 1260 509 @@ -1834,7 +1834,7 @@ 0 0 - 1282 + 1308 22 diff --git a/src/seedrestore.ui b/src/seedrestore.ui index fb923db..697c2c2 100644 --- a/src/seedrestore.ui +++ b/src/seedrestore.ui @@ -1,72 +1,114 @@ - - - - - Dialog - - + + + Restore + + 0 0 - 400 - 300 + 637 + 429 - - Dialog + + Restore your Wallet - - - - 30 - 240 - 341 - 32 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - + + + + + + 0 + 284 + + + + + + + + + + Birthday : + + + + + + + Quantity : + + + + + + + + + + + + 529 + 0 + + + + + 16777215 + 25 + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + + + + + + 529 + 0 + + + + + + + + + + + + + Qt::Horizontal + + + + 521 + 20 + + + + + + + + + 89 + 16777215 + + + + Restore + + + + - - - - buttonBox - accepted() - Dialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - Dialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - + -