Skip to content

Commit

Permalink
Fix GetDecimalString typo (#1812)
Browse files Browse the repository at this point in the history
  • Loading branch information
prasannavl authored Mar 9, 2023
1 parent c8f5616 commit 3be2c92
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static constexpr CAmount COIN = 100000000;
static constexpr CAmount CENT = 1000000;

//Converts the given value to decimal format string with COIN precision.
inline std::string GetDecimaleString(CAmount nValue)
inline std::string GetDecimalString(CAmount nValue)
{
const bool sign = nValue < 0;
const int64_t n_abs = (sign ? -nValue : nValue);
Expand Down Expand Up @@ -124,13 +124,13 @@ struct CTokenAmount { // simple std::pair is less informative
CAmount nValue;

std::string ToString() const {
return strprintf("%s@%d", GetDecimaleString(nValue), nTokenId.v);
return strprintf("%s@%d", GetDecimalString(nValue), nTokenId.v);
}

Res Add(CAmount amount) {
// safety checks
if (amount < 0) {
return Res::Err("negative amount: %s", GetDecimaleString(amount));
return Res::Err("negative amount: %s", GetDecimalString(amount));
}

// add
Expand All @@ -144,10 +144,10 @@ struct CTokenAmount { // simple std::pair is less informative
Res Sub(CAmount amount) {
// safety checks
if (amount < 0) {
return Res::Err("negative amount: %s", GetDecimaleString(amount));
return Res::Err("negative amount: %s", GetDecimalString(amount));
}
if (this->nValue < amount) {
return Res::Err("amount %s is less than %s", GetDecimaleString(this->nValue), GetDecimaleString(amount));
return Res::Err("amount %s is less than %s", GetDecimalString(this->nValue), GetDecimalString(amount));
}

// sub
Expand Down
4 changes: 2 additions & 2 deletions src/masternodes/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DeFiErrors {

static Res ICXBTCBelowMinSwap(const CAmount amount, const CAmount minSwap) {
// TODO: Change error in later version to include amount. Retaining old msg for compatibility
return Res::Err("Below minimum swapable amount, must be at least %s BTC", GetDecimaleString(minSwap));
return Res::Err("Below minimum swapable amount, must be at least %s BTC", GetDecimalString(minSwap));
}

static Res MNInvalidAttribute() {
Expand Down Expand Up @@ -126,7 +126,7 @@ class DeFiErrors {
}

static Res AmountOverflowAsValuePrice(const CAmount amount, const CAmount price) {
return Res::Err("Value/price too high (%s/%s)", GetDecimaleString(amount), GetDecimaleString(price));
return Res::Err("Value/price too high (%s/%s)", GetDecimalString(amount), GetDecimalString(price));
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/masternodes/govvariables/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ UniValue ATTRIBUTES::ExportFiltered(GovVarsFilter filter, const std::string &pre
(attrV0->key == DFIPKeys::BlockPeriod || attrV0->key == DFIPKeys::StartBlock)) {
ret.pushKV(key, KeyBuilder(*amount));
} else {
auto decimalStr = GetDecimaleString(*amount);
auto decimalStr = GetDecimalString(*amount);
rtrim(decimalStr, '0');
if (decimalStr.back() == '.') {
decimalStr.pop_back();
Expand Down Expand Up @@ -1568,7 +1568,7 @@ Res ATTRIBUTES::Apply(CCustomCSView &mnview, const uint32_t height) {
Require(factor, []{ return "Unexpected type"; });
Require(*factor < *ratio.begin() * CENT, [=]{ return strprintf(
"Factor cannot be more than or equal to the lowest scheme rate of %d\n",
GetDecimaleString(*ratio.begin() * CENT)); });
GetDecimalString(*ratio.begin() * CENT)); });
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/loan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Res CLoanView::CreateLoanCollateralToken(const CLoanSetCollateralTokenImpl &coll
collToken.creationTx.GetHex()); });
Require(
collToken.factor <= COIN, [=]{ return strprintf("setCollateralToken factor must be lower or equal than %s!",
GetDecimaleString(COIN)); });
GetDecimalString(COIN)); });
Require(collToken.factor >= 0, []{ return "setCollateralToken factor must not be negative!"; });

WriteBy<LoanSetCollateralTokenCreationTx>(collToken.creationTx, collToken);
Expand Down
6 changes: 3 additions & 3 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2816,7 +2816,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {
auto vaultCreationFee = consensus.vaultCreationFee;
Require(tx.vout[0].nValue == vaultCreationFee && tx.vout[0].nTokenId == DCT_ID{0},
"Malformed tx vouts, creation vault fee is %s DFI",
GetDecimaleString(vaultCreationFee));
GetDecimalString(vaultCreationFee));

CVaultData vault{};
static_cast<CVaultMessage &>(vault) = obj;
Expand Down Expand Up @@ -3283,8 +3283,8 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {
if (price > COIN) {
Require(amount >= tokenAmount,
"Value/price too high (%s/%s)",
GetDecimaleString(tokenAmount),
GetDecimaleString(price));
GetDecimalString(tokenAmount),
GetDecimalString(price));
}
auto &totalLoans = i > 0 ? totalLoansNextPrice : totalLoansActivePrice;
auto prevLoans = totalLoans;
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/rpc_customtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class CCustomTxRpcVisitor {

UniValue uniPair(UniValue::VOBJ);
uniPair.pushKV("currency", currency);
uniPair.pushKV("tokenAmount", strprintf("%s@%s", GetDecimaleString(amount), token));
uniPair.pushKV("tokenAmount", strprintf("%s@%s", GetDecimalString(amount), token));
tokenPrices.push_back(uniPair);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/masternodes/rpc_vault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,7 @@ UniValue estimateloan(const JSONRPCRequest& request) {
totalSplit += split;
}
if (totalSplit != COIN)
throw JSONRPCError(RPC_MISC_ERROR, strprintf("total split between loan tokens = %s vs expected %s", GetDecimaleString(totalSplit), GetDecimaleString(COIN)));
throw JSONRPCError(RPC_MISC_ERROR, strprintf("total split between loan tokens = %s vs expected %s", GetDecimalString(totalSplit), GetDecimalString(COIN)));
}
auto res = AmountsToJSON(loanBalances.balances);
return GetRPCResultCache().Set(request, res);
Expand Down Expand Up @@ -1795,7 +1795,7 @@ UniValue estimatecollateral(const JSONRPCRequest& request) {
totalSplit += split;
}
if (totalSplit != COIN) {
throw JSONRPCError(RPC_MISC_ERROR, strprintf("total split between collateral tokens = %s vs expected %s", GetDecimaleString(totalSplit), GetDecimaleString(COIN)));
throw JSONRPCError(RPC_MISC_ERROR, strprintf("total split between collateral tokens = %s vs expected %s", GetDecimalString(totalSplit), GetDecimalString(COIN)));
}

auto res = AmountsToJSON(collateralBalances.balances);
Expand Down
4 changes: 2 additions & 2 deletions src/test/amount_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ BOOST_AUTO_TEST_CASE(ToStringTest)
BOOST_CHECK_EQUAL(feeRate.ToString(), "0.00000001 DFI/kB");
}

//Tests whether the function GetDecimaleString() returns the correct string value
//Tests whether the function GetDecimalString() returns the correct string value
BOOST_AUTO_TEST_CASE(GetDecimaleString_Test)
{
CAmount val = 1200;
BOOST_CHECK_EQUAL(GetDecimaleString(val), "0.00001200");
BOOST_CHECK_EQUAL(GetDecimalString(val), "0.00001200");
}


Expand Down

0 comments on commit 3be2c92

Please sign in to comment.