Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui: Implement consolidateunspent wizard #2125

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ QT_FORMS_UI = \
qt/forms/aboutdialog.ui \
qt/forms/coincontroldialog.ui \
qt/forms/consolidateunspentdialog.ui \
qt/forms/consolidateunspentwizard.ui \
qt/forms/consolidateunspentwizardselectdestinationpage.ui \
qt/forms/consolidateunspentwizardselectinputspage.ui \
qt/forms/consolidateunspentwizardsendpage.ui \
qt/forms/diagnosticsdialog.ui \
qt/forms/optionsdialog.ui \
qt/forms/rpcconsole.ui \
Expand Down Expand Up @@ -113,6 +117,10 @@ QT_MOC_CPP = \
qt/moc_coincontroldialog.cpp \
qt/moc_coincontroltreewidget.cpp \
qt/moc_consolidateunspentdialog.cpp \
qt/moc_consolidateunspentwizard.cpp \
qt/moc_consolidateunspentwizardselectdestinationpage.cpp \
qt/moc_consolidateunspentwizardselectinputspage.cpp \
qt/moc_consolidateunspentwizardsendpage.cpp \
qt/moc_csvmodelwriter.cpp \
qt/moc_diagnosticsdialog.cpp \
qt/moc_editaddressdialog.cpp \
Expand Down Expand Up @@ -184,6 +192,10 @@ GRIDCOINRESEARCH_QT_H = \
qt/coincontroldialog.h \
qt/coincontroltreewidget.h \
qt/consolidateunspentdialog.h \
qt/consolidateunspentwizard.h \
qt/consolidateunspentwizardselectdestinationpage.h \
qt/consolidateunspentwizardselectinputspage.h \
qt/consolidateunspentwizardsendpage.h \
qt/csvmodelwriter.h \
qt/decoration.h \
qt/diagnosticsdialog.h \
Expand Down Expand Up @@ -247,6 +259,10 @@ GRIDCOINRESEARCH_QT_CPP = \
qt/coincontroldialog.cpp \
qt/coincontroltreewidget.cpp \
qt/consolidateunspentdialog.cpp \
qt/consolidateunspentwizard.cpp \
qt/consolidateunspentwizardselectdestinationpage.cpp \
qt/consolidateunspentwizardselectinputspage.cpp \
qt/consolidateunspentwizardsendpage.cpp \
qt/csvmodelwriter.cpp \
qt/decoration.cpp \
qt/diagnosticsdialog.cpp \
Expand Down
27 changes: 17 additions & 10 deletions src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@
#include <QTreeWidgetItem>

using namespace std;
QList<qint64> CoinControlDialog::payAmounts;
CCoinControl* CoinControlDialog::coinControl = new CCoinControl();

CoinControlDialog::CoinControlDialog(QWidget *parent) :
CoinControlDialog::CoinControlDialog(QWidget *parent, CCoinControl *coinControl, QList<qint64> *payAmounts) :
QDialog(parent),
m_inputSelectionLimit(GetMaxInputsForConsolidationTxn()),
ui(new Ui::CoinControlDialog),
coinControl(coinControl),
payAmounts(payAmounts),
jamescowens marked this conversation as resolved.
Show resolved Hide resolved
model(0)
{
assert(coinControl != nullptr && payAmounts != nullptr);

ui->setupUi(this);

// context menu actions
Expand Down Expand Up @@ -158,7 +160,7 @@ void CoinControlDialog::setModel(WalletModel *model)
{
updateView();
//updateLabelLocked();
CoinControlDialog::updateLabels(model, this);
CoinControlDialog::updateLabels(model, coinControl, payAmounts, this);
}
}

Expand Down Expand Up @@ -226,7 +228,7 @@ void CoinControlDialog::buttonSelectAllClicked()
ui->selectAllPushButton->setText("Select None");
}

CoinControlDialog::updateLabels(model, this);
CoinControlDialog::updateLabels(model, coinControl, payAmounts, this);
showHideConsolidationReadyToSend();
}

Expand Down Expand Up @@ -353,7 +355,7 @@ bool CoinControlDialog::filterInputsByValue(const bool& less, const CAmount& inp
// Reenable update signals.
ui->treeWidget->setEnabled(true);

CoinControlDialog::updateLabels(model, this);
CoinControlDialog::updateLabels(model, coinControl, payAmounts, this);

// If the number of inputs selected was limited, then true is returned.
return culled_inputs;
Expand Down Expand Up @@ -596,7 +598,9 @@ void CoinControlDialog::viewItemChanged(QTreeWidgetItem* item, int column)

// selection changed -> update labels
if (ui->treeWidget->isEnabled()) // do not update on every click for (un)select all
CoinControlDialog::updateLabels(model, this);
{
CoinControlDialog::updateLabels(model, coinControl, payAmounts, this);
}
}

showHideConsolidationReadyToSend();
Expand Down Expand Up @@ -633,7 +637,10 @@ QString CoinControlDialog::getPriorityLabel(double dPriority)
else ui->labelLocked->setVisible(false);
}*/

