Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool CommunityFundCreateProposalDialog::click_pushButtonCreateProposal()
- {
- if(this->validate())
- {
- LOCK2(cs_main, pwalletMain->cs_wallet);
- CNavCoinAddress address("NQFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ"); // Dummy address
- CWalletTx wtx;
- bool fSubtractFeeFromAmount = false;
- std::string Address = ui->lineEditNavcoinAddress->text().toStdString().c_str();
- CAmount nReqAmount = ui->lineEditRequestedAmount->value();
- int64_t nDeadline = ui->spinBoxDays->value()*24*60*60 + ui->spinBoxHours->value()*60*60 + ui->spinBoxMinutes->value()*60;
- string sDesc = ui->plainTextEditDescription->toPlainText().toStdString();
- UniValue strDZeel(UniValue::VOBJ);
- strDZeel.push_back(Pair("n",nReqAmount));
- strDZeel.push_back(Pair("a",Address));
- strDZeel.push_back(Pair("d",nDeadline));
- strDZeel.push_back(Pair("s",sDesc));
- strDZeel.push_back(Pair("v",IsReducedCFundQuorumEnabled(pindexBestHeader, Params().GetConsensus()) ? CFund::CProposal::CURRENT_VERSION : 2));
- wtx.strDZeel = strDZeel.write();
- wtx.nCustomVersion = CTransaction::PROPOSAL_VERSION;
- if(wtx.strDZeel.length() > 1024) {
- QMessageBox msgBox(this);
- std::string str = "Please shorten your description\n";
- msgBox.setText(tr(str.c_str()));
- msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole);
- msgBox.setIcon(QMessageBox::Warning);
- msgBox.setWindowTitle("Description too long");
- msgBox.exec();
- return false;
- }
- EnsureWalletIsUnlocked();
- CAmount curBalance = pwalletMain->GetBalance();
- if (curBalance < 50) {
- QMessageBox msgBox(this);
- std::string str = "You require at least 50 NAV mature and available to create a proposal\n";
- msgBox.setText(tr(str.c_str()));
- msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole);
- msgBox.setIcon(QMessageBox::Warning);
- msgBox.setWindowTitle("Insufficient NAV");
- msgBox.exec();
- return false;
- }
- // Parse NavCoin address (currently crashes wallet)
- CScript scriptPubKey = GetScriptForDestination(address.Get());
- //create partial proposal object with all nessesary display fields from input and create confirmation dialog
- {
- CFund::CProposal *proposal = new CFund::CProposal();
- proposal->Address = Address;
- proposal->nAmount = nReqAmount;
- proposal->strDZeel = sDesc;
- proposal->nDeadline = nDeadline;
- SendCommunityFundDialog dlg(this, proposal, 10);
- if(dlg.exec() == QDialog::Rejected)
- {
- // User Declined to make the proposal
- return false;
- }
- else {
- // User accepted making the proposal
- CFund::SetScriptForCommunityFundContribution(scriptPubKey);
- // Create and send the transaction
- CReserveKey reservekey(pwalletMain);
- CAmount nValue = 50;
- CAmount nFeeRequired;
- std::string strError;
- vector<CRecipient> vecSend;
- int nChangePosRet = -1;
- CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount, ""};
- vecSend.push_back(recipient);
- bool created_proposal = true;
- if (!pwalletMain->CreateTransaction(vecSend, wtx, reservekey, nFeeRequired, nChangePosRet, strError, NULL, true, "")) {
- if (!fSubtractFeeFromAmount && nValue + nFeeRequired > pwalletMain->GetBalance())
- created_proposal = false;
- }
- if (!pwalletMain->CommitTransaction(wtx, reservekey))
- created_proposal = false;
- // If the proposal was successfully made, confirm to the user it was made
- if (created_proposal) {
- // Display success UI
- CommunityFundSuccessDialog dlg(this, proposal);
- dlg.exec();
- return true;
- }
- else {
- // Display something went wrong UI
- QMessageBox msgBox(this);
- std::string str = "Proposal creation failed\n";
- msgBox.setText(tr(str.c_str()));
- msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole);
- msgBox.setIcon(QMessageBox::Warning);
- msgBox.setWindowTitle("Error");
- msgBox.exec();
- return false;
- }
- }
- }
- }
- else
- {
- QMessageBox msgBox(this);
- std::string str = "Please enter a valid:\n";
- if(!ui->lineEditNavcoinAddress->isValid() || (ui->lineEditNavcoinAddress->text() == QString("")))
- str += "- Address\n";
- if(!ui->lineEditRequestedAmount->validate())
- str += "- Requested Amount\n";
- if(ui->plainTextEditDescription->toPlainText() == QString("") || ui->plainTextEditDescription->toPlainText().size() <= 0)
- str += "- Description\n";
- if((ui->spinBoxDays->value()*24*60*60 + ui->spinBoxHours->value()*60*60 + ui->spinBoxMinutes->value()*60) <= 0)
- str += "- Duration\n";
- msgBox.setText(tr(str.c_str()));
- msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole);
- msgBox.setIcon(QMessageBox::Warning);
- msgBox.setWindowTitle("Please enter valid fields");
- msgBox.exec();
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement