Browse Source

transaction: TxInput.witness_elements() to return [] if not segwit

Previously it would raise:
```
>>> import electrum
>>> tx = electrum.transaction.tx_from_any("0200000001d945b6b076ad7858f7a2227374a42ada71582b1d558fde9ece4bf6c9395c67ca000000006a473044022034867c61623a147dbe7e8541da1086ec8691d4f39181deeba4be70559e26734d02205c0288c96ae6950a0687c0d8c06f9cd343362e6a174cd4c66cfc2abd2278aed801210330fb51ac7b556a599a05c2b8670e79008406e4c0b7e46d4a522ad01804f25dbbfdffffff02389d0700000000001976a9146d687bece6d502519ce5317e25f48da60a52ca8f88ac20a1070000000000220020a948d7fa6abbb97e31779ae54383012b413d53821c7fd394900f6b443c61deeee82a1800")
>>> tx.inputs()[0].witness_elements()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/wspace/electrum/electrum/transaction.py", line 257, in witness_elements
    vds.write(self.witness)
  File "/home/user/wspace/electrum/electrum/transaction.py", line 279, in write
    assert isinstance(_bytes, (bytes, bytearray))
AssertionError
```
patch-4
SomberNight 3 years ago
parent
commit
e00c998df3
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/transaction.py

2
electrum/transaction.py

@ -253,6 +253,8 @@ class TxInput:
return d
def witness_elements(self)-> Sequence[bytes]:
if not self.witness:
return []
vds = BCDataStream()
vds.write(self.witness)
n = vds.read_compact_size()

Loading…
Cancel
Save