Skip to content

Commit 1dc68ae

Browse files
committed
[tests] add function comments to bignum
1 parent f31fc0e commit 1dc68ae

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

test/functional/test_framework/bignum.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
import struct
1313

1414
def bn_bytes(v, have_ext=False):
15+
"""Return number of bytes in integer representation of v."""
1516
ext = 0
1617
if have_ext:
1718
ext = 1
1819
return (v.bit_length() + 7) // 8 + ext
1920

2021
def bn2bin(v):
22+
"""Convert a number to a byte array."""
2123
s = bytearray()
2224
i = bn_bytes(v)
2325
while i > 0:
@@ -26,6 +28,7 @@ def bn2bin(v):
2628
return s
2729

2830
def bn2mpi(v):
31+
"""Convert number to MPI format."""
2932
have_ext = False
3033
if v.bit_length() > 0:
3134
have_ext = (v.bit_length() & 0x07) == 0
@@ -47,11 +50,12 @@ def bn2mpi(v):
4750
v_bin[0] |= 0x80
4851
return s + ext + v_bin
4952

50-
# bitcoin-specific little endian format, with implicit size
5153
def mpi2vch(s):
54+
"""Convert MPI format to bitcoin-specific little endian format, with implicit size."""
5255
r = s[4:] # strip size
5356
r = r[::-1] # reverse string, converting BE->LE
5457
return r
5558

5659
def bn2vch(v):
60+
"""Convert number to bitcoin-specific little endian format."""
5761
return bytes(mpi2vch(bn2mpi(v)))

0 commit comments

Comments
 (0)