mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
feefrac: Introduce tagged wrappers to distinguish vsize/WU rates
This commit is contained in:
parent
d449773899
commit
6eab3b2d73
1 changed files with 22 additions and 0 deletions
|
@ -156,4 +156,26 @@ struct FeeFrac
|
|||
*/
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue