Skip to content

Commit

Permalink
Merge #1547: [Refactor] Define constant string variable for currency …
Browse files Browse the repository at this point in the history
…unit

528378d [Refactor] Define constant string variable for currency unit (random-zebra)

Pull request description:

  Closes #1317

ACKs for top commit:
  furszy:
    nice, code looking good. ACK 528378d
  Fuzzbawls:
    utACK 528378d

Tree-SHA512: 3313bd6badce49bd2ff01dfc2201bd93d3e7621391274fcabccd9987464d9b3036d1395afd7472924d8ab25b954948999d8f9382b9a585547a57bcced9c7a68c
  • Loading branch information
random-zebra committed May 21, 2020
2 parents 2c11e37 + 528378d commit 1824def
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 44 deletions.
4 changes: 3 additions & 1 deletion src/amount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "tinyformat.h"

const std::string CURRENCY_UNIT = "PIV";

CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize)
{
if (nSize > 0)
Expand All @@ -28,5 +30,5 @@ CAmount CFeeRate::GetFee(size_t nSize) const

std::string CFeeRate::ToString() const
{
return strprintf("%d.%08d PIV/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN);
return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
}
2 changes: 2 additions & 0 deletions src/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <stdlib.h>
#include <string>

extern const std::string CURRENCY_UNIT;

/** Amount in PIV (Can be negative) */
typedef int64_t CAmount;

Expand Down
12 changes: 6 additions & 6 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-pid=<file>", strprintf(_("Specify pid file (default: %s)"), "pivxd.pid"));
#endif
strUsage += HelpMessageOpt("-reindex", _("Rebuild block chain index from current blk000??.dat files") + " " + _("on startup"));
strUsage += HelpMessageOpt("-reindexmoneysupply", _("Reindex the PIV and zPIV money supply statistics") + " " + _("on startup"));
strUsage += HelpMessageOpt("-reindexmoneysupply", strprintf(_("Reindex the %s and z%s money supply statistics"), CURRENCY_UNIT, CURRENCY_UNIT) + " " + _("on startup"));
strUsage += HelpMessageOpt("-resync", _("Delete blockchain folders and resync from scratch") + " " + _("on startup"));
#if !defined(WIN32)
strUsage += HelpMessageOpt("-sysperms", _("Create new files with system default permissions, instead of umask 077 (only effective with disabled wallet functionality)"));
Expand Down Expand Up @@ -450,9 +450,9 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-disablewallet", _("Do not load the wallet and disable wallet RPC calls"));
strUsage += HelpMessageOpt("-keypool=<n>", strprintf(_("Set key pool size to <n> (default: %u)"), 100));
if (GetBoolArg("-help-debug", false))
strUsage += HelpMessageOpt("-mintxfee=<amt>", strprintf(_("Fees (in PIV/Kb) smaller than this are considered zero fee for transaction creation (default: %s)"),
FormatMoney(CWallet::minTxFee.GetFeePerK())));
strUsage += HelpMessageOpt("-paytxfee=<amt>", strprintf(_("Fee (in PIV/kB) to add to transactions you send (default: %s)"), FormatMoney(payTxFee.GetFeePerK())));
strUsage += HelpMessageOpt("-mintxfee=<amt>", strprintf(_("Fees (in %s/Kb) smaller than this are considered zero fee for transaction creation (default: %s)"),
CURRENCY_UNIT, FormatMoney(CWallet::minTxFee.GetFeePerK())));
strUsage += HelpMessageOpt("-paytxfee=<amt>", strprintf(_("Fee (in %s/kB) to add to transactions you send (default: %s)"), CURRENCY_UNIT, FormatMoney(payTxFee.GetFeePerK())));
strUsage += HelpMessageOpt("-rescan", _("Rescan the block chain for missing wallet transactions") + " " + _("on startup"));
strUsage += HelpMessageOpt("-salvagewallet", _("Attempt to recover private keys from a corrupt wallet.dat") + " " + _("on startup"));
strUsage += HelpMessageOpt("-sendfreetransactions", strprintf(_("Send transactions as zero-fee transactions if possible (default: %u)"), 0));
Expand Down Expand Up @@ -516,7 +516,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-maxsigcachesize=<n>", strprintf(_("Limit size of signature cache to <n> entries (default: %u)"), 50000));
}
strUsage += HelpMessageOpt("-maxtipage=<n>", strprintf("Maximum tip age in seconds to consider node in initial block download (default: %u)", DEFAULT_MAX_TIP_AGE));
strUsage += HelpMessageOpt("-minrelaytxfee=<amt>", strprintf(_("Fees (in PIV/Kb) smaller than this are considered zero fee for relaying (default: %s)"), FormatMoney(::minRelayTxFee.GetFeePerK())));
strUsage += HelpMessageOpt("-minrelaytxfee=<amt>", strprintf(_("Fees (in %s/Kb) smaller than this are considered zero fee for relaying (default: %s)"), CURRENCY_UNIT, FormatMoney(::minRelayTxFee.GetFeePerK())));
strUsage += HelpMessageOpt("-printtoconsole", strprintf(_("Send trace/debug info to console instead of debug.log file (default: %u)"), 0));
if (GetBoolArg("-help-debug", false)) {
strUsage += HelpMessageOpt("-printpriority", strprintf(_("Log transaction priority and fee per kB when mining blocks (default: %u)"), 0));
Expand All @@ -533,7 +533,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageGroup(_("Staking options:"));
strUsage += HelpMessageOpt("-staking=<n>", strprintf(_("Enable staking functionality (0-1, default: %u)"), 1));
strUsage += HelpMessageOpt("-coldstaking=<n>", strprintf(_("Enable cold staking functionality (0-1, default: %u). Disabled if staking=0"), 1));
strUsage += HelpMessageOpt("-pivstake=<n>", strprintf(_("Enable or disable staking functionality for PIV inputs (0-1, default: %u)"), 1));
strUsage += HelpMessageOpt("-pivstake=<n>", strprintf(_("Enable or disable staking functionality for %s inputs (0-1, default: %u)"), CURRENCY_UNIT, 1));
strUsage += HelpMessageOpt("-zpivstake=<n>", strprintf(_("Enable or disable staking functionality for zPIV inputs (0-1, default: %u)"), 1));
strUsage += HelpMessageOpt("-reservebalance=<amt>", _("Keep the specified amount available for spending at all times (default: 0)"));
if (GetBoolArg("-help-debug", false)) {
Expand Down
2 changes: 1 addition & 1 deletion src/qt/askpassphrasedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void AskPassphraseDialog::accept()
bool ret = openStandardDialog(
tr("Confirm wallet encryption"),
"<b>" + tr("WARNING") + ":</b> " + tr("If you encrypt your wallet and lose your passphrase, you will") +
" <b>" + tr("LOSE ALL OF YOUR PIV") + "</b>!<br><br>" + tr("Are you sure you wish to encrypt your wallet?"),
" <b>" + tr("LOSE ALL OF YOUR COINS") + "</b>!<br><br>" + tr("Are you sure you wish to encrypt your wallet?"),
tr("ENCRYPT"), tr("CANCEL")
);
if (ret) {
Expand Down
26 changes: 14 additions & 12 deletions src/qt/bitcoinunits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,28 @@ QString BitcoinUnits::id(int unit)

QString BitcoinUnits::name(int unit, bool isZpiv)
{
const QString CURR_UNIT = QString(CURRENCY_UNIT.c_str());
QString z = "";
if(isZpiv) z = "z";
if (Params().NetworkID() == CBaseChainParams::MAIN) {
switch (unit) {
case PIV:
return z + QString("PIV");
return z + CURR_UNIT;
case mPIV:
return z + QString("mPIV");
return z + QString("m") + CURR_UNIT;
case uPIV:
return z + QString::fromUtf8("μPIV");
return z + QString::fromUtf8("μ") + CURR_UNIT;
default:
return QString("???");
}
} else {
switch (unit) {
case PIV:
return z + QString("tPIV");
return z + QString("t") + CURR_UNIT;
case mPIV:
return z + QString("mtPIV");
return z + QString("mt") + CURR_UNIT;
case uPIV:
return z + QString::fromUtf8("μtPIV");
return z + QString::fromUtf8("μt") + CURR_UNIT;
default:
return QString("???");
}
Expand All @@ -84,25 +85,26 @@ QString BitcoinUnits::name(int unit, bool isZpiv)

QString BitcoinUnits::description(int unit)
{
const QString CURR_UNIT = QString(CURRENCY_UNIT.c_str());
if (Params().NetworkID() == CBaseChainParams::MAIN) {
switch (unit) {
case PIV:
return QString("PIV");
return CURR_UNIT;
case mPIV:
return QString("Milli-PIV (1 / 1" THIN_SP_UTF8 "000)");
return QString("Milli-") + CURR_UNIT + QString(" (1 / 1" THIN_SP_UTF8 "000)");
case uPIV:
return QString("Micro-PIV (1 / 1" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)");
return QString("Micro-") + CURR_UNIT + QString(" (1 / 1" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)");
default:
return QString("???");
}
} else {
switch (unit) {
case PIV:
return QString("TestPIVs");
return QString("Test") + CURR_UNIT;
case mPIV:
return QString("Milli-TestPIV (1 / 1" THIN_SP_UTF8 "000)");
return QString("Milli-Test") + CURR_UNIT + QString(" (1 / 1" THIN_SP_UTF8 "000)");
case uPIV:
return QString("Micro-TestPIV (1 / 1" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)");
return QString("Micro-Test") + CURR_UNIT + QString(" (1 / 1" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)");
default:
return QString("???");
}
Expand Down
6 changes: 3 additions & 3 deletions src/qt/pivx/coldstakingwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ ColdStakingWidget::ColdStakingWidget(PIVXGUI* parent) :
setCssProperty(ui->labelEmpty, "text-empty");

ui->btnCoinControl->setTitleClassAndText("btn-title-grey", tr("Coin Control"));
ui->btnCoinControl->setSubTitleClassAndText("text-subtitle", tr("Select PIV outputs to delegate."));
ui->btnCoinControl->setSubTitleClassAndText("text-subtitle", tr("Select %1 outputs to delegate.").arg(CURRENCY_UNIT.c_str()));

ui->btnColdStaking->setTitleClassAndText("btn-title-grey", tr("Create Cold Staking Address"));
ui->btnColdStaking->setSubTitleClassAndText("text-subtitle", tr("Creates an address to receive delegated coins\nand stake them on their owner's behalf."));
Expand Down Expand Up @@ -543,7 +543,7 @@ void ColdStakingWidget::onCoinControlClicked()
coinControlDialog->exec();
ui->btnCoinControl->setActive(CoinControlDialog::coinControl->HasSelected());
} else {
inform(tr("You don't have any PIV to select."));
inform(tr("You don't have any %1 to select.").arg(CURRENCY_UNIT.c_str()));
}
}
}
Expand Down Expand Up @@ -785,7 +785,7 @@ void ColdStakingWidget::updateStakingTotalLabel()
{
const CAmount& total = csModel->getTotalAmount();
ui->labelStakingTotal->setText(tr("Total Staking: %1").arg(
(total == 0) ? "0.00 PIV" : GUIUtil::formatBalance(total, nDisplayUnit))
(total == 0) ? "0.00 " + QString(CURRENCY_UNIT.c_str()) : GUIUtil::formatBalance(total, nDisplayUnit))
);
}

Expand Down
5 changes: 2 additions & 3 deletions src/qt/pivx/dashboardwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ DashboardWidget::DashboardWidget(PIVXGUI* parent) :
setCssProperty(ui->chartContainer, "container-chart");
setCssProperty(ui->pushImgEmptyChart, "img-empty-staking-on");


setCssBtnSecondary(ui->btnHowTo);

setCssProperty(ui->labelEmptyChart, "text-empty");
Expand Down Expand Up @@ -634,8 +633,8 @@ void DashboardWidget::onChartRefreshed()
axisX->clear();
}
// init sets
set0 = new QBarSet("PIV");
set1 = new QBarSet("zPIV");
set0 = new QBarSet(CURRENCY_UNIT.c_str());
set1 = new QBarSet("z" + QString(CURRENCY_UNIT.c_str()));
set0->setColor(QColor(92,75,125));
set1->setColor(QColor(176,136,255));

Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/masternodeswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ void MasterNodesWidget::onCreateMNClicked()
}

if (walletModel->getBalance() <= (COIN * 10000)) {
inform(tr("Not enough balance to create a masternode, 10,000 PIV required."));
inform(tr("Not enough balance to create a masternode, 10,000 %1 required.").arg(CURRENCY_UNIT.c_str()));
return;
}
showHideOp(true);
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/requestdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void RequestDialog::accept()
PairResult r(false);
if (this->isPaymentRequest) {
r = walletModel->getNewAddress(address, label);
title = tr("Request for ") + BitcoinUnits::format(displayUnit, value, false, BitcoinUnits::separatorAlways) + " PIV";
title = tr("Request for ") + BitcoinUnits::format(displayUnit, value, false, BitcoinUnits::separatorAlways) + " " + QString(CURRENCY_UNIT.c_str());
} else {
r = walletModel->getNewStakingAddress(address, label);
title = tr("Cold Staking Address Generated");
Expand Down
4 changes: 2 additions & 2 deletions src/qt/pivx/send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ SendWidget::SendWidget(PIVXGUI* parent) :
void SendWidget::refreshView()
{
const bool isChecked = ui->pushLeft->isChecked();
ui->pushButtonSave->setText(isChecked ? tr("Send PIV") : tr("Send zPIV"));
ui->pushButtonSave->setText((isChecked ? tr("Send ") : tr("Send z")) + QString(CURRENCY_UNIT.c_str()));
ui->pushButtonAddRecipient->setVisible(isChecked);
refreshAmounts();
}
Expand Down Expand Up @@ -640,7 +640,7 @@ void SendWidget::onCoinControlClicked()
ui->btnCoinControl->setActive(CoinControlDialog::coinControl->HasSelected());
refreshAmounts();
} else {
inform(tr("You don't have any PIV to select."));
inform(tr("You don't have any %1 to select.").arg(CURRENCY_UNIT.c_str()));
}
} else {
if (walletModel->getZerocoinBalance() > 0) {
Expand Down
18 changes: 9 additions & 9 deletions src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,13 @@ QString TransactionTableModel::formatTxType(const TransactionRecord* wtx) const
case TransactionRecord::SendToSelf:
return tr("Payment to yourself");
case TransactionRecord::StakeMint:
return tr("PIV Stake");
return tr("%1 Stake").arg(CURRENCY_UNIT.c_str());
case TransactionRecord::StakeZPIV:
return tr("zPIV Stake");
return tr("z%1 Stake").arg(CURRENCY_UNIT.c_str());
case TransactionRecord::StakeDelegated:
return tr("PIV Cold Stake");
return tr("%1 Cold Stake").arg(CURRENCY_UNIT.c_str());
case TransactionRecord::StakeHot:
return tr("PIV Stake on behalf of");
return tr("%1 Stake on behalf of").arg(CURRENCY_UNIT.c_str());
case TransactionRecord::P2CSDelegationSent:
case TransactionRecord::P2CSDelegationSentOwner:
case TransactionRecord::P2CSDelegation:
Expand All @@ -470,15 +470,15 @@ QString TransactionTableModel::formatTxType(const TransactionRecord* wtx) const
case TransactionRecord::Generated:
return tr("Mined");
case TransactionRecord::ZerocoinMint:
return tr("Converted PIV to zPIV");
return tr("Converted %1 to z%1").arg(CURRENCY_UNIT.c_str());
case TransactionRecord::ZerocoinSpend:
return tr("Spent zPIV");
return tr("Spent z%1").arg(CURRENCY_UNIT.c_str());
case TransactionRecord::RecvFromZerocoinSpend:
return tr("Received PIV from zPIV");
return tr("Received %1 from z%1").arg(CURRENCY_UNIT.c_str());
case TransactionRecord::ZerocoinSpend_Change_zPiv:
return tr("Minted Change as zPIV from zPIV Spend");
return tr("Minted Change as z%1 from z%1 Spend").arg(CURRENCY_UNIT.c_str());
case TransactionRecord::ZerocoinSpend_FromMe:
return tr("Converted zPIV to PIV");
return tr("Converted z%1 to %1").arg(CURRENCY_UNIT.c_str());
default:
return QString();
}
Expand Down
4 changes: 2 additions & 2 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact


if (recipients[0].useSwiftTX && total > sporkManager.GetSporkValue(SPORK_5_MAX_VALUE) * COIN) {
Q_EMIT message(tr("Send Coins"), tr("SwiftX doesn't support sending values that high yet. Transactions are currently limited to %1 PIV.").arg(sporkManager.GetSporkValue(SPORK_5_MAX_VALUE)),
Q_EMIT message(tr("Send Coins"), tr("SwiftX doesn't support sending values that high yet. Transactions are currently limited to %1 %2.").arg(sporkManager.GetSporkValue(SPORK_5_MAX_VALUE)).arg(CURRENCY_UNIT.c_str()),
CClientUIInterface::MSG_ERROR);
return TransactionCreationFailed;
}
Expand All @@ -517,7 +517,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
transaction.setTransactionFee(nFeeRequired);

if (recipients[0].useSwiftTX && newTx->GetValueOut() > sporkManager.GetSporkValue(SPORK_5_MAX_VALUE) * COIN) {
Q_EMIT message(tr("Send Coins"), tr("SwiftX doesn't support sending values that high yet. Transactions are currently limited to %1 PIV.").arg(sporkManager.GetSporkValue(SPORK_5_MAX_VALUE)),
Q_EMIT message(tr("Send Coins"), tr("SwiftX doesn't support sending values that high yet. Transactions are currently limited to %1 %2.").arg(sporkManager.GetSporkValue(SPORK_5_MAX_VALUE)).arg(CURRENCY_UNIT.c_str()),
CClientUIInterface::MSG_ERROR);
return TransactionCreationFailed;
}
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ void checkBudgetInputs(const UniValue& params, std::string &strProposalName, std

nAmount = AmountFromValue(params[5]);
if (nAmount < 10 * COIN)
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid amount - Payment of %d is less than minimum 10 PIV allowed", FormatMoney(nAmount)));
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid amount - Payment of %s is less than minimum 10 %s allowed", FormatMoney(nAmount), CURRENCY_UNIT));

if (nAmount > budget.GetTotalBudget(nBlockStart))
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid amount - Payment of %d more than max of %d", FormatMoney(nAmount), FormatMoney(budget.GetTotalBudget(nBlockStart))));
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid amount - Payment of %s more than max of %s", FormatMoney(nAmount), FormatMoney(budget.GetTotalBudget(nBlockStart))));
}

UniValue preparebudget(const UniValue& params, bool fHelp)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setup_network(self):
# Don't start the node

def run_test(self):
self.log.info("Start pivx with -h for help text")
self.log.info("Start pivx with -? for help text")
self.nodes[0].start(extra_args=['-?'], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
# Node should exit immediately and output help to stdout.
ret_code = self.nodes[0].process.wait(timeout=1)
Expand Down

0 comments on commit 1824def

Please sign in to comment.