Skip to content

Commit 6eab3b2

Browse files
committed
feefrac: Introduce tagged wrappers to distinguish vsize/WU rates
1 parent d449773 commit 6eab3b2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/util/feefrac.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,26 @@ struct FeeFrac
156156
*/
157157
std::partial_ordering CompareChunks(std::span<const FeeFrac> chunks0, std::span<const FeeFrac> chunks1);
158158

159+
/** Tagged wrapper around FeeFrac to avoid unit confusion. */
160+
template<typename Tag>
161+
struct FeePerUnit : public FeeFrac
162+
{
163+
// Inherit FeeFrac constructors.
164+
using FeeFrac::FeeFrac;
165+
166+
/** Convert a FeeFrac to a FeePerUnit. */
167+
static FeePerUnit FromFeeFrac(const FeeFrac& feefrac) noexcept
168+
{
169+
return {feefrac.fee, feefrac.size};
170+
}
171+
};
172+
173+
// FeePerUnit instance for satoshi / vbyte.
174+
struct VSizeTag {};
175+
using FeePerVSize = FeePerUnit<VSizeTag>;
176+
177+
// FeePerUnit instance for satoshi / WU.
178+
struct WeightTag {};
179+
using FeePerWeight = FeePerUnit<WeightTag>;
180+
159181
#endif // BITCOIN_UTIL_FEEFRAC_H

0 commit comments

Comments
 (0)