File tree Expand file tree Collapse file tree 1 file changed +6
-14
lines changed
test/functional/test_framework Expand file tree Collapse file tree 1 file changed +6
-14
lines changed Original file line number Diff line number Diff line change 99
1010This file is copied from python-bitcoinlib.
1111"""
12- import struct
13-
14- def bn_bytes (v , have_ext = False ):
12+ def bn_bytes (v ):
1513 """Return number of bytes in integer representation of v."""
16- ext = 0
17- if have_ext :
18- ext = 1
19- return (v .bit_length () + 7 ) // 8 + ext
14+ return (v .bit_length () + 7 ) // 8
2015
2116def bn2bin (v ):
2217 """Convert a number to a byte array."""
@@ -28,7 +23,7 @@ def bn2bin(v):
2823 return s
2924
3025def bn2mpi (v ):
31- """Convert number to MPI format."""
26+ """Convert number to MPI format, without the sign byte ."""
3227 have_ext = False
3328 if v .bit_length () > 0 :
3429 have_ext = (v .bit_length () & 0x07 ) == 0
@@ -38,7 +33,6 @@ def bn2mpi(v):
3833 neg = True
3934 v = - v
4035
41- s = struct .pack (b">I" , bn_bytes (v , have_ext ))
4236 ext = bytearray ()
4337 if have_ext :
4438 ext .append (0 )
@@ -48,13 +42,11 @@ def bn2mpi(v):
4842 ext [0 ] |= 0x80
4943 else :
5044 v_bin [0 ] |= 0x80
51- return s + ext + v_bin
45+ return ext + v_bin
5246
5347def mpi2vch (s ):
54- """Convert MPI format to bitcoin-specific little endian format, with implicit size."""
55- r = s [4 :] # strip size
56- r = r [::- 1 ] # reverse string, converting BE->LE
57- return r
48+ """Convert MPI format to bitcoin-specific little endian format."""
49+ return s [::- 1 ] # reverse string, converting BE->LE
5850
5951def bn2vch (v ):
6052 """Convert number to bitcoin-specific little endian format."""
You can’t perform that action at this time.
0 commit comments