Skip to content

Commit 1a089d6

Browse files
committed
Merge #159: Fix struct.unpack receiving an integer instead of a byte
81ca8a3 Fix struct.unpack receiving an integer instead of a byte. stackoverflow.com/q/29299136/ (David) Pull request description: Fix struct.unpack receiving an integer instead of a byte. Before I was receiving this error ``` File "/python-bitcoinlib/venv/lib/python3.6/site-packages/python_bitcoinlib-0.9.0-py3.6.egg/bitcoin/core/script.py", line 684, in is_witness_scriptpubkey return 3 <= len(self) <= 42 and CScriptOp(struct.unpack('<b',self[0])[0]).is_small_int() TypeError: a bytes-like object is required, not 'int' ``` Solved by getting the byte with self[0:1]. A bytearray of length 1 that is accepted by unpack. Check https://stackoverflow.com/q/29299136/ Tree-SHA512: 968d4b864baa820bb80f12b24031dbb9166aa3f46f612bb0f393eb5d445a869271591d100cebad528e3263079158e7a6bd7d565803b86e568b01223b55aa6f4a
2 parents 8c25c1d + 81ca8a3 commit 1a089d6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

bitcoin/core/script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ def is_p2sh(self):
680680
def is_witness_scriptpubkey(self):
681681
"""Returns true if this is a scriptpubkey signaling segregated witness
682682
data. """
683-
return 3 <= len(self) <= 42 and CScriptOp(struct.unpack('<b',self[0])[0]).is_small_int()
683+
return 3 <= len(self) <= 42 and CScriptOp(struct.unpack('<b',self[0:1])[0]).is_small_int()
684684

685685
def witness_version(self):
686686
"""Returns the witness version on [0,16]. """

0 commit comments

Comments
 (0)