aboutsummaryrefslogtreecommitdiff
path: root/src/core.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2014-04-10 14:14:18 -0400
committerGavin Andresen <gavinandresen@gmail.com>2014-06-06 10:34:18 -0400
commitc6cb21d17ab8097b6a425d37e48c955fbb0e9f0c (patch)
tree297b740beca0274be8a85d8c355acecafecbbc3e /src/core.cpp
parent345cb52e8ba878ca3e2590d5792b733ec11a1f0d (diff)
Type-safe CFeeRate class
Use CFeeRate instead of an int64_t for quantities that are fee-per-size. Helps prevent unit-conversion mismatches between the wallet, relaying, and mining code.
Diffstat (limited to 'src/core.cpp')
-rw-r--r--src/core.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/core.cpp b/src/core.cpp
index aadcb44b98..6039986e6c 100644
--- a/src/core.cpp
+++ b/src/core.cpp
@@ -72,6 +72,25 @@ void CTxOut::print() const
LogPrintf("%s\n", ToString());
}
+CFeeRate::CFeeRate(int64_t nFeePaid, size_t nSize)
+{
+ if (nSize > 0)
+ nSatoshisPerK = nFeePaid*1000/nSize;
+ else
+ nSatoshisPerK = 0;
+}
+
+int64_t CFeeRate::GetFee(size_t nSize)
+{
+ return nSatoshisPerK*nSize / 1000;
+}
+
+std::string CFeeRate::ToString() const
+{
+ std::string result = FormatMoney(nSatoshisPerK) + " BTC/kB";
+ return result;
+}
+
uint256 CTransaction::GetHash() const
{
return SerializeHash(*this);