MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetTransactionWeight

Function GetTransactionWeight

src/consensus/validation.h:147–150  ·  view source on GitHub ↗

These implement the weight = (stripped_size * 4) + witness_size formula, using only serialization with and without witness data. As witness_size is equal to total_size - stripped_size, this formula is identical to: weight = (stripped_size * 3) + total_size.

Source from the content-addressed store, hash-verified

145// is equal to total_size - stripped_size, this formula is identical to:
146// weight = (stripped_size * 3) + total_size.
147static inline int64_t GetTransactionWeight(const CTransaction& tx)
148{
149 return ::GetSerializeSize(tx, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * (WITNESS_SCALE_FACTOR - 1) + ::GetSerializeSize(tx, PROTOCOL_VERSION);
150}
151static inline int64_t GetBlockWeight(const CBlock& block)
152{
153 return ::GetSerializeSize(block, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * (WITNESS_SCALE_FACTOR - 1) + ::GetSerializeSize(block, PROTOCOL_VERSION);

Callers 11

TxToUnivFunction · 0.85
CTxMemPoolEntryMethod · 0.85
AddTxMethod · 0.85
IsStandardTxFunction · 0.85
spend.cppFile · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
FUZZ_TARGET_INITFunction · 0.85
getblocktemplateFunction · 0.85
getblockstatsFunction · 0.85

Calls 1

GetSerializeSizeFunction · 0.85

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.68
FUZZ_TARGET_INITFunction · 0.68