Skip to content

Commit 3ed772d

Browse files
committed
[tests] remove bignum.py
It only contains one function and is only imported by one other module (script.py). Just move the function to script.py.
1 parent f950ec2 commit 3ed772d

File tree

3 files changed

+34
-48
lines changed

3 files changed

+34
-48
lines changed

test/functional/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ Utilities for manipulating transaction scripts (originally from python-bitcoinli
121121
#### [key.py](test_framework/key.py)
122122
Test-only secp256k1 elliptic curve implementation
123123

124-
#### [bignum.py](test_framework/bignum.py)
125-
Helpers for script.py
126-
127124
#### [blocktools.py](test_framework/blocktools.py)
128125
Helper functions for creating blocks and transactions.
129126

test/functional/test_framework/bignum.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

test/functional/test_framework/script.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import hashlib
1010
import struct
1111

12-
from .bignum import bn2vch
1312
from .messages import (
1413
CTransaction,
1514
CTxOut,
@@ -26,6 +25,40 @@
2625
def hash160(s):
2726
return hashlib.new('ripemd160', sha256(s)).digest()
2827

28+
def bn2vch(v):
29+
"""Convert number to bitcoin-specific little endian format."""
30+
# The top bit is used to indicate the sign of the number. If there
31+
# isn't a spare bit in the bit length, add an extension byte.
32+
have_ext = False
33+
ext = bytearray()
34+
if v.bit_length() > 0:
35+
have_ext = (v.bit_length() & 0x07) == 0
36+
ext.append(0)
37+
38+
# Is the number negative?
39+
neg = False
40+
if v < 0:
41+
neg = True
42+
v = -v
43+
44+
# Convert the int to bytes
45+
v_bin = bytearray()
46+
bytes_len = (v.bit_length() + 7) // 8
47+
for i in range(bytes_len, 0, -1):
48+
v_bin.append((v >> ((i - 1) * 8)) & 0xff)
49+
50+
# Add the sign bit if necessary
51+
if neg:
52+
if have_ext:
53+
ext[0] |= 0x80
54+
else:
55+
v_bin[0] |= 0x80
56+
57+
v_bytes = ext + v_bin
58+
# Reverse bytes ordering for LE
59+
v_bytes.reverse()
60+
61+
return bytes(v_bytes)
2962

3063
_opcode_instances = []
3164
class CScriptOp(int):

0 commit comments

Comments
 (0)