Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.73 KB | None | 0 0
  1. bool CommunityFundCreateProposalDialog::click_pushButtonCreateProposal()
  2. {
  3.     if(this->validate())
  4.     {
  5.         LOCK2(cs_main, pwalletMain->cs_wallet);
  6.  
  7.         CNavCoinAddress address("NQFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ"); // Dummy address
  8.         CWalletTx wtx;
  9.         bool fSubtractFeeFromAmount = false;
  10.  
  11.         std::string Address = ui->lineEditNavcoinAddress->text().toStdString().c_str();
  12.  
  13.         CAmount nReqAmount = ui->lineEditRequestedAmount->value();
  14.  
  15.         int64_t nDeadline = ui->spinBoxDays->value()*24*60*60 + ui->spinBoxHours->value()*60*60 + ui->spinBoxMinutes->value()*60;
  16.  
  17.         string sDesc = ui->plainTextEditDescription->toPlainText().toStdString();
  18.  
  19.         UniValue strDZeel(UniValue::VOBJ);
  20.  
  21.         strDZeel.push_back(Pair("n",nReqAmount));
  22.         strDZeel.push_back(Pair("a",Address));
  23.         strDZeel.push_back(Pair("d",nDeadline));
  24.         strDZeel.push_back(Pair("s",sDesc));
  25.         strDZeel.push_back(Pair("v",IsReducedCFundQuorumEnabled(pindexBestHeader, Params().GetConsensus()) ? CFund::CProposal::CURRENT_VERSION : 2));
  26.  
  27.         wtx.strDZeel = strDZeel.write();
  28.         wtx.nCustomVersion = CTransaction::PROPOSAL_VERSION;
  29.  
  30.         if(wtx.strDZeel.length() > 1024) {
  31.             QMessageBox msgBox(this);
  32.             std::string str = "Please shorten your description\n";
  33.             msgBox.setText(tr(str.c_str()));
  34.             msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole);
  35.             msgBox.setIcon(QMessageBox::Warning);
  36.             msgBox.setWindowTitle("Description too long");
  37.             msgBox.exec();
  38.             return false;
  39.         }
  40.  
  41.         EnsureWalletIsUnlocked();
  42.         CAmount curBalance = pwalletMain->GetBalance();
  43.  
  44.         if (curBalance < 50) {
  45.             QMessageBox msgBox(this);
  46.             std::string str = "You require at least 50 NAV mature and available to create a proposal\n";
  47.             msgBox.setText(tr(str.c_str()));
  48.             msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole);
  49.             msgBox.setIcon(QMessageBox::Warning);
  50.             msgBox.setWindowTitle("Insufficient NAV");
  51.             msgBox.exec();
  52.             return false;
  53.         }
  54.  
  55.         // Parse NavCoin address (currently crashes wallet)
  56.         CScript scriptPubKey = GetScriptForDestination(address.Get());
  57.  
  58.         //create partial proposal object with all nessesary display fields from input and create confirmation dialog
  59.         {
  60.             CFund::CProposal *proposal = new CFund::CProposal();
  61.             proposal->Address = Address;
  62.             proposal->nAmount = nReqAmount;
  63.             proposal->strDZeel = sDesc;
  64.             proposal->nDeadline = nDeadline;
  65.  
  66.             SendCommunityFundDialog dlg(this, proposal, 10);
  67.             if(dlg.exec() == QDialog::Rejected)
  68.             {
  69.                 // User Declined to make the proposal
  70.                 return false;
  71.             }
  72.             else {
  73.                 // User accepted making the proposal
  74.                 CFund::SetScriptForCommunityFundContribution(scriptPubKey);
  75.  
  76.                 // Create and send the transaction
  77.                 CReserveKey reservekey(pwalletMain);
  78.                 CAmount nValue = 50;
  79.                 CAmount nFeeRequired;
  80.                 std::string strError;
  81.                 vector<CRecipient> vecSend;
  82.                 int nChangePosRet = -1;
  83.                 CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount, ""};
  84.                 vecSend.push_back(recipient);
  85.  
  86.                 bool created_proposal = true;
  87.  
  88.                 if (!pwalletMain->CreateTransaction(vecSend, wtx, reservekey, nFeeRequired, nChangePosRet, strError, NULL, true, "")) {
  89.                     if (!fSubtractFeeFromAmount && nValue + nFeeRequired > pwalletMain->GetBalance())
  90.                         created_proposal = false;
  91.                 }
  92.                 if (!pwalletMain->CommitTransaction(wtx, reservekey))
  93.                     created_proposal = false;
  94.  
  95.                 // If the proposal was successfully made, confirm to the user it was made
  96.                 if (created_proposal) {
  97.                     // Display success UI
  98.                     CommunityFundSuccessDialog dlg(this, proposal);
  99.                     dlg.exec();
  100.                     return true;
  101.                 }
  102.                 else {
  103.                     // Display something went wrong UI
  104.                     QMessageBox msgBox(this);
  105.                     std::string str = "Proposal creation failed\n";
  106.                     msgBox.setText(tr(str.c_str()));
  107.                     msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole);
  108.                     msgBox.setIcon(QMessageBox::Warning);
  109.                     msgBox.setWindowTitle("Error");
  110.                     msgBox.exec();
  111.                     return false;
  112.                 }
  113.             }
  114.         }      
  115.     }
  116.     else
  117.     {
  118.         QMessageBox msgBox(this);
  119.         std::string str = "Please enter a valid:\n";
  120.         if(!ui->lineEditNavcoinAddress->isValid() || (ui->lineEditNavcoinAddress->text() == QString("")))
  121.             str += "- Address\n";
  122.         if(!ui->lineEditRequestedAmount->validate())
  123.             str += "- Requested Amount\n";
  124.         if(ui->plainTextEditDescription->toPlainText() == QString("") || ui->plainTextEditDescription->toPlainText().size() <= 0)
  125.             str += "- Description\n";
  126.         if((ui->spinBoxDays->value()*24*60*60 + ui->spinBoxHours->value()*60*60 + ui->spinBoxMinutes->value()*60) <= 0)
  127.             str += "- Duration\n";
  128.  
  129.         msgBox.setText(tr(str.c_str()));
  130.         msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole);
  131.         msgBox.setIcon(QMessageBox::Warning);
  132.         msgBox.setWindowTitle("Please enter valid fields");
  133.         msgBox.exec();
  134.         return false;
  135.     }
  136.     return true;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement