mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 14:08:40 +01:00
[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.
This commit is contained in:
@@ -121,9 +121,6 @@ Utilities for manipulating transaction scripts (originally from python-bitcoinli
|
|||||||
#### [key.py](test_framework/key.py)
|
#### [key.py](test_framework/key.py)
|
||||||
Test-only secp256k1 elliptic curve implementation
|
Test-only secp256k1 elliptic curve implementation
|
||||||
|
|
||||||
#### [bignum.py](test_framework/bignum.py)
|
|
||||||
Helpers for script.py
|
|
||||||
|
|
||||||
#### [blocktools.py](test_framework/blocktools.py)
|
#### [blocktools.py](test_framework/blocktools.py)
|
||||||
Helper functions for creating blocks and transactions.
|
Helper functions for creating blocks and transactions.
|
||||||
|
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
#
|
|
||||||
# Distributed under the MIT software license, see the accompanying
|
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
||||||
"""Big number routines.
|
|
||||||
|
|
||||||
Functions for converting numbers to MPI format and Bitcoin-specific little
|
|
||||||
endian format.
|
|
||||||
|
|
||||||
This file is copied from python-bitcoinlib.
|
|
||||||
"""
|
|
||||||
def bn2mpi(v):
|
|
||||||
"""Convert number to MPI format, without the sign byte."""
|
|
||||||
# The top bit is used to indicate the sign of the number. If there
|
|
||||||
# isn't a spare bit in the bit length, add an extension byte.
|
|
||||||
have_ext = False
|
|
||||||
ext = bytearray()
|
|
||||||
if v.bit_length() > 0:
|
|
||||||
have_ext = (v.bit_length() & 0x07) == 0
|
|
||||||
ext.append(0)
|
|
||||||
|
|
||||||
# Is the number negative?
|
|
||||||
neg = False
|
|
||||||
if v < 0:
|
|
||||||
neg = True
|
|
||||||
v = -v
|
|
||||||
|
|
||||||
# Convert the int to bytes
|
|
||||||
v_bin = bytearray()
|
|
||||||
bytes_len = (v.bit_length() + 7) // 8
|
|
||||||
for i in range(bytes_len, 0, -1):
|
|
||||||
v_bin.append((v >> ((i - 1) * 8)) & 0xff)
|
|
||||||
|
|
||||||
# Add the sign bit if necessary
|
|
||||||
if neg:
|
|
||||||
if have_ext:
|
|
||||||
ext[0] |= 0x80
|
|
||||||
else:
|
|
||||||
v_bin[0] |= 0x80
|
|
||||||
return ext + v_bin
|
|
||||||
|
|
||||||
def bn2vch(v):
|
|
||||||
"""Convert number to bitcoin-specific little endian format."""
|
|
||||||
return bytes(reversed(bn2mpi(v)))
|
|
||||||
@@ -9,7 +9,6 @@ This file is modified from python-bitcoinlib.
|
|||||||
import hashlib
|
import hashlib
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
from .bignum import bn2vch
|
|
||||||
from .messages import (
|
from .messages import (
|
||||||
CTransaction,
|
CTransaction,
|
||||||
CTxOut,
|
CTxOut,
|
||||||
@@ -26,6 +25,40 @@ OPCODE_NAMES = {}
|
|||||||
def hash160(s):
|
def hash160(s):
|
||||||
return hashlib.new('ripemd160', sha256(s)).digest()
|
return hashlib.new('ripemd160', sha256(s)).digest()
|
||||||
|
|
||||||
|
def bn2vch(v):
|
||||||
|
"""Convert number to bitcoin-specific little endian format."""
|
||||||
|
# The top bit is used to indicate the sign of the number. If there
|
||||||
|
# isn't a spare bit in the bit length, add an extension byte.
|
||||||
|
have_ext = False
|
||||||
|
ext = bytearray()
|
||||||
|
if v.bit_length() > 0:
|
||||||
|
have_ext = (v.bit_length() & 0x07) == 0
|
||||||
|
ext.append(0)
|
||||||
|
|
||||||
|
# Is the number negative?
|
||||||
|
neg = False
|
||||||
|
if v < 0:
|
||||||
|
neg = True
|
||||||
|
v = -v
|
||||||
|
|
||||||
|
# Convert the int to bytes
|
||||||
|
v_bin = bytearray()
|
||||||
|
bytes_len = (v.bit_length() + 7) // 8
|
||||||
|
for i in range(bytes_len, 0, -1):
|
||||||
|
v_bin.append((v >> ((i - 1) * 8)) & 0xff)
|
||||||
|
|
||||||
|
# Add the sign bit if necessary
|
||||||
|
if neg:
|
||||||
|
if have_ext:
|
||||||
|
ext[0] |= 0x80
|
||||||
|
else:
|
||||||
|
v_bin[0] |= 0x80
|
||||||
|
|
||||||
|
v_bytes = ext + v_bin
|
||||||
|
# Reverse bytes ordering for LE
|
||||||
|
v_bytes.reverse()
|
||||||
|
|
||||||
|
return bytes(v_bytes)
|
||||||
|
|
||||||
_opcode_instances = []
|
_opcode_instances = []
|
||||||
class CScriptOp(int):
|
class CScriptOp(int):
|
||||||
|
|||||||
Reference in New Issue
Block a user