diff --git a/src/util/feefrac.h b/src/util/feefrac.h index 6097d1ec638..2a1754ac514 100644 --- a/src/util/feefrac.h +++ b/src/util/feefrac.h @@ -156,4 +156,26 @@ struct FeeFrac */ std::partial_ordering CompareChunks(std::span chunks0, std::span chunks1); +/** Tagged wrapper around FeeFrac to avoid unit confusion. */ +template +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; + +// FeePerUnit instance for satoshi / WU. +struct WeightTag {}; +using FeePerWeight = FeePerUnit; + #endif // BITCOIN_UTIL_FEEFRAC_H