2014-10-22 17:05:11 -07:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2014-12-16 17:47:57 -08:00
|
|
|
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
2023-01-23 10:31:54 -08:00
|
|
|
// Copyright (c) 2017-2023 The Zcash developers
|
2014-10-22 17:05:11 -07:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2019-07-18 07:16:09 -07:00
|
|
|
// file COPYING or https://www.opensource.org/licenses/mit-license.php .
|
2014-10-22 17:05:11 -07:00
|
|
|
|
|
|
|
#include "amount.h"
|
2020-12-18 13:19:23 -08:00
|
|
|
#include "policy/fees.h"
|
2014-10-22 17:05:11 -07:00
|
|
|
|
|
|
|
#include "tinyformat.h"
|
|
|
|
|
2017-08-03 10:49:04 -07:00
|
|
|
const std::string CURRENCY_UNIT = "ZEC";
|
2020-04-22 07:21:12 -07:00
|
|
|
const std::string MINOR_CURRENCY_UNIT = "zatoshis";
|
2015-08-01 12:15:23 -07:00
|
|
|
|
2014-10-22 17:05:11 -07:00
|
|
|
CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize)
|
|
|
|
{
|
|
|
|
if (nSize > 0)
|
|
|
|
nSatoshisPerK = nFeePaid*1000/nSize;
|
|
|
|
else
|
|
|
|
nSatoshisPerK = 0;
|
|
|
|
}
|
|
|
|
|
2020-12-18 13:19:23 -08:00
|
|
|
CAmount CFeeRate::GetFeeForRelay(size_t nSize) const
|
|
|
|
{
|
|
|
|
return std::min(GetFee(nSize), DEFAULT_FEE);
|
|
|
|
}
|
|
|
|
|
2014-10-22 17:05:11 -07:00
|
|
|
CAmount CFeeRate::GetFee(size_t nSize) const
|
|
|
|
{
|
|
|
|
CAmount nFee = nSatoshisPerK*nSize / 1000;
|
|
|
|
|
|
|
|
if (nFee == 0 && nSatoshisPerK > 0)
|
|
|
|
nFee = nSatoshisPerK;
|
|
|
|
|
|
|
|
return nFee;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CFeeRate::ToString() const
|
|
|
|
{
|
2015-08-01 12:15:23 -07:00
|
|
|
return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT);
|
2014-10-22 17:05:11 -07:00
|
|
|
}
|