#ifndef BITCOIN_POLICY_FEERATE_H
#define BITCOIN_POLICY_FEERATE_H
#include <consensus/amount.h>
#include <serialize.h>
#include <util/feefrac.h>
#include <util/fees.h>
#include <cstdint>
#include <string>
#include <type_traits>
const std::string CURRENCY_UNIT = "BTC"; const std::string CURRENCY_ATOM = "sat";
enum class FeeRateFormat {
BTC_KVB, SAT_VB, };
class CFeeRate
{
private:
FeePerVSize m_feerate;
public:
CFeeRate() = default;
template<std::integral I> explicit CFeeRate(const I m_feerate_kvb) : m_feerate(FeePerVSize(m_feerate_kvb, 1000)) {}
CFeeRate(const CAmount& nFeePaid, int32_t virtual_bytes);
CAmount GetFee(int32_t virtual_bytes) const;
FeePerVSize GetFeePerVSize() const { return m_feerate; }
CAmount GetFeePerK() const { return CAmount(m_feerate.EvaluateFeeDown(1000)); }
friend std::weak_ordering operator<=>(const CFeeRate& a, const CFeeRate& b) noexcept
{
return FeeRateCompare(a.m_feerate, b.m_feerate);
}
friend bool operator==(const CFeeRate& a, const CFeeRate& b) noexcept
{
return FeeRateCompare(a.m_feerate, b.m_feerate) == std::weak_ordering::equivalent;
}
CFeeRate& operator+=(const CFeeRate& a) {
m_feerate = FeePerVSize(GetFeePerK() + a.GetFeePerK(), 1000);
return *this;
}
std::string ToString(FeeRateFormat fee_rate_format = FeeRateFormat::BTC_KVB) const;
friend CFeeRate operator*(const CFeeRate& f, int a) { return CFeeRate(a * f.m_feerate.fee, f.m_feerate.size); }
friend CFeeRate operator*(int a, const CFeeRate& f) { return CFeeRate(a * f.m_feerate.fee, f.m_feerate.size); }
SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.m_feerate.fee, obj.m_feerate.size); }
};
#endif