Skip to content

Commit fdf82fb

Browse files
committed
Adding method GetTotalSize() to CTransaction
GetTotalSize() returns the total transaction size (including witness) in bytes.
1 parent cbe9ae8 commit fdf82fb

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/primitives/transaction.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ unsigned int CTransaction::CalculateModifiedSize(unsigned int nTxSize) const
131131
return nTxSize;
132132
}
133133

134+
unsigned int CTransaction::GetTotalSize() const
135+
{
136+
return ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION);
137+
}
138+
134139
std::string CTransaction::ToString() const
135140
{
136141
std::string str;

src/primitives/transaction.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,13 @@ class CTransaction
415415

416416
// Compute modified tx size for priority calculation (optionally given tx size)
417417
unsigned int CalculateModifiedSize(unsigned int nTxSize=0) const;
418+
419+
/**
420+
* Get the total transaction size in bytes, including witness data.
421+
* "Total Size" defined in BIP141 and BIP144.
422+
* @return Total transaction size in bytes
423+
*/
424+
unsigned int GetTotalSize() const;
418425

419426
bool IsCoinBase() const
420427
{

0 commit comments

Comments
 (0)