Skip to content

Commit d641c79

Browse files
committed
Make bitcoin.core.bignum internal use
May be replaced, as was done in Bitcoin Core
1 parent e3cdf68 commit d641c79

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

README

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ consensus critical and non-consensus-critical.
2626

2727
bitcoin.core - Basic core definitions, datastructures, and
2828
(context-independent) validation
29-
bitcoin.core.bignum - Bignum handling
3029
bitcoin.core.key - ECC pubkeys
3130
bitcoin.core.script - Scripts and opcodes
3231
bitcoin.core.scripteval - Script evaluation/verification

bitcoin/core/bignum.py renamed to bitcoin/core/_bignum.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
# propagated, or distributed except according to the terms contained in the
1010
# LICENSE file.
1111

12-
"""Bignum routines"""
12+
# Bignum routines
13+
#
14+
# Internally used for script evaluation; not to be used externally.
1315

1416
from __future__ import absolute_import, division, print_function, unicode_literals
1517

bitcoin/core/script.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import struct
3030

3131
import bitcoin.core
32-
import bitcoin.core.bignum
32+
import bitcoin.core._bignum
3333

3434
MAX_SCRIPT_SIZE = 10000
3535
MAX_SCRIPT_ELEMENT_SIZE = 520
@@ -521,7 +521,7 @@ def __coerce_instance(cls, other):
521521
elif other == -1:
522522
other = bytes(_bchr(OP_1NEGATE))
523523
else:
524-
other = CScriptOp.encode_op_pushdata(bitcoin.core.bignum.bn2vch(other))
524+
other = CScriptOp.encode_op_pushdata(bitcoin.core._bignum.bn2vch(other))
525525
elif isinstance(other, (bytes, bytearray)):
526526
other = CScriptOp.encode_op_pushdata(other)
527527
return other

bitcoin/core/scripteval.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import hashlib
2929

3030
import bitcoin.core
31+
import bitcoin.core._bignum
3132
import bitcoin.core.key
3233
import bitcoin.core.serialize
3334

@@ -96,7 +97,7 @@ def __init__(self, opcode, **kwargs):
9697
**kwargs)
9798

9899
def _CastToBigNum(s, err_raiser):
99-
v = bitcoin.core.bignum.vch2bn(s)
100+
v = bitcoin.core._bignum.vch2bn(s)
100101
if len(s) > MAX_NUM_SIZE:
101102
raise err_raiser(EvalScriptError, 'CastToBigNum() : overflow')
102103
return v
@@ -239,7 +240,7 @@ def _UnaryOp(opcode, stack, err_raiser):
239240
else:
240241
raise AssertionError("Unknown unary opcode encountered; this should not happen")
241242

242-
stack.append(bitcoin.core.bignum.bn2vch(bn))
243+
stack.append(bitcoin.core._bignum.bn2vch(bn))
243244

244245

245246
# OP_LSHIFT and OP_RSHIFT are *not* included in this list as they are disabled
@@ -326,7 +327,7 @@ def _BinOp(opcode, stack, err_raiser):
326327

327328
stack.pop()
328329
stack.pop()
329-
stack.append(bitcoin.core.bignum.bn2vch(bn))
330+
stack.append(bitcoin.core._bignum.bn2vch(bn))
330331

331332

332333
def _CheckExec(vfExec):
@@ -399,7 +400,7 @@ def check_args(n):
399400

400401
if sop == OP_1NEGATE or ((sop >= OP_1) and (sop <= OP_16)):
401402
v = sop - (OP_1 - 1)
402-
stack.append(bitcoin.core.bignum.bn2vch(v))
403+
stack.append(bitcoin.core._bignum.bn2vch(v))
403404

404405
elif sop in _ISA_BINOP:
405406
_BinOp(sop, stack, err_raiser)
@@ -490,7 +491,7 @@ def check_args(n):
490491

491492
elif sop == OP_DEPTH:
492493
bn = len(stack)
493-
stack.append(bitcoin.core.bignum.bn2vch(bn))
494+
stack.append(bitcoin.core._bignum.bn2vch(bn))
494495

495496
elif sop == OP_DROP:
496497
check_args(1)
@@ -610,7 +611,7 @@ def check_args(n):
610611
elif sop == OP_SIZE:
611612
check_args(1)
612613
bn = len(stack[-1])
613-
stack.append(bitcoin.core.bignum.bn2vch(bn))
614+
stack.append(bitcoin.core._bignum.bn2vch(bn))
614615

615616
elif sop == OP_SHA1:
616617
check_args(1)

0 commit comments

Comments
 (0)