forked from davidlatapie/HyperStake
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathcreateproposaldialog.cpp
More file actions
133 lines (115 loc) · 4.03 KB
/
Copy pathcreateproposaldialog.cpp
File metadata and controls
133 lines (115 loc) · 4.03 KB
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
#include "createproposaldialog.h"
#include "ui_createproposaldialog.h"
#include "init.h"
#include "main.h"
#include "walletmodel.h"
#include "voteproposal.h"
#include "voteobject.h"
#include "base58.h"
#include <QLineEdit>
#include <QMessageBox>
CreateProposalDialog::CreateProposalDialog(QWidget* parent) :
QDialog(parent),
ui(new Ui::CreateProposalDialog)
{
ui->setupUi(this);
walletModel = nullptr;
Clear();
}
CreateProposalDialog::~CreateProposalDialog()
{
delete ui;
}
void CreateProposalDialog::SetWalletModel(WalletModel* model)
{
walletModel = model;
}
void CreateProposalDialog::on_button_CreateProposal_clicked()
{
QString strName = ui->lineEdit_Name->text();
if (!strName.size() || strName.size() > MAX_CHAR_NAME) {
QMessageBox msg;
msg.setText(tr("Name needs to be between 1 and %1 characters long").arg(MAX_CHAR_NAME));
msg.exec();
return;
}
QString strAbstract = ui->lineEdit_Abstract->text();
if (!strAbstract.size() || strAbstract.size() > MAX_CHAR_ABSTRACT) {
QMessageBox msg;
msg.setText(tr("Abstract needs to be between 1 and %1 characters long").arg(MAX_CHAR_ABSTRACT));
msg.exec();
return;
}
int nStartHeight = ui->lineEdit_StartBlock->text().toInt();
if (nStartHeight <= nBestHeight || nStartHeight > nBestHeight + MAX_BLOCKS_IN_FUTURE) {
QMessageBox msg;
msg.setText(tr("Start height needs to be greater than current height (%1) and less than %2.").arg(nBestHeight).arg(nStartHeight + MAX_BLOCKS_IN_FUTURE));
msg.exec();
return;
}
int nCheckSpan = ui->lineEdit_Length->text().toInt();
if (!nCheckSpan || nCheckSpan > MAX_CHECKSPAN) {
QMessageBox msg;
msg.setText(tr("Voting length needs to be between 1 and %1 blocks").arg(MAX_CHECKSPAN));
msg.exec();
return;
}
int nMaxFee = ui->lineEdit_Max_Fee->text().toInt();
if (nMaxFee < CVoteProposal::BASE_FEE) {
QMessageBox msg;
msg.setText(tr("Max Fee must be greater than or equal to %1").arg(CVoteProposal::BASE_FEE));
msg.exec();
return;
}
std::string strRefundAddress = ui->lineEdit_Refund_Address->text().toStdString();
CBitcoinAddress address;
if (strRefundAddress.empty() || !address.SetString(strRefundAddress)) {
QMessageBox msg;
msg.setText(tr("The provided refund address is invalid"));
msg.exec();
return;
}
//Right now only supporting 2 bit votes
int nBitCount = 2;
QString strSize = QString::number(nBitCount);
ui->label_Size_result->setText(strSize);
VoteLocation location;
if(!proposalManager.GetNextLocation(nBitCount, nStartHeight, nCheckSpan, location)) {
QMessageBox msg;
msg.setText(tr("The specified voting span is already full. Try a different start and span."));
msg.exec();
return;
}
//Create the actual proposal
this->proposal = new CVoteProposal(strName.toStdString(), nStartHeight, nCheckSpan, strAbstract.toStdString(), nMaxFee, strRefundAddress);
//Set proposal hash in dialog
uint256 hashProposal = proposal->GetHash();
QString strHash = QString::fromStdString(hashProposal.GetHex());
ui->label_Hash_result->setText(strHash);
if (strHash != "")
ui->button_SendProposal->setDisabled(false);
}
void CreateProposalDialog::on_button_SendProposal_clicked()
{
uint256 txid;
if (!pwalletMain->SendProposal(*proposal, txid)) {
QMessageBox msg;
msg.setText(tr("Failed to send proposal"));
msg.exec();
return;
}
//display dialog showing tx success
QMessageBox msg;
msg.setText(tr("Proposal Sent. TXID: %1").arg(QString::fromStdString(txid.GetHex())));
msg.exec();
Clear();
}
void CreateProposalDialog::Clear()
{
ui->lineEdit_Abstract->clear();
ui->lineEdit_Length->clear();
ui->lineEdit_Name->clear();
ui->lineEdit_StartBlock->clear();
ui->label_Hash_result->setText("(Automatically Generated)");
ui->button_SendProposal->setEnabled(false);
}