Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui: Initial implementation of GUI MRC submission form #2513

Merged
merged 21 commits into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
85a0a3f
Add mrcmodel.h/cpp skeletons
jamescowens May 8, 2022
abe3ca5
Add mrcrequestpage.h/cpp skeletons
jamescowens May 8, 2022
55e4d16
Add mrcrequestpage.ui form skeleton
jamescowens May 8, 2022
4c8a56b
Hook in skeleton mrcmodel
jamescowens May 8, 2022
553d7ef
Add MRCChanged core signal
jamescowens May 8, 2022
98b17f3
Wire up MRCChanged signal to AcceptToMemoryPool and Validate in the core
jamescowens May 8, 2022
aaa99f6
Prototype implementation of mrcmodel and mrcrequestpage
jamescowens May 9, 2022
8d927d1
Redo memory pool loop in MRCModel::refresh() and createmrcrewards
jamescowens May 13, 2022
8b4d6c5
Add ModelStatus and string translations
jamescowens May 13, 2022
152c64d
Tweak MRCModel::refresh() to properly handle already submitted MRC
jamescowens May 14, 2022
a1006b5
Implement check and status for invalid researcher
jamescowens May 14, 2022
fc562b9
Implement showHideMRCToolButton() and associated signals
jamescowens May 14, 2022
f8eed2a
Add documentation to mrcmodel and mrcrequestpage
jamescowens May 14, 2022
34ce424
Correct spelling error in comments in mrcmodel.cpp
jamescowens May 14, 2022
0b30500
Implementation of mrcFeeBoostRaiseToMinimumButton
jamescowens May 15, 2022
22f8053
Implement STALE_CANCEL state
jamescowens May 15, 2022
092b242
Move OutOfSyncByAge check in MRCModel::refresh
jamescowens May 16, 2022
4b9dc16
Fix mrc request tooltip opening up more than one mrc request page
jamescowens May 16, 2022
6b1caaa
Remove detailed debug logging and clean up comments
jamescowens May 16, 2022
c85fe7c
Minor cleanup of commented code, a comment misspelling
jamescowens May 20, 2022
6167cab
Fix string handling in error handler in submitMRC
jamescowens May 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ QT_FORMS_UI = \
qt/forms/editaddressdialog.ui \
qt/forms/favoritespage.ui \
qt/forms/intro.ui \
qt/forms/mrcrequestpage.ui \
qt/forms/noresult.ui \
qt/forms/optionsdialog.ui \
qt/forms/overviewpage.ui \
Expand Down Expand Up @@ -145,6 +146,8 @@ QT_MOC_CPP = \
qt/moc_favoritespage.cpp \
qt/moc_guiutil.cpp \
qt/moc_intro.cpp \
qt/moc_mrcmodel.cpp \
qt/moc_mrcrequestpage.cpp \
qt/moc_monitoreddatamapper.cpp \
qt/moc_noresult.cpp \
qt/moc_notificator.cpp \
Expand Down Expand Up @@ -252,6 +255,8 @@ GRIDCOINRESEARCH_QT_H = \
qt/macnotificationhandler.h \
qt/macos_appnap.h \
qt/monitoreddatamapper.h \
qt/mrcmodel.h \
qt/mrcrequestpage.h \
qt/noresult.h \
qt/notificator.h \
qt/optionsdialog.h \
Expand Down Expand Up @@ -335,6 +340,8 @@ GRIDCOINRESEARCH_QT_CPP = \
qt/guiutil.cpp \
qt/intro.cpp \
qt/monitoreddatamapper.cpp \
qt/mrcmodel.cpp \
qt/mrcrequestpage.cpp \
qt/noresult.cpp \
qt/notificator.cpp \
qt/optionsdialog.cpp \
Expand Down
18 changes: 8 additions & 10 deletions src/gridcoin/mrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void GRC::CreateMRC(CBlockIndex* pindex,
MRC& mrc,
CAmount &nReward,
CAmount &fee,
CWallet* pwallet) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
CWallet* pwallet, bool no_sign) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
{
const GRC::ResearcherPtr researcher = GRC::Researcher::Get();

Expand Down Expand Up @@ -356,16 +356,14 @@ void GRC::CreateMRC(CBlockIndex* pindex,
}
}

