MCPcopy
hub / github.com/petertodd/python-bitcoinlib / calc_weight

Method calc_weight

bitcoin/core/__init__.py:449–465  ·  view source on GitHub ↗

Calculate the transaction weight, as defined by BIP141. The transaction must contain at least one input and one output.

(self)

Source from the content-addressed store, hash-verified

447 return txid
448
449 def calc_weight(self):
450 """Calculate the transaction weight, as defined by BIP141.
451
452 The transaction must contain at least one input and one output.
453 """
454 # Not clear how calc_weight() should be defined for the zero vin/vout
455 # cases, so punting on that decision for now.
456 assert len(self.vin) > 0
457 assert len(self.vout) > 0
458
459 # This special case isn't strictly necessary. But saves on serializing
460 # the transaction twice in the no-witness case.
461 if self.wit.is_null():
462 return len(self.serialize()) * 4
463 else:
464 stripped = CTransaction(self.vin, self.vout, self.nLockTime, self.nVersion)
465 return len(stripped.serialize()) * 3 + len(self.serialize())
466
467@__make_mutable
468class CMutableTransaction(CTransaction):

Callers 1

test_calc_weightMethod · 0.80

Calls 3

CTransactionClass · 0.85
is_nullMethod · 0.45
serializeMethod · 0.45

Tested by 1

test_calc_weightMethod · 0.64