void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
void CoinControlDialog::updateLabels(WalletModel *model,
CCoinControl *coinControl,
QList<qint64>* payAmounts,
QDialog* dialog)
{
if (!model) return;

Expand All @@ -642,7 +649,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
bool fLowOutput = false;
bool fDust = false;
CTransaction txDummy;
foreach(const qint64 &amount, CoinControlDialog::payAmounts)
foreach(const qint64 &amount, *payAmounts)
{
nPayAmount += amount;

Expand Down Expand Up @@ -704,7 +711,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
if (nQuantity > 0)
{
// Bytes
nBytes = nBytesInputs + ((CoinControlDialog::payAmounts.size() > 0 ? CoinControlDialog::payAmounts.size() + 1 : 2) * 34) + 10; // always assume +1 output for change here
nBytes = nBytesInputs + ((payAmounts->size() > 0 ? payAmounts->size() + 1 : 2) * 34) + 10; // always assume +1 output for change here

// Priority
dPriority = dPriorityInputs / nBytes;
Expand Down
11 changes: 6 additions & 5 deletions src/qt/coincontroldialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ class CoinControlDialog : public QDialog
Q_OBJECT

public:
explicit CoinControlDialog(QWidget *parent = 0);
explicit CoinControlDialog(QWidget *parent = 0,
CCoinControl *coinControl = nullptr,
QList<qint64> *payAmounts = nullptr);
~CoinControlDialog();

void setModel(WalletModel *model);

// static because also called from sendcoinsdialog
static void updateLabels(WalletModel*, QDialog*);
static void updateLabels(WalletModel*, CCoinControl*, QList<qint64>*, QDialog*);
static QString getPriorityLabel(double);

static QList<qint64> payAmounts;
static CCoinControl *coinControl;

// This is based on what will guarantee a successful transaction.
const size_t m_inputSelectionLimit;

Expand All @@ -47,6 +46,8 @@ public slots:

private:
Ui::CoinControlDialog *ui;
CCoinControl *coinControl;
QList<qint64> *payAmounts;
WalletModel *model;
int sortColumn;
Qt::SortOrder sortOrder;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/consolidateunspentdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ConsolidateUnspentDialog : public QDialog
Q_OBJECT

public:
explicit ConsolidateUnspentDialog(QWidget *parent = 0, size_t inputSelectionLimit = 600);
explicit ConsolidateUnspentDialog(QWidget *parent = nullptr, size_t inputSelectionLimit = 600);
~ConsolidateUnspentDialog();

void SetAddressList(const std::map<QString, QString>& addressList);
Expand Down
50 changes: 50 additions & 0 deletions src/qt/consolidateunspentwizard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "coincontroldialog.h"
#include "consolidateunspentwizard.h"
#include "consolidateunspentdialog.h"
#include "ui_consolidateunspentwizard.h"

#include "util.h"


ConsolidateUnspentWizard::ConsolidateUnspentWizard(QWidget *parent,
CCoinControl *coinControl,
QList<qint64> *payAmounts) :
QWizard(parent),
ui(new Ui::ConsolidateUnspentWizard),
coinControl(coinControl),
payAmounts(payAmounts)
{
ui->setupUi(this);
this->setStartId(SelectInputsPage);

ui->selectInputsPage->setCoinControl(coinControl);
ui->selectInputsPage->setPayAmounts(payAmounts);

connect(ui->selectInputsPage, SIGNAL(setAddressListSignal(std::map<QString, QString>)),
ui->selectDestinationPage, SLOT(SetAddressList(const std::map<QString, QString>)));

connect(ui->selectInputsPage, SIGNAL(setDefaultAddressSignal(QString)),
ui->selectDestinationPage, SLOT(setDefaultAddressSelection(QString)));

connect(this->button(QWizard::FinishButton), SIGNAL(clicked()), ui->sendPage, SLOT(onFinishButtonClicked()));
connect(ui->sendPage, SIGNAL(selectedConsolidationRecipientSignal(SendCoinsRecipient)),
this, SIGNAL(selectedConsolidationRecipientSignal(SendCoinsRecipient)));
}

ConsolidateUnspentWizard::~ConsolidateUnspentWizard()
{
delete ui;
}

void ConsolidateUnspentWizard::accept()
{
QDialog::accept();
}

void ConsolidateUnspentWizard::setModel(WalletModel *model)
{
this->model = model;

ui->selectInputsPage->setModel(model);
ui->sendPage->setModel(model);
}
51 changes: 51 additions & 0 deletions src/qt/consolidateunspentwizard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef CONSOLIDATEUNSPENTWIZARD_H
#define CONSOLIDATEUNSPENTWIZARD_H

#include "walletmodel.h"

#include <QDialogButtonBox>
#include <QDialog>
#include <QWizard>
#include <QString>
#include <QLabel>

namespace Ui {
class ConsolidateUnspentWizard;
}

class CoinControlDialog;

class ConsolidateUnspentWizard : public QWizard
{
Q_OBJECT

public:
enum Pages
{
SelectInputsPage,
SelectDestinationPage,
SendPage
};

explicit ConsolidateUnspentWizard(QWidget *parent = nullptr,
CCoinControl *coinControl = nullptr,
QList<qint64> *payAmounts = nullptr);
~ConsolidateUnspentWizard();

void setModel(WalletModel *model);

void accept() override;

signals:
void passCoinControlSignal(CCoinControl*);
void selectedConsolidationRecipientSignal(SendCoinsRecipient);
void sendConsolidationTransactionSignal();

private:
Ui::ConsolidateUnspentWizard *ui;
CCoinControl *coinControl;
QList<qint64> *payAmounts;
WalletModel *model;
};

#endif // CONSOLIDATEUNSPENTWIZARD_H
Loading