if (!TrySignMRC(pwallet, pindex, mrc)) {
if (!no_sign && !TrySignMRC(pwallet, pindex, mrc)) {
throw MRC_error(strprintf("%s: Failed to sign mrc.", __func__));
}

LogPrintf(
"INFO: %s: for %s mrc %s magnitude %d Research %s",
__func__,
mrc.m_mining_id.ToString(),
FormatMoney(nReward),
mrc.m_magnitude,
FormatMoney(mrc.m_research_subsidy));
LogPrintf("INFO: %s: for %s mrc request created: magnitude %d, research rewards %s, mrc fee %s.",
__func__,
mrc.m_mining_id.ToString(),
mrc.m_magnitude,
FormatMoney(mrc.m_research_subsidy),
FormatMoney(mrc.m_fee));
}

3 changes: 2 additions & 1 deletion src/gridcoin/mrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,10 @@ class MRCContractHandler : public IContractHandler
//! \param nReward: The research reward (out parameter)
//! \param fee: The MRC fees to be taken out of the research reward (in/out parameter)
//! \param pwallet: The wallet object
//! \param no_sign: If true, don't sign the MRC (trial run).
//! \return
//!
void CreateMRC(CBlockIndex* pindex, MRC& mrc, CAmount &nReward, CAmount &fee, CWallet* pwallet);
void CreateMRC(CBlockIndex* pindex, MRC& mrc, CAmount &nReward, CAmount &fee, CWallet* pwallet, bool no_sign = false);


} // namespace GRC
Expand Down
16 changes: 16 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool* pfMissingInput
// from the same CPID in the accept to memory pool stage.
//
// We have implemented a bloom filter to help with the overhead.
bool tx_contains_valid_mrc = false;

for (const auto& contract : tx.GetContracts()) {
if (contract.m_type == GRC::ContractType::MRC) {
GRC::MRC mrc = contract.CopyPayloadAs<GRC::MRC>();
Expand All @@ -428,6 +430,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool* pfMissingInput
if ((mempool.m_mrc_bloom & k) != k) {
// The cpid definitely does not exist in the mempool.
mempool.m_mrc_bloom |= k;
tx_contains_valid_mrc = true;

continue;
}
// The cpid might exist in the mempool.
Expand Down Expand Up @@ -464,6 +468,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool* pfMissingInput

mempool.m_mrc_bloom_dirty = false;
if (found) return false;

tx_contains_valid_mrc = true;
}
}

Expand Down Expand Up @@ -550,6 +556,11 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool* pfMissingInput

return false;
}

// If we accepted a transaction with a valid mrc contract, then signal MRC changed.
if (tx_contains_valid_mrc) {
uiInterface.MRCChanged();
}
}

// Store transaction in memory
Expand Down Expand Up @@ -1655,6 +1666,11 @@ class ClaimValidator
}

// If we arrive here, the MRCRewards are valid.

// Signal MRCChanged because this method is called from ConnectBlock and the successful validation of an MRC
// indicates an MRC state change.
uiInterface.MRCChanged();

