From 32b7116a7eb97c0013f42baf0cef7ecc628eedcd Mon Sep 17 00:00:00 2001 From: Barry Deeney Date: Tue, 30 Apr 2019 03:38:48 +0800 Subject: [PATCH 1/7] Added a short bash command for dependencies to build-unix.md --- doc/build-unix.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/build-unix.md b/doc/build-unix.md index 852072ae9..9914c705f 100755 --- a/doc/build-unix.md +++ b/doc/build-unix.md @@ -7,7 +7,11 @@ Some notes on how to build NavCoin Core in Unix. ## Building in Ubuntu 18.04 -You can easily build the dependencies by running the [NavCoin dev tools script here](https://github.com/NAVCoin/navcoin-dev-tools/blob/master/ubuntu-18.04-navcoin-core-dev-setup.sh). +You can easily build the dependencies by running the [NavCoin dev tools script](https://github.com/NAVCoin/navcoin-dev-tools/blob/master/ubuntu-18.04-navcoin-core-dev-setup.sh) using the command bellow. + +```bash +curl -o- https://raw.githubusercontent.com/NAVCoin/navcoin-dev-tools/master/ubuntu-18.04-navcoin-core-dev-setup.sh | bash +``` From the navcoin-core directory, you will still need to: ```bash From 3c9aa50e93034b9ace5e3f55975f8ed6508152ce Mon Sep 17 00:00:00 2001 From: Barry Deeney Date: Tue, 30 Apr 2019 04:45:46 +0800 Subject: [PATCH 2/7] Changes for issue #309 --- src/qt/navcoingui.cpp | 1 - src/qt/overviewpage.cpp | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qt/navcoingui.cpp b/src/qt/navcoingui.cpp index 8d07d3050..723f214ff 100755 --- a/src/qt/navcoingui.cpp +++ b/src/qt/navcoingui.cpp @@ -1697,7 +1697,6 @@ void NavCoinGUI::updateWeight() nWeight = pwalletMain->GetStakeWeight(); } - void NavCoinGUI::updatePrice() { QNetworkAccessManager *manager = new QNetworkAccessManager(); diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index cb840ec9b..f0cb198f8 100755 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -189,6 +189,8 @@ void OverviewPage::setBalance(const CAmount& balance, const CAmount& unconfirmed ui->labelImmature->setText(NavCoinUnits::formatWithUnit(unit, immatureBalance, false, NavCoinUnits::separatorAlways)); ui->labelTotal->setText(NavCoinUnits::formatWithUnit(unit, balance + unconfirmedBalance + stakingBalance, false, NavCoinUnits::separatorAlways)); + updateStakeReportNow(); + bool showStaking = stakingBalance != 0; ui->labelStaking->setVisible(showStaking); From a163b60c195a4cab83afdfc0d0d07873ddcfe579 Mon Sep 17 00:00:00 2001 From: Barry Deeney Date: Tue, 30 Apr 2019 05:28:54 +0800 Subject: [PATCH 3/7] Added the NavCoin Knowledge Base menu item --- src/qt/navcoingui.cpp | 17 +++++++++++++++++ src/qt/navcoingui.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/src/qt/navcoingui.cpp b/src/qt/navcoingui.cpp index 8d07d3050..3bc96ee86 100755 --- a/src/qt/navcoingui.cpp +++ b/src/qt/navcoingui.cpp @@ -129,6 +129,7 @@ NavCoinGUI::NavCoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *n signMessageAction(0), verifyMessageAction(0), aboutAction(0), + infoAction(0), receiveCoinsAction(0), receiveCoinsMenuAction(0), optionsAction(0), @@ -419,6 +420,10 @@ void NavCoinGUI::createActions() aboutAction->setStatusTip(tr("Show information about %1").arg(tr(PACKAGE_NAME))); aboutAction->setMenuRole(QAction::AboutRole); aboutAction->setEnabled(false); + infoAction = new QAction(platformStyle->TextColorIcon(":/icons/address-book"), tr("%1 &Knowledge Base").arg(tr(PACKAGE_NAME)), this); + infoAction->setStatusTip(tr("Open the %1 Knowledge Base in your browser").arg(tr(PACKAGE_NAME))); + infoAction->setMenuRole(QAction::NoRole); + infoAction->setEnabled(false); aboutQtAction = new QAction(platformStyle->TextColorIcon(":/icons/about_qt"), tr("About &Qt"), this); aboutQtAction->setStatusTip(tr("Show information about Qt")); aboutQtAction->setMenuRole(QAction::AboutQtRole); @@ -476,6 +481,7 @@ void NavCoinGUI::createActions() connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); + connect(infoAction, SIGNAL(triggered()), this, SLOT(infoClicked())); connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked())); connect(cfundProposalsAction, SIGNAL(triggered()), this, SLOT(cfundProposalsClicked())); @@ -593,6 +599,7 @@ void NavCoinGUI::createMenuBar() help->addAction(showHelpMessageAction); help->addSeparator(); help->addAction(aboutAction); + help->addAction(infoAction); help->addAction(aboutQtAction); } @@ -913,6 +920,15 @@ void NavCoinGUI::aboutClicked() dlg.exec(); } +void NavCoinGUI::infoClicked() +{ + if(!clientModel) + return; + + QString link = QString("https://info.navcoin.org/"); + QDesktopServices::openUrl(QUrl(link)); +} + void NavCoinGUI::showDebugWindow() { rpcConsole->showNormal(); @@ -1378,6 +1394,7 @@ void NavCoinGUI::showEvent(QShowEvent *event) // enable the debug window when the main window shows up openRPCConsoleAction->setEnabled(true); aboutAction->setEnabled(true); + infoAction->setEnabled(true); optionsAction->setEnabled(true); } diff --git a/src/qt/navcoingui.h b/src/qt/navcoingui.h index bba20ed67..337bd1164 100755 --- a/src/qt/navcoingui.h +++ b/src/qt/navcoingui.h @@ -114,6 +114,7 @@ class NavCoinGUI : public QMainWindow QAction *signMessageAction; QAction *verifyMessageAction; QAction *aboutAction; + QAction *infoAction; QAction *receiveCoinsAction; QAction *receiveCoinsMenuAction; QAction *optionsAction; @@ -257,6 +258,8 @@ private Q_SLOTS: void cfundPaymentRequestsClicked(); /** Show about dialog */ void aboutClicked(); + /** Open NavCoin Knowledge base */ + void infoClicked(); /** Show debug window */ void showDebugWindow(); /** Show debug window and set focus to the console */ From b8ea06c88fde8aa80cab02110bfdc616ee5681b9 Mon Sep 17 00:00:00 2001 From: Barry Deeney Date: Thu, 9 May 2019 08:34:36 +0800 Subject: [PATCH 4/7] Updated all old references to github repo to the current repo address --- contrib/gitian-build.sh | 2 +- contrib/gitian-descriptors/gitian-arm.yml | 2 +- contrib/gitian-descriptors/gitian-linux.yml | 2 +- contrib/gitian-descriptors/gitian-osx.yml | 2 +- contrib/gitian-descriptors/gitian-win.yml | 2 +- doc/gitian-building.md | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/contrib/gitian-build.sh b/contrib/gitian-build.sh index 374600fe1..d33b99402 100755 --- a/contrib/gitian-build.sh +++ b/contrib/gitian-build.sh @@ -17,7 +17,7 @@ osx=true SIGNER= VERSION= commit=false -url=https://github.com/navcoindev/navcoin-core +url=https://github.com/navcoin/navcoin-core proc=2 mem=2000 lxc=true diff --git a/contrib/gitian-descriptors/gitian-arm.yml b/contrib/gitian-descriptors/gitian-arm.yml index 9127ab458..366a58b70 100644 --- a/contrib/gitian-descriptors/gitian-arm.yml +++ b/contrib/gitian-descriptors/gitian-arm.yml @@ -29,7 +29,7 @@ packages: - "python" - "libexpat1-dev" remotes: -- "url": "https://github.com/navcoindev/navcoin-core.git" +- "url": "https://github.com/navcoin/navcoin-core.git" "dir": "navcoin-core" files: [] script: | diff --git a/contrib/gitian-descriptors/gitian-linux.yml b/contrib/gitian-descriptors/gitian-linux.yml index 76312fd9f..bfdc6b8b0 100755 --- a/contrib/gitian-descriptors/gitian-linux.yml +++ b/contrib/gitian-descriptors/gitian-linux.yml @@ -29,7 +29,7 @@ packages: - "python" - "libexpat1-dev" remotes: -- "url": "https://github.com/navcoindev/navcoin-core.git" +- "url": "https://github.com/navcoin/navcoin-core.git" "dir": "navcoin-core" files: [] script: | diff --git a/contrib/gitian-descriptors/gitian-osx.yml b/contrib/gitian-descriptors/gitian-osx.yml index 26616c86e..bc37391f8 100755 --- a/contrib/gitian-descriptors/gitian-osx.yml +++ b/contrib/gitian-descriptors/gitian-osx.yml @@ -29,7 +29,7 @@ packages: - "fonts-tuffy" - "libexpat1-dev" remotes: -- "url": "https://github.com/navcoindev/navcoin-core.git" +- "url": "https://github.com/navcoin/navcoin-core.git" "dir": "navcoin-core" files: - "MacOSX10.11.sdk.tar.gz" diff --git a/contrib/gitian-descriptors/gitian-win.yml b/contrib/gitian-descriptors/gitian-win.yml index a0fd9dd8a..220a6f3b8 100755 --- a/contrib/gitian-descriptors/gitian-win.yml +++ b/contrib/gitian-descriptors/gitian-win.yml @@ -23,7 +23,7 @@ packages: - "python" - "libexpat1-dev" remotes: -- "url": "https://github.com/navcoindev/navcoin-core.git" +- "url": "https://github.com/navcoin/navcoin-core.git" "dir": "navcoin-core" files: [] script: | diff --git a/doc/gitian-building.md b/doc/gitian-building.md index b840eee87..c16ee7448 100755 --- a/doc/gitian-building.md +++ b/doc/gitian-building.md @@ -364,7 +364,7 @@ Output from `gbuild` will look something like remote: Total 57959 (delta 0), reused 0 (delta 0), pack-reused 57958 Receiving objects: 100% (57959/57959), 53.76 MiB | 484.00 KiB/s, done. Resolving deltas: 100% (41590/41590), done. - From https://github.com/navcoindev/navcoin-core + From https://github.com/navcoin/navcoin-core ... (new tags, new branch etc) --- Building for trusty amd64 --- Stopping target if it is up @@ -390,7 +390,7 @@ and inputs. For example: ```bash -URL=https://github.com/navcoindev/navcoin-core.git +URL=https://github.com/navcoin/navcoin-core.git COMMIT=2014_03_windows_unicode_path ./bin/gbuild --commit navcoin-core=${COMMIT} --url navcoin-core=${URL} ../navcoin-core/contrib/gitian-descriptors/gitian-arm.yml ./bin/gbuild --commit navcoin-core=${COMMIT} --url navcoin-core=${URL} ../navcoin-core/contrib/gitian-descriptors/gitian-linux.yml From 12ed154b43359ad91d26c8f310542852c428d30b Mon Sep 17 00:00:00 2001 From: Francis Alec Yap Date: Thu, 9 May 2019 19:51:24 +0800 Subject: [PATCH 5/7] Added password prompt for CFund payment/proposal dialogs --- ...ommunityfundcreatepaymentrequestdialog.cpp | 44 +++++++--------- .../communityfundcreatepaymentrequestdialog.h | 7 ++- src/qt/communityfundcreateproposaldialog.cpp | 51 +++++++++---------- src/qt/communityfundcreateproposaldialog.h | 8 ++- src/qt/communityfundpage.cpp | 2 + 5 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/qt/communityfundcreatepaymentrequestdialog.cpp b/src/qt/communityfundcreatepaymentrequestdialog.cpp index 8bd8b17fc..b8d800ea3 100644 --- a/src/qt/communityfundcreatepaymentrequestdialog.cpp +++ b/src/qt/communityfundcreatepaymentrequestdialog.cpp @@ -1,19 +1,21 @@ #include "communityfundcreatepaymentrequestdialog.h" -#include "ui_communityfundcreatepaymentrequestdialog.h" #include "communityfundsuccessdialog.h" #include "sendcommunityfunddialog.h" +#include "ui_communityfundcreatepaymentrequestdialog.h" #include +#include + +#include "base58.h" #include "consensus/cfund.h" -#include "main.h" -#include "main.cpp" #include "guiconstants.h" -#include "skinize.h" #include "guiutil.h" +#include "main.cpp" +#include "main.h" +#include "skinize.h" #include "sync.h" #include "wallet/wallet.h" -#include "base58.h" -#include +#include "walletmodel.h" std::string random_str(size_t length) { @@ -33,7 +35,8 @@ std::string random_str(size_t length) CommunityFundCreatePaymentRequestDialog::CommunityFundCreatePaymentRequestDialog(QWidget *parent) : QDialog(parent), - ui(new Ui::CommunityFundCreatePaymentRequestDialog) + ui(new Ui::CommunityFundCreatePaymentRequestDialog), + model(0) { ui->setupUi(this); @@ -41,6 +44,11 @@ CommunityFundCreatePaymentRequestDialog::CommunityFundCreatePaymentRequestDialog connect(ui->pushButtonSubmitPaymentRequest, SIGNAL(clicked()), SLOT(click_pushButtonSubmitPaymentRequest())); } +void CommunityFundCreatePaymentRequestDialog::setModel(WalletModel *model) +{ + this->model = model; +} + bool CommunityFundCreatePaymentRequestDialog::validate() { bool isValid = true; @@ -131,24 +139,10 @@ void CommunityFundCreatePaymentRequestDialog::click_pushButtonSubmitPaymentReque } // Ensure wallet is unlocked - if (pwalletMain->IsLocked()) { - QMessageBox msgBox(this); - std::string str = "Please unlock the wallet\n"; - msgBox.setText(tr(str.c_str())); - msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole); - msgBox.setIcon(QMessageBox::Warning); - msgBox.setWindowTitle("Error"); - msgBox.exec(); - return; - } - if (fWalletUnlockStakingOnly) { - QMessageBox msgBox(this); - std::string str = "Wallet is unlocked for staking only\n"; - msgBox.setText(tr(str.c_str())); - msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole); - msgBox.setIcon(QMessageBox::Warning); - msgBox.setWindowTitle("Error"); - msgBox.exec(); + WalletModel::UnlockContext ctx(model->requestUnlock()); + if(!ctx.isValid()) + { + // Unlock wallet was cancelled return; } diff --git a/src/qt/communityfundcreatepaymentrequestdialog.h b/src/qt/communityfundcreatepaymentrequestdialog.h index 541f7b02a..f56e90adb 100644 --- a/src/qt/communityfundcreatepaymentrequestdialog.h +++ b/src/qt/communityfundcreatepaymentrequestdialog.h @@ -1,9 +1,11 @@ #ifndef COMMUNITYFUNDCREATEPAYMENTREQUESTDIALOG_H #define COMMUNITYFUNDCREATEPAYMENTREQUESTDIALOG_H -#include #include "../qvalidatedplaintextedit.h" #include "uint256.h" +#include "walletmodel.h" + +#include namespace Ui { class CommunityFundCreatePaymentRequestDialog; @@ -17,8 +19,11 @@ class CommunityFundCreatePaymentRequestDialog : public QDialog explicit CommunityFundCreatePaymentRequestDialog(QWidget *parent = 0); ~CommunityFundCreatePaymentRequestDialog(); + void setModel(WalletModel *model); + private: Ui::CommunityFundCreatePaymentRequestDialog *ui; + WalletModel *model; bool validate(); bool isActiveProposal(uint256 hash); diff --git a/src/qt/communityfundcreateproposaldialog.cpp b/src/qt/communityfundcreateproposaldialog.cpp index 319a086ef..627e6b2d6 100644 --- a/src/qt/communityfundcreateproposaldialog.cpp +++ b/src/qt/communityfundcreateproposaldialog.cpp @@ -1,25 +1,27 @@ #include "communityfundcreateproposaldialog.h" -#include "ui_communityfundcreateproposaldialog.h" -#include "sendcommunityfunddialog.h" #include "communityfundsuccessdialog.h" +#include "sendcommunityfunddialog.h" +#include "ui_communityfundcreateproposaldialog.h" -#include -#include #include +#include #include +#include +#include +#include "base58.h" #include "guiconstants.h" #include "guiutil.h" -#include "sync.h" -#include "wallet/wallet.h" -#include "base58.h" #include "main.h" -#include #include "qvalidatedspinbox.h" +#include "sync.h" +#include "wallet/wallet.h" +#include "walletmodel.h" CommunityFundCreateProposalDialog::CommunityFundCreateProposalDialog(QWidget *parent) : QDialog(parent), - ui(new Ui::CommunityFundCreateProposalDialog) + ui(new Ui::CommunityFundCreateProposalDialog), + model(0) { ui->setupUi(this); GUIUtil::setupAddressWidget(ui->lineEditNavcoinAddress, this); @@ -57,6 +59,11 @@ CommunityFundCreateProposalDialog::CommunityFundCreateProposalDialog(QWidget *pa ui->labelWarning->setText(QString::fromStdString(warning)); } +void CommunityFundCreateProposalDialog::setModel(WalletModel *model) +{ + this->model = model; +} + // Validate input fields bool CommunityFundCreateProposalDialog::validate() { @@ -103,6 +110,9 @@ void CommunityFundCreateProposalDialog::click_spinBox() { void CommunityFundCreateProposalDialog::click_pushButtonCreateProposal() { + if(!model) + return; + if(this->validate()) { LOCK2(cs_main, pwalletMain->cs_wallet); @@ -147,24 +157,10 @@ void CommunityFundCreateProposalDialog::click_pushButtonCreateProposal() } // Ensure wallet is unlocked - if (pwalletMain->IsLocked()) { - QMessageBox msgBox(this); - std::string str = "Please unlock the wallet\n"; - msgBox.setText(tr(str.c_str())); - msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole); - msgBox.setIcon(QMessageBox::Warning); - msgBox.setWindowTitle("Error"); - msgBox.exec(); - return; - } - if (fWalletUnlockStakingOnly) { - QMessageBox msgBox(this); - std::string str = "Wallet is unlocked for staking only\n"; - msgBox.setText(tr(str.c_str())); - msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole); - msgBox.setIcon(QMessageBox::Warning); - msgBox.setWindowTitle("Error"); - msgBox.exec(); + WalletModel::UnlockContext ctx(model->requestUnlock()); + if(!ctx.isValid()) + { + // Unlock wallet was cancelled return; } @@ -197,7 +193,6 @@ void CommunityFundCreateProposalDialog::click_pushButtonCreateProposal() return; } else { - // User accepted making the proposal // Parse NavCoin address CScript CFContributionScript; diff --git a/src/qt/communityfundcreateproposaldialog.h b/src/qt/communityfundcreateproposaldialog.h index 874687e52..94e1f1932 100644 --- a/src/qt/communityfundcreateproposaldialog.h +++ b/src/qt/communityfundcreateproposaldialog.h @@ -1,8 +1,10 @@ #ifndef COMMUNITYFUNDCREATEPROPOSALDIALOG_H #define COMMUNITYFUNDCREATEPROPOSALDIALOG_H -#include #include "qvalidatedspinbox.h" +#include "walletmodel.h" + +#include namespace Ui { class CommunityFundCreateProposalDialog; @@ -16,14 +18,16 @@ class CommunityFundCreateProposalDialog : public QDialog explicit CommunityFundCreateProposalDialog(QWidget *parent = 0); ~CommunityFundCreateProposalDialog(); + void setModel(WalletModel *model); + private: Ui::CommunityFundCreateProposalDialog *ui; + WalletModel *model; bool validate(); private Q_SLOTS: void click_pushButtonCreateProposal(); void click_spinBox(); - }; #endif // COMMUNITYFUNDCREATEPROPOSALDIALOG_H diff --git a/src/qt/communityfundpage.cpp b/src/qt/communityfundpage.cpp index b35ef8bdf..233da57b9 100644 --- a/src/qt/communityfundpage.cpp +++ b/src/qt/communityfundpage.cpp @@ -374,6 +374,7 @@ void CommunityFundPage::click_radioButtonExpired() void CommunityFundPage::click_pushButtonCreateProposal() { CommunityFundCreateProposalDialog dlg(this); + dlg.setModel(walletModel); dlg.exec(); refresh(ui->radioButtonAll->isChecked(), viewing_proposals); } @@ -381,6 +382,7 @@ void CommunityFundPage::click_pushButtonCreateProposal() void CommunityFundPage::click_pushButtonCreatePaymentRequest() { CommunityFundCreatePaymentRequestDialog dlg(this); + dlg.setModel(walletModel); dlg.exec(); refresh(ui->radioButtonAll->isChecked(), viewing_proposals); } From f00efb3c4d4c3437ccccdb168fb1d43e68a9de66 Mon Sep 17 00:00:00 2001 From: alex v Date: Thu, 9 May 2019 22:56:34 +0200 Subject: [PATCH 6/7] Update copyright year and wallet version in clienversion.h (#475) --- src/clientversion.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/clientversion.h b/src/clientversion.h index c543a0a69..f73b4baa2 100755 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -15,8 +15,8 @@ //! These need to be macros, as clientversion.cpp's and navcoin*-res.rc's voodoo requires it #define CLIENT_VERSION_MAJOR 4 -#define CLIENT_VERSION_MINOR 5 -#define CLIENT_VERSION_REVISION 2 +#define CLIENT_VERSION_MINOR 6 +#define CLIENT_VERSION_REVISION 0 #define CLIENT_VERSION_BUILD 0 //! Set to true for release, false for prerelease or test build @@ -32,7 +32,7 @@ * Copyright year (2009-this) * Todo: update this when changing our copyright comments in the source */ -#define COPYRIGHT_YEAR 2018 +#define COPYRIGHT_YEAR 2019 #endif //HAVE_CONFIG_H From 4a620216be20493225267b6a6ef9c8d21f11a5e7 Mon Sep 17 00:00:00 2001 From: Francis Yap Date: Tue, 14 May 2019 18:15:15 +0800 Subject: [PATCH 7/7] Added new details for getstakinginfo error message as suggested in #288 (#472) * Added new details for getstakinginfo error message as suggested in #288 * Updated the test cases to be more thorough * Updated variable name as per suggesstion --- qa/pull-tester/rpc-tests.py | 1 + qa/rpc-tests/getstakinginfo.py | 78 ++++++++++++++++++++++++++++++++++ src/main.cpp | 36 +++++++++++++--- src/main.h | 1 + src/rpc/net.cpp | 2 +- 5 files changed, 110 insertions(+), 8 deletions(-) create mode 100755 qa/rpc-tests/getstakinginfo.py diff --git a/qa/pull-tester/rpc-tests.py b/qa/pull-tester/rpc-tests.py index df36b8df9..b8f7f54a9 100755 --- a/qa/pull-tester/rpc-tests.py +++ b/qa/pull-tester/rpc-tests.py @@ -169,6 +169,7 @@ 'reject-version-bit.py', 'getcoldstakingaddress.py', 'getstakereport.py', + 'getstakinginfo.py', 'coldstaking_staking.py', 'coldstaking_spending.py', 'staticr-staking-amount.py', diff --git a/qa/rpc-tests/getstakinginfo.py b/qa/rpc-tests/getstakinginfo.py new file mode 100755 index 000000000..cb126dc56 --- /dev/null +++ b/qa/rpc-tests/getstakinginfo.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +# Copyright (c) 2018 The Navcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +from test_framework.test_framework import NavCoinTestFramework +from test_framework.staticr_util import * + +#import time + +class GetStakingInfo(NavCoinTestFramework): + """Tests getstakereport accounting.""" + + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 1 + + def setup_network(self, split=False): + self.nodes = self.setup_nodes() + self.is_network_split = False + + def run_test(self): + # Turn off staking + self.nodes[0].staking(False) + + # Check if we get the error for nWeight + assert(not self.nodes[0].getstakinginfo()['enabled']) + assert(not self.nodes[0].getstakinginfo()['staking']) + assert_equal("Warning: We don't appear to have mature coins.", self.nodes[0].getstakinginfo()['errors']) + + # Make it to the static rewards fork! + activate_staticr(self.nodes[0]) + + # Check balance + assert_equal(59814950, self.nodes[0].getwalletinfo()['balance'] + self.nodes[0].getwalletinfo()['immature_balance']) + + # Turn on staking + self.nodes[0].staking(True) + + # Check for staking after we have matured coins + assert(self.nodes[0].getstakinginfo()['enabled']) + assert(not self.nodes[0].getstakinginfo()['staking']) + assert_equal("", self.nodes[0].getstakinginfo()['errors']) + + # Get the current block count to check against while we wait for a stake + blockcount = self.nodes[0].getblockcount() + + # wait for a new block to be mined + while self.nodes[0].getblockcount() == blockcount: + print("waiting for a new block...") + time.sleep(1) + + # We got one + print("found a new block...") + + # Check balance + assert_equal(59814952, self.nodes[0].getwalletinfo()['balance'] + self.nodes[0].getwalletinfo()['immature_balance']) + + # Check if we get the error for nWeight again after a stake + assert(self.nodes[0].getstakinginfo()['enabled']) + assert(self.nodes[0].getstakinginfo()['staking']) + assert_equal("", self.nodes[0].getstakinginfo()['errors']) + + # LOCK the wallet + self.nodes[0].encryptwallet("password") + stop_nodes(self.nodes) + wait_navcoinds() + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir) + + # Check if we get the error for nWeight again after a stake + assert(self.nodes[0].getstakinginfo()['enabled']) + assert(not self.nodes[0].getstakinginfo()['staking']) + assert_equal("Warning: Wallet is locked. Please enter the wallet passphrase with walletpassphrase first.", self.nodes[0].getstakinginfo()['errors']) + + +if __name__ == '__main__': + GetStakingInfo().main() diff --git a/src/main.cpp b/src/main.cpp index 095c98580..ab61a3752 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -2542,7 +2542,7 @@ bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockI } else if (prevout.scriptPubKey.IsPayToPublicKey() || prevout.scriptPubKey.IsColdStaking()) { uint160 hashBytes; int type = 0; - CTxDestination destination; + CTxDestination destination; ExtractDestination(prevout.scriptPubKey, destination); CNavCoinAddress address(destination); if (prevout.scriptPubKey.IsColdStaking()) @@ -6260,6 +6260,11 @@ void static CheckBlockIndex(const Consensus::Params& consensusParams) } std::string GetWarnings(const std::string& strFor) +{ + return GetWarnings(strFor, false); +} + +std::string GetWarnings(const std::string& strFor, bool fForStaking) { string strStatusBar; string strRPC; @@ -6275,7 +6280,6 @@ std::string GetWarnings(const std::string& strFor) strStatusBar = "This is a Release Candidate build - use at your own risk - please make sure your wallet is backed up"; strGUI = _("This is a Release Candidate build - use at your own risk - please make sure your wallet is backed up"); } - } if (GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE)) @@ -6290,20 +6294,38 @@ std::string GetWarnings(const std::string& strFor) if (fLargeWorkForkFound) { strStatusBar = strRPC = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues."; - strGUI = _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues."); + strGUI = _(strRPC.c_str()); } else if (fLargeWorkInvalidChainFound) { strStatusBar = strRPC = "Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade."; - strGUI = _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade."); + strGUI = _(strRPC.c_str()); + } + + if (fForStaking) + { + if (pwalletMain->IsLocked()) + { + strStatusBar = strRPC = "Warning: Wallet is locked. Please enter the wallet passphrase with walletpassphrase first."; + strGUI = _(strRPC.c_str()); + } + + if (!pwalletMain->GetStakeWeight()) + { + strStatusBar = strRPC = "Warning: We don't appear to have mature coins."; + strGUI = _(strRPC.c_str()); + } } if (strFor == "gui") return strGUI; - else if (strFor == "statusbar") + + if (strFor == "statusbar") return strStatusBar; - else if (strFor == "rpc") + + if (strFor == "rpc") return strRPC; + assert(!"GetWarnings(): invalid parameter"); return "error"; } @@ -7120,7 +7142,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, CTransaction tx; vRecv >> tx; - LogPrint("net", "Received tx %s peer=%d\n%s\n", tx.GetHash().ToString(), pfrom->id, tx.ToString()); + LogPrint("net", "Received tx %s peer=%d\n%s\n", tx.GetHash().ToString(), pfrom->id, tx.ToString()); CInv inv(MSG_TX, tx.GetHash()); pfrom->AddInventoryKnown(inv); diff --git a/src/main.h b/src/main.h index a9ecf0609..a333adeb9 100755 --- a/src/main.h +++ b/src/main.h @@ -289,6 +289,7 @@ bool IsInitialBlockDownload(); * This function only returns the highest priority warning of the set selected by strFor. */ std::string GetWarnings(const std::string& strFor); +std::string GetWarnings(const std::string& strFor, bool fForStaking); /** Retrieve a transaction (from memory pool, or from disk, if possible) */ bool GetTransaction(const uint256 &hash, CTransaction &tx, const Consensus::Params& params, uint256 &hashBlock, bool fAllowSlow = false); /** Find the best known block, and make it the tip of the block chain */ diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 31b8c6d45..250e8aa6f 100755 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -649,7 +649,7 @@ UniValue getstakinginfo(const UniValue& params, bool fHelp) obj.push_back(Pair("enabled", GetStaking())); obj.push_back(Pair("staking", staking)); - obj.push_back(Pair("errors", GetWarnings("statusbar"))); + obj.push_back(Pair("errors", GetWarnings("statusbar", true))); obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize)); obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));