Calculate the transaction weight, as defined by BIP141. The transaction must contain at least one input and one output.
(self)
| 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 |
| 468 | class CMutableTransaction(CTransaction): |