return true;
}
}; // ClaimValidator
Expand Down
3 changes: 3 additions & 0 deletions src/node/ui_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct UISignals {
boost::signals2::signal<CClientUIInterface::MinerStatusChangedSig> MinerStatusChanged;
boost::signals2::signal<CClientUIInterface::ResearcherChangedSig> ResearcherChanged;
boost::signals2::signal<CClientUIInterface::AccrualChangedFromStakeOrMRCSig> AccrualChangedFromStakeOrMRC;
boost::signals2::signal<CClientUIInterface::MRCChangedSig> MRCChanged;
boost::signals2::signal<CClientUIInterface::BeaconChangedSig> BeaconChanged;
boost::signals2::signal<CClientUIInterface::NewPollReceivedSig> NewPollReceived;
boost::signals2::signal<CClientUIInterface::NotifyScraperEventSig> NotifyScraperEvent;
Expand Down Expand Up @@ -49,6 +50,7 @@ ADD_SIGNALS_IMPL_WRAPPER(BannedListChanged);
ADD_SIGNALS_IMPL_WRAPPER(MinerStatusChanged);
ADD_SIGNALS_IMPL_WRAPPER(ResearcherChanged);
ADD_SIGNALS_IMPL_WRAPPER(AccrualChangedFromStakeOrMRC);
ADD_SIGNALS_IMPL_WRAPPER(MRCChanged);
ADD_SIGNALS_IMPL_WRAPPER(BeaconChanged);
ADD_SIGNALS_IMPL_WRAPPER(NewPollReceived);
ADD_SIGNALS_IMPL_WRAPPER(NotifyScraperEvent);
Expand All @@ -73,6 +75,7 @@ void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListCha
void CClientUIInterface::MinerStatusChanged(bool staking, double coin_weight) { return g_ui_signals.MinerStatusChanged(staking, coin_weight); }
void CClientUIInterface::ResearcherChanged() { return g_ui_signals.ResearcherChanged(); }
void CClientUIInterface::AccrualChangedFromStakeOrMRC() { return g_ui_signals.AccrualChangedFromStakeOrMRC(); }
void CClientUIInterface::MRCChanged() { return g_ui_signals.MRCChanged(); }
void CClientUIInterface::BeaconChanged() { return g_ui_signals.BeaconChanged(); }
void CClientUIInterface::NewPollReceived(int64_t poll_time) { return g_ui_signals.NewPollReceived(poll_time); }
void CClientUIInterface::NotifyAlertChanged(const uint256 &hash, ChangeType status) { return g_ui_signals.NotifyAlertChanged(hash, status); }
Expand Down
3 changes: 3 additions & 0 deletions src/node/ui_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ class CClientUIInterface
/** Walletholder accrual changed as a result of stake or MRC to the walletholder */
ADD_SIGNALS_DECL_WRAPPER(AccrualChangedFromStakeOrMRC, void);

/** MRC state changed */
ADD_SIGNALS_DECL_WRAPPER(MRCChanged, void);

/** Beacon changed */
ADD_SIGNALS_DECL_WRAPPER(BeaconChanged, void);

Expand Down
3 changes: 3 additions & 0 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "clientmodel.h"
#include "walletmodel.h"
#include "researcher/researchermodel.h"
#include "mrcmodel.h"
#include "voting/votingmodel.h"
#include "optionsmodel.h"
#include "guiutil.h"
Expand Down Expand Up @@ -663,11 +664,13 @@ int StartGridcoinQt(int argc, char *argv[], QApplication& app, OptionsModel& opt
ClientModel clientModel(&optionsModel);
WalletModel walletModel(pwalletMain, &optionsModel);
ResearcherModel researcherModel;
MRCModel mrcModel(&walletModel, &clientModel, &researcherModel);
VotingModel votingModel(clientModel, optionsModel, walletModel);

window.setResearcherModel(&researcherModel);
window.setClientModel(&clientModel);
window.setWalletModel(&walletModel);
window.setMRCModel(&mrcModel);
window.setVotingModel(&votingModel);

// If -min option passed, start window minimized.
Expand Down
11 changes: 11 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,17 @@ void BitcoinGUI::setResearcherModel(ResearcherModel *researcherModel)
connect(researcherModel, &ResearcherModel::beaconChanged, this, &BitcoinGUI::updateBeaconIcon);
}

void BitcoinGUI::setMRCModel(MRCModel *mrcModel)
{
m_mrc_model = mrcModel;

if (!mrcModel) {
return;
}

overviewPage->setMRCModel(mrcModel);
}

void BitcoinGUI::setVotingModel(VotingModel *votingModel)
{
this->votingModel = votingModel;
Expand Down
7 changes: 7 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class TransactionTableModel;
class ClientModel;
class WalletModel;
class ResearcherModel;
class MRCModel;
class VotingModel;
class TransactionView;
class OverviewPage;
Expand Down Expand Up @@ -69,6 +70,11 @@ class BitcoinGUI : public QMainWindow
*/
void setResearcherModel(ResearcherModel *researcherModel);

/** Set the MRC model.
The MRC model provides the model for MRC payment requests.
*/
void setMRCModel(MRCModel *mrcModel);

/** Set the voting model.
The voting model facilitates presentation of and interaction with network polls and votes.
*/
Expand All @@ -91,6 +97,7 @@ class BitcoinGUI : public QMainWindow
ClientModel *clientModel;
WalletModel *walletModel;
ResearcherModel *researcherModel;
MRCModel *m_mrc_model;
VotingModel *votingModel;

QStackedWidget *centralWidget;
Expand Down
Loading