mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-08-04 14:04:49 +02:00
policy: add CFeeRate::SatsToString helper without units
This commit is contained in:
parent
55bd5d8015
commit
09c51e7f7d
@ -43,3 +43,7 @@ std::string CFeeRate::ToString(const FeeEstimateMode& fee_estimate_mode) const
|
|||||||
default: return strprintf("%d.%08d %s/kvB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
|
default: return strprintf("%d.%08d %s/kvB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CFeeRate::SatsToString() const {
|
||||||
|
return strprintf("%d.%03d", nSatoshisPerK / 1000, nSatoshisPerK % 1000);
|
||||||
|
}
|
||||||
|
@ -70,7 +70,10 @@ public:
|
|||||||
friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
|
friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
|
||||||
friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; }
|
friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; }
|
||||||
CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
|
CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
|
||||||
|
/** Return the fee rate in sat/vB or BTC/kvB, with units, as a string. */
|
||||||
std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KVB) const;
|
std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KVB) const;
|
||||||
|
/** Return the fee rate in sat/vB, without units, as a string. */
|
||||||
|
std::string SatsToString() const;
|
||||||
friend CFeeRate operator*(const CFeeRate& f, int a) { return CFeeRate(a * f.nSatoshisPerK); }
|
friend CFeeRate operator*(const CFeeRate& f, int a) { return CFeeRate(a * f.nSatoshisPerK); }
|
||||||
friend CFeeRate operator*(int a, const CFeeRate& f) { return CFeeRate(a * f.nSatoshisPerK); }
|
friend CFeeRate operator*(int a, const CFeeRate& f) { return CFeeRate(a * f.nSatoshisPerK); }
|
||||||
|
|
||||||
|
@ -139,4 +139,12 @@ BOOST_AUTO_TEST_CASE(ToStringTest)
|
|||||||
BOOST_CHECK_EQUAL(feeRate.ToString(FeeEstimateMode::SAT_VB), "0.001 sat/vB");
|
BOOST_CHECK_EQUAL(feeRate.ToString(FeeEstimateMode::SAT_VB), "0.001 sat/vB");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(SatsToStringTest)
|
||||||
|
{
|
||||||
|
BOOST_CHECK_EQUAL(CFeeRate(1).SatsToString(), "0.001");
|
||||||
|
BOOST_CHECK_EQUAL(CFeeRate(70).SatsToString(), "0.070");
|
||||||
|
BOOST_CHECK_EQUAL(CFeeRate(3141).SatsToString(), "3.141");
|
||||||
|
BOOST_CHECK_EQUAL(CFeeRate(10002).SatsToString(), "10.002");
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
Loading…
Reference in New Issue
Block a user