92@@ -93,8 +93,10 @@ class CValidationState {
93 // using only serialization with and without witness data. As witness_size
94 // is equal to total_size - stripped_size, this formula is identical to:
95 // weight = (stripped_size * 3) + total_size.
96-static inline int64_t GetTransactionWeight(const CTransaction& tx)
97+template <typename T>
98+static inline int64_t GetTransactionWeight(const T& tx)
99 {
100+ static_assert(std::is_same<T, CTransaction>::value || std::is_same<T, CMutableTransaction>::value, "no need to allow other types");
it might be nicer to have this function not participate in overload resolution (i.e. enable_if
) when these conditions are not met, rather than being triggering a static assert.
Downside of using enable_if is that the resulting compiler error message will probably be more ambiguous and harder to understand.
Either way, I think there should be a standard logic for checking whether a type is a transaction type – provided by transaction.h
, thus preserving encapsulation.