feefrac: Introduce tagged wrappers to distinguish vsize/WU rates

This commit is contained in:
Pieter Wuille 2025-01-30 17:14:52 -05:00
parent d449773899
commit 6eab3b2d73

View file

@ -156,4 +156,26 @@ struct FeeFrac
*/ */
std::partial_ordering CompareChunks(std::span<const FeeFrac> chunks0, std::span<const FeeFrac> chunks1); std::partial_ordering CompareChunks(std::span<const FeeFrac> chunks0, std::span<const FeeFrac> chunks1);
/** Tagged wrapper around FeeFrac to avoid unit confusion. */
template<typename Tag>
struct FeePerUnit : public FeeFrac
{
// Inherit FeeFrac constructors.
using FeeFrac::FeeFrac;
/** Convert a FeeFrac to a FeePerUnit. */
static FeePerUnit FromFeeFrac(const FeeFrac& feefrac) noexcept
{
return {feefrac.fee, feefrac.size};
}
};
// FeePerUnit instance for satoshi / vbyte.
struct VSizeTag {};
using FeePerVSize = FeePerUnit<VSizeTag>;
// FeePerUnit instance for satoshi / WU.
struct WeightTag {};
using FeePerWeight = FeePerUnit<WeightTag>;
#endif // BITCOIN_UTIL_FEEFRAC_H #endif // BITCOIN_UTIL_FEEFRAC_H