Skip to content

Commit

Permalink
Add virtual size to TX
Browse files Browse the repository at this point in the history
The virtual size of a TX can be useful info to have, as it's what is used to calculate the fee when fee/byte is used. Allow users to get the virtual size.
  • Loading branch information
droark committed Dec 24, 2018
1 parent 8c0e848 commit fec1f39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cppForSwig/TxClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,13 @@ size_t Tx::getTxWeight() const
return size;
}

/////////////////////////////////////////////////////////////////////////////
// Get the virtual size of the TX. Used in Bitcoin to determine minimum fees.
size_t Tx::getVirtSize(void) const
{
return std::ceil(static_cast<float>(getTxWeight()) / 4.0f);
}

/////////////////////////////////////////////////////////////////////////////
void Tx::pprint(ostream & os, int nIndent, bool pBigendian)
{
Expand Down
1 change: 1 addition & 0 deletions cppForSwig/TxClasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ class Tx

//returns tx weight in bytes
size_t getTxWeight(void) const;
size_t getVirtSize(void) const;

private:
// Full copy of the serialized tx
Expand Down

0 comments on commit fec1f39

Please sign in to comment.