-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmultisenddialog.cpp
207 lines (177 loc) · 5.99 KB
/
multisenddialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include "multisenddialog.h"
#include "ui_multisenddialog.h"
#include "walletmodel.h"
#include "base58.h"
#include "addressbookpage.h"
#include "init.h"
#include <QMessageBox>
#include <QLineEdit>
#include <boost/lexical_cast.hpp>
using namespace std;
using namespace boost;
MultiSendDialog::MultiSendDialog(QWidget *parent) :
QWidget(parent),
ui(new Ui::MultiSendDialog),
model(0)
{
ui->setupUi(this);
}
MultiSendDialog::~MultiSendDialog()
{
delete ui;
}
void MultiSendDialog::setModel(WalletModel *model)
{
this->model = model;
}
void MultiSendDialog::setAddress(const QString &address)
{
setAddress(address, ui->multiSendAddressEdit);
}
void MultiSendDialog::setAddress(const QString &address, QLineEdit *addrEdit)
{
addrEdit->setText(address);
addrEdit->setFocus();
}
void MultiSendDialog::on_addressBookButton_clicked()
{
if (model && model->getAddressTableModel())
{
AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
dlg.setModel(model->getAddressTableModel());
if (dlg.exec())
setAddress(dlg.getReturnValue(), ui->multiSendAddressEdit);
}
}
void MultiSendDialog::on_viewButton_clicked()
{
std::pair<std::string, int> pMultiSend;
std::string strMultiSendPrint = "";
if(pwalletMain->fMultiSend)
strMultiSendPrint += "MultiSend Active\n";
else
strMultiSendPrint += "MultiSend Not Active\n";
for(int i = 0; i < (int)pwalletMain->vMultiSend.size(); i++)
{
pMultiSend = pwalletMain->vMultiSend[i];
strMultiSendPrint += pMultiSend.first.c_str();
strMultiSendPrint += " - ";
strMultiSendPrint += boost::lexical_cast<string>(pMultiSend.second);
strMultiSendPrint += "% \n";
}
ui->message->setProperty("status", "ok");
ui->message->style()->polish(ui->message);
ui->message->setText(QString(strMultiSendPrint.c_str()));
return;
}
void MultiSendDialog::on_addButton_clicked()
{
bool fValidConversion = false;
std::string strAddress = ui->multiSendAddressEdit->text().toStdString();
if (!CBitcoinAddress(strAddress).IsValid())
{
ui->message->setProperty("status", "error");
ui->message->style()->polish(ui->message);
ui->message->setText(tr("The entered address:\n") + ui->multiSendAddressEdit->text() + tr(" is invalid.\nPlease check the address and try again."));
ui->multiSendAddressEdit->setFocus();
return;
}
int nMultiSendPercent = ui->multiSendPercentEdit->text().toInt(&fValidConversion, 10);
int nSumMultiSend = 0;
for(int i = 0; i < (int)pwalletMain->vMultiSend.size(); i++)
nSumMultiSend += pwalletMain->vMultiSend[i].second;
if(nSumMultiSend + nMultiSendPercent > 100)
{
ui->message->setProperty("status", "error");
ui->message->style()->polish(ui->message);
ui->message->setText(tr("The total amount of your MultiSend vector is over 100% of your stake reward\n"));
ui->multiSendAddressEdit->setFocus();
return;
}
if (!fValidConversion || nMultiSendPercent > 100 || nMultiSendPercent <= 0)
{
ui->message->setProperty("status", "error");
ui->message->style()->polish(ui->message);
ui->message->setText(tr("Please Enter 1 - 100 for percent."));
ui->multiSendPercentEdit->setFocus();
return;
}
std::pair<std::string, int> pMultiSend;
pMultiSend.first = strAddress;
pMultiSend.second = nMultiSendPercent;
pwalletMain->vMultiSend.push_back(pMultiSend);
ui->message->setProperty("status", "ok");
ui->message->style()->polish(ui->message);
std::string strMultiSendPrint = "";
for(int i = 0; i < (int)pwalletMain->vMultiSend.size(); i++)
{
pMultiSend = pwalletMain->vMultiSend[i];
strMultiSendPrint += pMultiSend.first.c_str();
strMultiSendPrint += " - ";
strMultiSendPrint += boost::lexical_cast<string>(pMultiSend.second);
strMultiSendPrint += "% \n";
}
CWalletDB walletdb(pwalletMain->strWalletFile);
walletdb.WriteMultiSend(pwalletMain->vMultiSend);
ui->message->setText(tr("MultiSend Vector\n") + QString(strMultiSendPrint.c_str()));
return;
}
void MultiSendDialog::on_deleteButton_clicked()
{
std::vector<std::pair<std::string, int> > vMultiSendTemp = pwalletMain->vMultiSend;
std::string strAddress = ui->multiSendAddressEdit->text().toStdString();
bool fRemoved = false;
for(int i = 0; i < (int)pwalletMain->vMultiSend.size(); i++)
{
if(pwalletMain->vMultiSend[i].first == strAddress)
{
pwalletMain->vMultiSend.erase(pwalletMain->vMultiSend.begin() + i);
fRemoved = true;
}
}
CWalletDB walletdb(pwalletMain->strWalletFile);
if(!walletdb.EraseMultiSend(vMultiSendTemp))
fRemoved = false;
if(!walletdb.WriteMultiSend(pwalletMain->vMultiSend))
fRemoved = false;
if(fRemoved)
ui->message->setText(tr("Removed ") + QString(strAddress.c_str()));
else
ui->message->setText(tr("Could not locate address\n"));
return;
}
void MultiSendDialog::on_activateButton_clicked()
{
std::string strRet = "";
if(pwalletMain->vMultiSend.size() < 1)
strRet = "Unable to activate MultiSend, check MultiSend vector\n";
else if(CBitcoinAddress(pwalletMain->vMultiSend[0].first).IsValid())
{
pwalletMain->fMultiSend = true;
CWalletDB walletdb(pwalletMain->strWalletFile);
if(!walletdb.WriteMSettings(true, pwalletMain->nLastMultiSendHeight))
strRet = "MultiSend activated but writing settings to DB failed";
else
strRet = "MultiSend activated";
}
else
strRet = "First Address Not Valid";
ui->message->setProperty("status", "ok");
ui->message->style()->polish(ui->message);
ui->message->setText(tr(strRet.c_str()));
return;
}
void MultiSendDialog::on_disableButton_clicked()
{
std::string strRet = "";
pwalletMain->fMultiSend = false;
CWalletDB walletdb(pwalletMain->strWalletFile);
if(!walletdb.WriteMSettings(false, pwalletMain->nLastMultiSendHeight))
strRet = "MultiSend deactivated but writing settings to DB failed";
else
strRet = "MultiSend deactivated";
ui->message->setProperty("status", "");
ui->message->style()->polish(ui->message);
ui->message->setText(tr(strRet.c_str()));
return;
}