We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7aea41b commit 230532dCopy full SHA for 230532d
matt/utils.py
@@ -12,10 +12,10 @@ def vch2bn(s: bytes) -> int:
12
"""Convert bitcoin-specific little endian format to number."""
13
if len(s) == 0:
14
return 0
15
- # The most significant bit is the sign bit.
16
- is_negative = s[0] & 0x80 != 0
+ # The most significant bit is the sign bit. (remembering it's little-endian)
+ is_negative = s[-1] & 0x80 != 0
17
# Mask off the sign bit.
18
- s_abs = bytes([s[0] & 0x7f]) + s[1:]
+ s_abs = s[:-1] + bytes([s[-1] & 0x7f])
19
v_abs = int.from_bytes(s_abs, 'little')
20
# Return as negative number if it's negative.
21
return -v_abs if is_negative else v_abs
0 commit comments