Skip to content

Commit 230532d

Browse files
committed
Fix vch2bn helper function
1 parent 7aea41b commit 230532d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

matt/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ def vch2bn(s: bytes) -> int:
1212
"""Convert bitcoin-specific little endian format to number."""
1313
if len(s) == 0:
1414
return 0
15-
# The most significant bit is the sign bit.
16-
is_negative = s[0] & 0x80 != 0
15+
# The most significant bit is the sign bit. (remembering it's little-endian)
16+
is_negative = s[-1] & 0x80 != 0
1717
# Mask off the sign bit.
18-
s_abs = bytes([s[0] & 0x7f]) + s[1:]
18+
s_abs = s[:-1] + bytes([s[-1] & 0x7f])
1919
v_abs = int.from_bytes(s_abs, 'little')
2020
# Return as negative number if it's negative.
2121
return -v_abs if is_negative else v_abs

0 commit comments

Comments
 (0)