merge
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
#include "mainwindow.h"
|
||||
#include "settings.h"
|
||||
#include "ui_connection.h"
|
||||
#include "firsttimewizard.h"
|
||||
#include "ui_createhushconfdialog.h"
|
||||
#include "controller.h"
|
||||
|
||||
|
||||
#include "../lib/silentdragonlitelib.h"
|
||||
|
||||
#include "precompiled.h"
|
||||
@@ -42,7 +44,15 @@ void ConnectionLoader::doAutoConnect() {
|
||||
|
||||
// Initialize the library
|
||||
main->logger->write(QObject::tr("Attempting to initialize"));
|
||||
litelib_initialze_existing(config->dangerous, config->server.toStdString().c_str());
|
||||
|
||||
// Check to see if there's an existing wallet
|
||||
if (litelib_wallet_exists(Settings::getChainName().toStdString().c_str())) {
|
||||
main->logger->write(QObject::tr("Using existing wallet."));
|
||||
litelib_initialize_existing(config->dangerous, config->server.toStdString().c_str());
|
||||
} else {
|
||||
main->logger->write(QObject::tr("Create/restore wallet."));
|
||||
createOrRestore(config->dangerous, config->server);
|
||||
}
|
||||
|
||||
auto connection = makeConnection(config);
|
||||
|
||||
@@ -54,6 +64,16 @@ void ConnectionLoader::doAutoConnect() {
|
||||
}, [=](auto err) {});
|
||||
}
|
||||
|
||||
void ConnectionLoader::createOrRestore(bool dangerous, QString server) {
|
||||
// Close the startup dialog, since we'll be showing the wizard
|
||||
d->hide();
|
||||
|
||||
// Create a wizard
|
||||
FirstTimeWizard wizard(dangerous, server);
|
||||
|
||||
wizard.exec();
|
||||
}
|
||||
|
||||
void ConnectionLoader::doRPCSetConnection(Connection* conn) {
|
||||
rpc->setConnection(conn);
|
||||
|
||||
@@ -94,15 +114,7 @@ void ConnectionLoader::showError(QString explanation) {
|
||||
d->close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***********************************************************************************
|
||||
* Connection, Executor and Callback Class
|
||||
************************************************************************************/
|
||||
void Executor::run() {
|
||||
char* resp = litelib_execute(this->cmd.toStdString().c_str(), this->args.toStdString().c_str());
|
||||
|
||||
// Copy the string, since we need to return this back to rust
|
||||
QString litelib_process_response(char* resp) {
|
||||
char* resp_copy = new char[strlen(resp) + 1];
|
||||
strcpy(resp_copy, resp);
|
||||
litelib_rust_free_string(resp);
|
||||
@@ -111,6 +123,17 @@ void Executor::run() {
|
||||
memset(resp_copy, '-', strlen(resp_copy));
|
||||
delete[] resp_copy;
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
/***********************************************************************************
|
||||
* Connection, Executor and Callback Class
|
||||
************************************************************************************/
|
||||
void Executor::run() {
|
||||
char* resp = litelib_execute(this->cmd.toStdString().c_str(), this->args.toStdString().c_str());
|
||||
|
||||
QString reply = litelib_process_response(resp);
|
||||
|
||||
qDebug() << "Reply=" << reply;
|
||||
auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false);
|
||||
if (parsed.is_discarded() || parsed.is_null()) {
|
||||
@@ -126,8 +149,6 @@ void Executor::run() {
|
||||
|
||||
|
||||
void Callback::processRPCCallback(json resp) {
|
||||
const bool isGuiThread = QThread::currentThread() == QCoreApplication::instance()->thread();
|
||||
qDebug() << "Doing RPC callback: isGUI=" << isGuiThread;
|
||||
this->cb(resp);
|
||||
|
||||
// Destroy self
|
||||
@@ -135,8 +156,6 @@ void Callback::processRPCCallback(json resp) {
|
||||
}
|
||||
|
||||
void Callback::processError(QString resp) {
|
||||
const bool isGuiThread = QThread::currentThread() == QCoreApplication::instance()->thread();
|
||||
qDebug() << "Doing RPC callback: isGUI=" << isGuiThread;
|
||||
this->errCb(resp);
|
||||
|
||||
// Destroy self
|
||||
@@ -158,9 +177,7 @@ void Connection::doRPC(const QString cmd, const QString args, const std::functio
|
||||
return;
|
||||
}
|
||||
|
||||
const bool isGuiThread =
|
||||
QThread::currentThread() == QCoreApplication::instance()->thread();
|
||||
qDebug() << "Doing RPC: isGUI=" << isGuiThread;
|
||||
qDebug() << "Doing RPC: " << cmd;
|
||||
|
||||
// Create a runner.
|
||||
auto runner = new Executor(cmd, args);
|
||||
|
||||
@@ -33,6 +33,8 @@ private:
|
||||
|
||||
void doAutoConnect();
|
||||
|
||||
void createOrRestore(bool dangerous, QString server);
|
||||
|
||||
void showError(QString explanation);
|
||||
void showInformation(QString info, QString detail = "");
|
||||
|
||||
|
||||
@@ -417,7 +417,7 @@ void Controller::executeTransaction(Tx tx,
|
||||
std::cout << std::setw(2) << params << std::endl;
|
||||
|
||||
zrpc->sendTransaction(QString::fromStdString(params.dump()), [=](const json& reply) {
|
||||
if (reply["result"].is_null() || reply["result"] != "success") {
|
||||
if (reply.find("txid") == reply.end()) {
|
||||
error("", "Couldn't understand Response: " + QString::fromStdString(reply.dump()));
|
||||
}
|
||||
|
||||
|
||||
151
src/firsttimewizard.cpp
Normal file
151
src/firsttimewizard.cpp
Normal file
@@ -0,0 +1,151 @@
|
||||
#include "firsttimewizard.h"
|
||||
|
||||
#include "ui_newseed.h"
|
||||
#include "ui_restoreseed.h"
|
||||
#include "ui_newwallet.h"
|
||||
|
||||
#include "../lib/silentdragonlitelib.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
FirstTimeWizard::FirstTimeWizard(bool dangerous, QString server)
|
||||
{
|
||||
setWindowTitle("New wallet wizard");
|
||||
this->dangerous = dangerous;
|
||||
this->server = server;
|
||||
|
||||
// Create the pages
|
||||
setPage(Page_NewOrRestore, new NewOrRestorePage(this));
|
||||
setPage(Page_New, new NewSeedPage(this));
|
||||
setPage(Page_Restore,new RestoreSeedPage(this));
|
||||
}
|
||||
|
||||
int FirstTimeWizard::nextId() const {
|
||||
switch (currentId()) {
|
||||
case Page_NewOrRestore:
|
||||
if (field("intro.new").toBool()) {
|
||||
return Page_New;
|
||||
} else {
|
||||
return Page_Restore;
|
||||
}
|
||||
case Page_New:
|
||||
case Page_Restore:
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
NewOrRestorePage::NewOrRestorePage(FirstTimeWizard *parent) : QWizardPage(parent) {
|
||||
setTitle("Create or Restore wallet.");
|
||||
|
||||
QWidget* pageWidget = new QWidget();
|
||||
Ui_CreateWalletForm form;
|
||||
form.setupUi(pageWidget);
|
||||
|
||||
// Exclusive buttons
|
||||
QObject::connect(form.radioNewWallet, &QRadioButton::clicked, [=](bool checked) {
|
||||
if (checked) {
|
||||
form.radioRestoreWallet->setChecked(false);
|
||||
}
|
||||
});
|
||||
|
||||
QObject::connect(form.radioRestoreWallet, &QRadioButton::clicked, [=](bool checked) {
|
||||
if (checked) {
|
||||
form.radioNewWallet->setChecked(false);
|
||||
}
|
||||
});
|
||||
form.radioNewWallet->setChecked(true);
|
||||
|
||||
registerField("intro.new", form.radioNewWallet);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
layout->addWidget(pageWidget);
|
||||
setLayout(layout);
|
||||
setCommitPage(true);
|
||||
setButtonText(QWizard::CommitButton, "Next");
|
||||
}
|
||||
|
||||
NewSeedPage::NewSeedPage(FirstTimeWizard *parent) : QWizardPage(parent) {
|
||||
this->parent = parent;
|
||||
|
||||
setTitle("Your new wallet");
|
||||
|
||||
QWidget* pageWidget = new QWidget();
|
||||
form.setupUi(pageWidget);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
layout->addWidget(pageWidget);
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void NewSeedPage::initializePage() {
|
||||
// Call the library to create a new wallet.
|
||||
char* resp = litelib_initialize_new(parent->dangerous, parent->server.toStdString().c_str());
|
||||
QString reply = litelib_process_response(resp);
|
||||
|
||||
auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false);
|
||||
if (parsed.is_discarded() || parsed.is_null() || parsed.find("seed") == parsed.end()) {
|
||||
form.txtSeed->setPlainText(tr("Error creating a wallet") + "\n" + reply);
|
||||
} else {
|
||||
QString seed = QString::fromStdString(parsed["seed"].get<json::string_t>());
|
||||
form.txtSeed->setPlainText(seed);
|
||||
}
|
||||
}
|
||||
|
||||
// Will be called just before closing. Make sure we can save the seed in the wallet
|
||||
// before we allow the page to be closed
|
||||
bool NewSeedPage::validatePage() {
|
||||
char* resp = litelib_execute("save", "");
|
||||
QString reply = litelib_process_response(resp);
|
||||
|
||||
auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false);
|
||||
if (parsed.is_discarded() || parsed.is_null() || parsed.find("result") == parsed.end()) {
|
||||
QMessageBox::warning(this, tr("Failed to save wallet"),
|
||||
tr("Couldn't save the wallet") + "\n" + reply,
|
||||
QMessageBox::Ok);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RestoreSeedPage::RestoreSeedPage(FirstTimeWizard *parent) : QWizardPage(parent) {
|
||||
this->parent = parent;
|
||||
|
||||
setTitle("Restore wallet from seed");
|
||||
|
||||
QWidget* pageWidget = new QWidget();
|
||||
form.setupUi(pageWidget);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
layout->addWidget(pageWidget);
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
bool RestoreSeedPage::validatePage() {
|
||||
// 1. Validate that we do have 24 words
|
||||
QString seed = form.txtSeed->toPlainText().replace(QRegExp("[ \n\r]+"), " ");
|
||||
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. Attempt to restore wallet with the seed phrase
|
||||
char* resp = litelib_initialize_new_from_phrase(parent->dangerous, parent->server.toStdString().c_str(),
|
||||
seed.toStdString().c_str(), 0);
|
||||
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);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
66
src/firsttimewizard.h
Normal file
66
src/firsttimewizard.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef FIRSTTIMEWIZARD_H
|
||||
#define FIRSTTIMEWIZARD_H
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "ui_newseed.h"
|
||||
#include "ui_restoreseed.h"
|
||||
|
||||
class FirstTimeWizard: public QWizard
|
||||
{
|
||||
public:
|
||||
FirstTimeWizard(bool dangerous, QString server);
|
||||
|
||||
protected:
|
||||
int nextId() const;
|
||||
|
||||
private:
|
||||
enum {
|
||||
Page_NewOrRestore,
|
||||
Page_New,
|
||||
Page_Restore
|
||||
};
|
||||
|
||||
bool dangerous;
|
||||
QString server;
|
||||
|
||||
friend class NewOrRestorePage;
|
||||
friend class NewSeedPage;
|
||||
friend class RestoreSeedPage;
|
||||
};
|
||||
|
||||
class NewOrRestorePage: public QWizardPage {
|
||||
public:
|
||||
NewOrRestorePage(FirstTimeWizard* parent);
|
||||
};
|
||||
|
||||
|
||||
class NewSeedPage: public QWizardPage {
|
||||
public:
|
||||
NewSeedPage(FirstTimeWizard* parent);
|
||||
|
||||
protected:
|
||||
virtual void initializePage();
|
||||
virtual bool validatePage();
|
||||
|
||||
private:
|
||||
FirstTimeWizard* parent;
|
||||
Ui_NewSeedForm form;
|
||||
};
|
||||
|
||||
|
||||
class RestoreSeedPage: public QWizardPage {
|
||||
public:
|
||||
RestoreSeedPage(FirstTimeWizard* parent);
|
||||
|
||||
protected:
|
||||
bool validatePage();
|
||||
|
||||
private:
|
||||
FirstTimeWizard* parent;
|
||||
Ui_RestoreSeedForm form;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // FIRSTTIMEWIZARD_H
|
||||
@@ -17,7 +17,7 @@ using json = nlohmann::json;
|
||||
// Struct used to hold destination info when sending a Tx.
|
||||
struct ToFields {
|
||||
QString addr;
|
||||
double amount;
|
||||
qint64 amount;
|
||||
QString memo;
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ struct ToFields {
|
||||
struct Tx {
|
||||
QString fromAddr;
|
||||
QList<ToFields> toAddrs;
|
||||
double fee;
|
||||
qint64 fee;
|
||||
};
|
||||
|
||||
namespace Ui {
|
||||
|
||||
63
src/newseed.ui
Normal file
63
src/newseed.ui
Normal file
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>NewSeedForm</class>
|
||||
<widget class="QWidget" name="NewSeedForm">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>This is your new wallet's seed phrase. PLEASE BACK IT UP SECURELY.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>The seed phrase is the only way to restore the wallet. If you forget the seed phrase, THERE IS NO WAY TO RESTORE YOUR WALLET AND THE FUNDS in it</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="txtSeed">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
85
src/newwallet.ui
Normal file
85
src/newwallet.ui
Normal file
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CreateWalletForm</class>
|
||||
<widget class="QWidget" name="CreateWalletForm">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QRadioButton" name="radioRestoreWallet">
|
||||
<property name="text">
|
||||
<string>Restore wallet from seed</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Restore an existing wallet, using the 24-word seed. </string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QRadioButton" name="radioNewWallet">
|
||||
<property name="text">
|
||||
<string>Create a new Wallet</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Create a new wallet with a randomly generated seed.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -17,6 +17,8 @@
|
||||
#include <QAbstractTableModel>
|
||||
#include <QTranslator>
|
||||
#include <QClipboard>
|
||||
#include <QWizard>
|
||||
#include <QWizardPage>
|
||||
#include <QStringBuilder>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QTableView>
|
||||
|
||||
53
src/restoreseed.ui
Normal file
53
src/restoreseed.ui
Normal file
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>RestoreSeedForm</class>
|
||||
<widget class="QWidget" name="RestoreSeedForm">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Please enter your 24-word seed below</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="txtSeed">
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -315,7 +315,7 @@ bool Settings::removeFromhushConf(QString confLocation, QString option) {
|
||||
}
|
||||
|
||||
double Settings::getMinerFee() {
|
||||
return 0.0001;
|
||||
return 10000;
|
||||
}
|
||||
|
||||
double Settings::getZboardAmount() {
|
||||
|
||||
@@ -119,6 +119,8 @@ public:
|
||||
static bool addTohushConf(QString confLocation, QString line);
|
||||
static bool removeFromhushConf(QString confLocation, QString option);
|
||||
|
||||
static QString getChainName() { return QString("test"); }
|
||||
|
||||
static const QString labelRegExp;
|
||||
|
||||
static const int updateSpeed = 20 * 1000; // 10 sec
|
||||
|
||||
Reference in New Issue
Block a user