Skip to content

Commit 1553c80

Browse files
committed
Add multiplication operator to CFeeRate
1 parent 2e8ec6b commit 1553c80

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/policy/feerate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class CFeeRate
7171
friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; }
7272
CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
7373
std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KVB) const;
74+
friend CFeeRate operator*(const CFeeRate& f, int a) { return CFeeRate(a * f.nSatoshisPerK); }
75+
friend CFeeRate operator*(int a, const CFeeRate& f) { return CFeeRate(a * f.nSatoshisPerK); }
7476

7577
SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); }
7678
};

src/test/amount_tests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ BOOST_AUTO_TEST_CASE(GetFeeTest)
8585
BOOST_CHECK(CFeeRate(CAmount(27), 789) == CFeeRate(34));
8686
// Maximum size in bytes, should not crash
8787
CFeeRate(MAX_MONEY, std::numeric_limits<uint32_t>::max()).GetFeePerK();
88+
89+
// check multiplication operator
90+
feeRate = CFeeRate(1000);
91+
BOOST_CHECK(0 * feeRate == CFeeRate(0));
92+
BOOST_CHECK(3 * feeRate == CFeeRate(3000));
93+
BOOST_CHECK(-3 * feeRate == CFeeRate(-3000));
8894
}
8995

9096
BOOST_AUTO_TEST_CASE(BinaryOperatorTest)

0 commit comments

Comments
 (0)