test: introduce get_weight() helper for CTransaction

This commit is contained in:
Sebastian Falbesoner
2021-06-30 23:40:39 +02:00
parent 3fc20abab0
commit a084ebe133
3 changed files with 14 additions and 13 deletions

View File

@ -590,12 +590,15 @@ class CTransaction:
return False
return True
# Calculate the virtual transaction size using witness and non-witness
# Calculate the transaction weight using witness and non-witness
# serialization size (does NOT use sigops).
def get_vsize(self):
def get_weight(self):
with_witness_size = len(self.serialize_with_witness())
without_witness_size = len(self.serialize_without_witness())
return math.ceil(((WITNESS_SCALE_FACTOR - 1) * without_witness_size + with_witness_size) / WITNESS_SCALE_FACTOR)
return (WITNESS_SCALE_FACTOR - 1) * without_witness_size + with_witness_size
def get_vsize(self):
return math.ceil(self.get_weight() / WITNESS_SCALE_FACTOR)
def __repr__(self):
return "CTransaction(nVersion=%i vin=%s vout=%s wit=%s nLockTime=%i)" \