From 6eab3b2d7380b8ff818e3a1cefeb7731b7342e04 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Thu, 30 Jan 2025 17:14:52 -0500 Subject: [PATCH] feefrac: Introduce tagged wrappers to distinguish vsize/WU rates --- src/util/feefrac.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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