Skip to content

Commit 5c0b0eb

Browse files
authored
Merge pull request #1787 from evoskuil/master
Add virtual size and weight constexpr utils.
2 parents 46fe81c + 0ca869a commit 5c0b0eb

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

include/bitcoin/system/chain/enums/magic_numbers.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define LIBBITCOIN_SYSTEM_CHAIN_ENUMS_MAGIC_NUMBERS_HPP
2121

2222
#include <bitcoin/system/define.hpp>
23+
#include <bitcoin/system/math/math.hpp>
2324

2425
namespace libbitcoin {
2526
namespace system {
@@ -98,6 +99,23 @@ constexpr uint8_t tapscript_version = 0b1100'0000; // 0xc0
9899

99100
constexpr size_t max_null_data_size = 80;
100101

102+
/// Utilities.
103+
/// ---------------------------------------------------------------------------
104+
105+
constexpr size_t weighted_size(size_t nominal, size_t witnessed) NOEXCEPT
106+
{
107+
return ceilinged_add(
108+
ceilinged_multiply(base_size_contribution, nominal),
109+
ceilinged_multiply(total_size_contribution, witnessed));
110+
}
111+
112+
constexpr size_t virtual_size(size_t nominal, size_t witnessed) NOEXCEPT
113+
{
114+
// Block weight is 3 * nominal size * + 1 * witness size [bip141].
115+
constexpr auto scale = base_size_contribution + total_size_contribution;
116+
return ceilinged_divide(weighted_size(nominal, witnessed), scale);
117+
}
118+
101119
} // namespace chain
102120
} // namespace system
103121
} // namespace libbitcoin

0 commit comments

Comments
 (0)