diff --git a/src/masternodes/loan.cpp b/src/masternodes/loan.cpp index 75f6bf3b25..a4f2b9e7f2 100644 --- a/src/masternodes/loan.cpp +++ b/src/masternodes/loan.cpp @@ -1,6 +1,7 @@ #include #include +#include std::unique_ptr CLoanView::GetLoanCollateralToken(uint256 const & txid) const { @@ -478,3 +479,41 @@ CAmount CLoanView::GetLoanLiquidationPenalty() return 5 * COIN / 100; } + +std::string GetInterestPerBlockHighPrecisionString(base_uint<128> value) { + struct HighPrecisionInterestValue { + typedef boost::multiprecision::int128_t int128; + typedef int64_t int64; + + int128 value; + + HighPrecisionInterestValue(base_uint<128> val) { + value = int128("0x" + val.GetHex()); + } + + int64 GetInterestPerBlockSat() { + return int64(value / HIGH_PRECISION_SCALER); + } + + int64 GetInterestPerBlockSubSat() { + return int64(value % HIGH_PRECISION_SCALER); + } + + int64 GetInterestPerBlockMagnitude() { + return int64(value / HIGH_PRECISION_SCALER / COIN); + } + + int128 GetInterestPerBlockDecimal() { + auto v = GetInterestPerBlockSat(); + return v == 0 ? value : value % (int128(HIGH_PRECISION_SCALER) * COIN); + } + + std::string GetInterestPerBlockString() { + std::ostringstream result; + result << GetInterestPerBlockMagnitude() << "."; + result << std::setw(24) << std::setfill('0') << GetInterestPerBlockDecimal(); + return result.str(); + } + }; + return HighPrecisionInterestValue(value).GetInterestPerBlockString(); +} diff --git a/src/masternodes/loan.h b/src/masternodes/loan.h index 33cb7cfdb8..541990d20b 100644 --- a/src/masternodes/loan.h +++ b/src/masternodes/loan.h @@ -11,6 +11,7 @@ #include #include