From 12ec29d3bb0d46c61712210fe9bb96a0d543204a Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 5 Mar 2018 16:37:24 -0500 Subject: Calculate and store the number of bytes required to spend an input --- src/consensus/validation.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/consensus/validation.h') diff --git a/src/consensus/validation.h b/src/consensus/validation.h index c2a343c155..757df518ae 100644 --- a/src/consensus/validation.h +++ b/src/consensus/validation.h @@ -101,5 +101,10 @@ static inline int64_t GetBlockWeight(const CBlock& block) { return ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * (WITNESS_SCALE_FACTOR - 1) + ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION); } +static inline int64_t GetTransationInputWeight(const CTxIn& txin) +{ + // scriptWitness size is added here because witnesses and txins are split up in segwit serialization. + return ::GetSerializeSize(txin, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * (WITNESS_SCALE_FACTOR - 1) + ::GetSerializeSize(txin, SER_NETWORK, PROTOCOL_VERSION) + ::GetSerializeSize(txin.scriptWitness.stack, SER_NETWORK, PROTOCOL_VERSION); +} #endif // BITCOIN_CONSENSUS_VALIDATION_H -- cgit v1.2.3