Skip to content

Commit

Permalink
Merge pull request #2628 from jamescowens/implement_mrc_insufficient_…
Browse files Browse the repository at this point in the history
…funds_display

gui: implement INSUFFICIENT_MATURE_FUNDS status for the mrcmodel
  • Loading branch information
jamescowens authored Jan 22, 2023
2 parents 725be57 + 6991349 commit cf29af3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
19 changes: 17 additions & 2 deletions src/qt/mrcmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ int MRCModel::getMRCOutputLimit()
MRCModel::ModelStatus MRCModel::getMRCModelStatus()
{
if (m_mrc_status == MRCRequestStatus::NOT_VALID_RESEARCHER) {
return MRCModel::NOT_VALID_RESEARCHER;
return MRCModel::ModelStatus::NOT_VALID_RESEARCHER;
} else if (m_mrc_status == MRCRequestStatus::INSUFFICIENT_MATURE_FUNDS) {
return MRCModel::ModelStatus::INSUFFICIENT_MATURE_FUNDS;
} else if (!IsV12Enabled(m_block_height)) {
return MRCModel::ModelStatus::INVALID_BLOCK_VERSION;
} else if (OutOfSyncByAge()) {
Expand Down Expand Up @@ -259,6 +261,18 @@ void MRCModel::refresh() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
// Store this locally so we don't have to get this from the client model, which takes another lock on cs_main.
m_block_height = pindexBest->nHeight;

// Do a balance check before anything else.
if (m_wallet_model) {
CAmount mature_balance = m_wallet_model->getBalance();

if (mature_balance < COIN) {
m_mrc_error |= true;
m_mrc_status = MRCRequestStatus::INSUFFICIENT_MATURE_FUNDS;
m_mrc_error_desc = tr("You must have a mature balance of at least 1 GRC to submit an MRC.");
return;
}
}

if (!IsV12Enabled(pindexBest->nHeight)) {
return;
}
Expand All @@ -274,7 +288,8 @@ void MRCModel::refresh() EXCLUSIVE_LOCKS_REQUIRED(cs_main)

m_mrc_output_limit = static_cast<int>(GetMRCOutputLimit(pindexBest->nVersion, false));

// Do a first run with m_mrc_min_fee = 0 to compute the mrc min fee required.
// Do a first run with m_mrc_min_fee = 0 to compute the mrc min fee required. The lock on pwalletMain is taken in the
// call scope of CreateMRC.
try {
GRC::CreateMRC(pindexBest, m_mrc, m_reward, m_mrc_min_fee, pwalletMain, m_wallet_locked);
} catch (GRC::MRC_error& e) {
Expand Down
6 changes: 4 additions & 2 deletions src/qt/mrcmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ enum class MRCRequestStatus
ZERO_PAYOUT,
EXCESSIVE_FEE,
WALLET_LOCKED,
SUBMIT_ERROR
SUBMIT_ERROR,
INSUFFICIENT_MATURE_FUNDS
};

//!
Expand Down Expand Up @@ -59,7 +60,8 @@ class MRCModel : public QObject
NOT_VALID_RESEARCHER,
INVALID_BLOCK_VERSION,
OUT_OF_SYNC,
NO_BLOCK_UPDATE_FROM_INIT
NO_BLOCK_UPDATE_FROM_INIT,
INSUFFICIENT_MATURE_FUNDS
};

WalletModel* getWalletModel();
Expand Down
7 changes: 6 additions & 1 deletion src/qt/mrcrequestpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "qspinbox.h"
#include "sync.h"
#include "mrcrequestpage.h"
#include "ui_mrcrequestpage.h"
#include "forms/ui_mrcrequestpage.h"
#include "walletmodel.h"
#include "optionsmodel.h"
#include "qt/decoration.h"
Expand Down Expand Up @@ -269,6 +269,11 @@ void MRCRequestPage::showMRCStatus(const MRCModel::ModelStatus& status) {
ui->waitForNextBlockUpdateFrame->show();
ui->mrcStatusSubmitFrame->hide();
return;
case MRCModel::ModelStatus::INSUFFICIENT_MATURE_FUNDS:
ui->waitForBlockUpdateLabel->setText(tr("You must have a mature balance of at least 1 GRC to submit an MRC."));
ui->waitForNextBlockUpdateFrame->show();
ui->mrcStatusSubmitFrame->hide();
return;
case MRCModel::ModelStatus::VALID:
ui->waitForBlockUpdateLabel->setText("");
ui->waitForNextBlockUpdateFrame->hide();
Expand Down

0 comments on commit cf29af3

Please sign in to comment.