Skip to content

Commit 9a23b0f

Browse files
committed
use new version of rlp
1 parent 87251eb commit 9a23b0f

27 files changed

+49
-36
lines changed

ethereum/abi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# use yaml instead of json to get non unicode (works with ascii only data)
99
import yaml
10-
from rlp.utils import decode_hex
10+
from ethereum.utils import decode_hex
1111
from ethereum.utils import encode_hex
1212

1313
from ethereum import utils

ethereum/compress.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from rlp.utils import decode_hex, ascii_chr
1+
from ethereum.utils import decode_hex, ascii_chr
22
from ethereum.utils import safe_ord, int_to_bytes
33

44
NULLSHA3 = decode_hex(

ethereum/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from rlp.utils import decode_hex
1+
from ethereum.utils import decode_hex
22

33
from ethereum import utils
44
from ethereum.db import BaseDB, EphemDB

ethereum/db.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from ethereum import utils
22
from ethereum.slogging import get_logger
3-
from rlp.utils import str_to_bytes
3+
from ethereum.utils import str_to_bytes
44
import sys
55
if sys.version_info.major == 2:
66
from repoze.lru import lru_cache

ethereum/experimental/fastvm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from ethereum import opcodes
1313
import time
1414
from ethereum.slogging import get_logger
15-
from rlp.utils import ascii_chr
15+
from ethereum.utils import ascii_chr
1616
from ethereum.utils import encode_hex
1717
from ethereum.utils import to_string
1818

ethereum/experimental/pruning_trie.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ethereum.utils import is_string
88
from ethereum.utils import encode_hex
99
import copy
10-
from rlp.utils import decode_hex, ascii_chr, str_to_bytes
10+
from ethereum.utils import decode_hex, ascii_chr, str_to_bytes
1111
import sys
1212
from ethereum.fast_rlp import encode_optimized
1313
rlp_encode = encode_optimized

ethereum/fastvm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from ethereum import opcodes
1313
import time
1414
from ethereum.slogging import get_logger
15-
from rlp.utils import encode_hex, ascii_chr
15+
from ethereum.utils import encode_hex, ascii_chr
1616
from ethereum.utils import to_string, encode_int, zpad, bytearray_to_bytestr
1717

1818
log_log = get_logger('eth.vm.log')

ethereum/hybrid_casper/chain.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from ethereum.common import update_block_env_variables
1515
from ethereum.tools import tester
1616
import rlp
17-
from rlp.utils import encode_hex
17+
from ethereum.utils import encode_hex
1818
from ethereum.exceptions import InvalidTransaction, VerificationFailed
1919
from ethereum.slogging import get_logger
2020
from ethereum.config import Env

ethereum/messages.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
safe_ord, int_to_addr, sha3, big_endian_to_int, \
77
ascii_chr, bytearray_to_bytestr
88
from rlp.sedes import big_endian_int, Binary, binary, CountableList
9-
from rlp.utils import decode_hex, encode_hex, ascii_chr
9+
from ethereum.utils import decode_hex, encode_hex, ascii_chr
1010
from ethereum import utils
1111
from ethereum import trie
1212
from ethereum import bloom

ethereum/pow/chain.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ethereum.common import update_block_env_variables
1111
from ethereum.messages import apply_transaction
1212
import rlp
13-
from rlp.utils import encode_hex
13+
from ethereum.utils import encode_hex
1414
from ethereum.exceptions import InvalidNonce, InsufficientStartGas, UnsignedTransaction, \
1515
BlockGasLimitReached, InsufficientBalance, InvalidTransaction, VerificationFailed
1616
from ethereum.slogging import get_logger, configure_logging

ethereum/pow/ethash_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def sha3_512(x): return keccak.new(digest_bits=512, data=x)
1010
def sha3_256(x): return _sha3.sha3_256(x).digest()
1111

1212
def sha3_512(x): return _sha3.sha3_512(x).digest()
13-
from rlp.utils import decode_hex
13+
from ethereum.utils import decode_hex
1414
from ethereum.utils import encode_hex
1515
import sys
1616

ethereum/specials.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf8 -*-
22
from py_ecc.secp256k1 import privtopub, ecdsa_raw_recover, N as secp256k1n
33
import hashlib
4-
from rlp.utils import ascii_chr
4+
from ethereum.utils import ascii_chr
55

66
from ethereum import utils, opcodes
77
from ethereum.utils import safe_ord, decode_hex, encode_int32

ethereum/tests/test_blocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ethereum.config import Env
88
from ethereum.genesis_helpers import state_from_genesis_declaration, initialize_genesis_keys
99
import rlp
10-
from rlp.utils import decode_hex, encode_hex, str_to_bytes
10+
from ethereum.utils import decode_hex, encode_hex, str_to_bytes
1111
from rlp import DecodingError, DeserializationError
1212
import os
1313
import sys

ethereum/tests/test_bloom.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import ethereum.tools.testutils as testutils
66
import ethereum.bloom as bloom
77
import os
8-
from rlp.utils import decode_hex, str_to_bytes
8+
from ethereum.utils import decode_hex, str_to_bytes
99
from ethereum.utils import encode_hex
1010

1111

ethereum/tests/test_chain.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import ethereum.meta as meta
66
from ethereum.transaction_queue import TransactionQueue
77
import rlp
8-
from rlp.utils import decode_hex, encode_hex
8+
from ethereum.utils import decode_hex, encode_hex
99
import ethereum.pow.ethpow as ethpow
1010
import ethereum.utils as utils
1111
from ethereum.pow.chain import Chain

ethereum/tests/test_contracts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import bitcoin
55
import pytest
66
import serpent
7-
from rlp.utils import decode_hex
7+
from ethereum.utils import decode_hex
88

99
from ethereum import utils, abi
1010
from ethereum.tools import tester

ethereum/tests/test_db.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import random
33
import pytest
44
from ethereum.db import _EphemDB
5-
from rlp.utils import ascii_chr
5+
from ethereum.utils import ascii_chr
66

77
random.seed(0)
88

ethereum/tests/test_transactions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ethereum.transactions as transactions
22
import ethereum.utils as utils
33
import rlp
4-
from rlp.utils import decode_hex, encode_hex, str_to_bytes
4+
from ethereum.utils import decode_hex, encode_hex, str_to_bytes
55
from ethereum.tools import testutils
66
from ethereum.messages import config_fork_specific_validation, null_address
77
import ethereum.config as config

ethereum/tests/test_trie.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import ethereum.db as db
55
import itertools
66
from ethereum.slogging import get_logger
7-
from rlp.utils import decode_hex
7+
from ethereum.utils import decode_hex
88
from ethereum.utils import encode_hex, to_string
99
from ethereum.abi import is_string
1010
logger = get_logger()

ethereum/tools/_solidity.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import yaml
99

10-
from rlp.utils import decode_hex
10+
from ethereum.utils import decode_hex
1111
from ethereum import utils
1212

1313
BINARY = 'solc'

ethereum/tools/keys.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
import pbkdf2
44

5-
from rlp.utils import decode_hex
5+
from ethereum.utils import decode_hex
66
from ethereum.utils import encode_hex
77

88
try:

ethereum/transactions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# -*- coding: utf-8 -*-
22
import rlp
33
from rlp.sedes import big_endian_int, binary
4-
from rlp.utils import str_to_bytes, ascii_chr
5-
from ethereum.utils import encode_hex
4+
from ethereum.utils import str_to_bytes
5+
from ethereum.utils import encode_hex, ascii_chr
66

77
from ethereum.exceptions import InvalidTransaction
88
from ethereum import bloom

ethereum/trie.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ethereum.utils import to_string
66
from ethereum.abi import is_string
77
import copy
8-
from rlp.utils import decode_hex, ascii_chr, str_to_bytes
8+
from ethereum.utils import decode_hex, ascii_chr, str_to_bytes
99
from ethereum.utils import encode_hex
1010
from ethereum.fast_rlp import encode_optimized
1111
rlp_encode = encode_optimized

ethereum/utils.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ def sha3_256(x): return _sha3.keccak_256(x).digest()
1010
import sys
1111
import rlp
1212
from rlp.sedes import big_endian_int, BigEndianInt, Binary
13-
from rlp.utils import decode_hex, encode_hex, ascii_chr, str_to_bytes
13+
from eth_utils import encode_hex as encode_hex_0x
14+
from eth_utils import decode_hex, int_to_big_endian, big_endian_to_int
15+
from rlp.utils import ALL_BYTES
1416
import random
1517

16-
1718
try:
1819
import coincurve
1920
except ImportError:
@@ -30,13 +31,6 @@ def __call__(self, *args):
3031
self.memo[args] = self.fn(*args)
3132
return self.memo[args]
3233

33-
def big_endian_to_int(x): return big_endian_int.deserialize(
34-
str_to_bytes(x).lstrip(b'\x00'))
35-
36-
37-
def int_to_big_endian(x): return big_endian_int.serialize(x)
38-
39-
4034
TT256 = 2 ** 256
4135
TT256M1 = 2 ** 256 - 1
4236
TT255 = 2 ** 255
@@ -68,6 +62,13 @@ def encode_int32(v):
6862
def bytes_to_int(value):
6963
return big_endian_to_int(bytes(''.join(chr(c) for c in value)))
7064

65+
def str_to_bytes(value):
66+
if isinstance(value, (bytes, bytearray)):
67+
return bytes(value)
68+
elif isinstance(value, unicode):
69+
return codecs.encode(value, 'utf8')
70+
else:
71+
raise TypeError("Value must be text, bytes, or bytearray")
7172
else:
7273
def is_numeric(x): return isinstance(x, int)
7374

@@ -99,6 +100,18 @@ def encode_int32(v):
99100
def bytes_to_int(value):
100101
return int.from_bytes(value, byteorder='big')
101102

103+
def str_to_bytes(value):
104+
if isinstance(value, bytearray):
105+
value = bytes(value)
106+
if isinstance(value, bytes):
107+
return value
108+
return bytes(value, 'utf-8')
109+
110+
def ascii_chr(n):
111+
return ALL_BYTES[n]
112+
113+
def encode_hex(n):
114+
return encode_hex_0x(n)[2:]
102115

103116
def ecrecover_to_pub(rawhash, v, r, s):
104117
if coincurve and hasattr(coincurve, "PublicKey"):

ethereum/vm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import copy
1010

11-
from rlp.utils import encode_hex, ascii_chr
11+
from ethereum.utils import encode_hex, ascii_chr
1212
from ethereum import utils
1313
from ethereum.abi import is_numeric
1414
from ethereum import opcodes

tools/random_vm_test_generator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
u = pyethereum.utils
66
import sys
77
import random
8-
from rlp.utils import encode_hex, ascii_chr
8+
from ethereum.utils import encode_hex, ascii_chr
99

1010

1111
def mkrndgen(seed):

tools/vm_test_generator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
pb = pyethereum.processblock
55
import serpent
66
import sys
7-
from rlp.utils import encode_hex, ascii_chr
7+
from ethereum.utils import encode_hex, ascii_chr
88

99

1010
# Code: serpent code

0 commit comments

Comments
 (0)