Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #869 from yihuang/develop
Browse files Browse the repository at this point in the history
use new version of rlp, fix #868
  • Loading branch information
joeykrug committed Apr 26, 2018
2 parents 87251eb + 9a23b0f commit c8b6205
Show file tree
Hide file tree
Showing 27 changed files with 49 additions and 36 deletions.
2 changes: 1 addition & 1 deletion ethereum/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# use yaml instead of json to get non unicode (works with ascii only data)
import yaml
from rlp.utils import decode_hex
from ethereum.utils import decode_hex
from ethereum.utils import encode_hex

from ethereum import utils
Expand Down
2 changes: 1 addition & 1 deletion ethereum/compress.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from rlp.utils import decode_hex, ascii_chr
from ethereum.utils import decode_hex, ascii_chr
from ethereum.utils import safe_ord, int_to_bytes

NULLSHA3 = decode_hex(
Expand Down
2 changes: 1 addition & 1 deletion ethereum/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from rlp.utils import decode_hex
from ethereum.utils import decode_hex

from ethereum import utils
from ethereum.db import BaseDB, EphemDB
Expand Down
2 changes: 1 addition & 1 deletion ethereum/db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ethereum import utils
from ethereum.slogging import get_logger
from rlp.utils import str_to_bytes
from ethereum.utils import str_to_bytes
import sys
if sys.version_info.major == 2:
from repoze.lru import lru_cache
Expand Down
2 changes: 1 addition & 1 deletion ethereum/experimental/fastvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ethereum import opcodes
import time
from ethereum.slogging import get_logger
from rlp.utils import ascii_chr
from ethereum.utils import ascii_chr
from ethereum.utils import encode_hex
from ethereum.utils import to_string

Expand Down
2 changes: 1 addition & 1 deletion ethereum/experimental/pruning_trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ethereum.utils import is_string
from ethereum.utils import encode_hex
import copy
from rlp.utils import decode_hex, ascii_chr, str_to_bytes
from ethereum.utils import decode_hex, ascii_chr, str_to_bytes
import sys
from ethereum.fast_rlp import encode_optimized
rlp_encode = encode_optimized
Expand Down
2 changes: 1 addition & 1 deletion ethereum/fastvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ethereum import opcodes
import time
from ethereum.slogging import get_logger
from rlp.utils import encode_hex, ascii_chr
from ethereum.utils import encode_hex, ascii_chr
from ethereum.utils import to_string, encode_int, zpad, bytearray_to_bytestr

log_log = get_logger('eth.vm.log')
Expand Down
2 changes: 1 addition & 1 deletion ethereum/hybrid_casper/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ethereum.common import update_block_env_variables
from ethereum.tools import tester
import rlp
from rlp.utils import encode_hex
from ethereum.utils import encode_hex
from ethereum.exceptions import InvalidTransaction, VerificationFailed
from ethereum.slogging import get_logger
from ethereum.config import Env
Expand Down
2 changes: 1 addition & 1 deletion ethereum/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
safe_ord, int_to_addr, sha3, big_endian_to_int, \
ascii_chr, bytearray_to_bytestr
from rlp.sedes import big_endian_int, Binary, binary, CountableList
from rlp.utils import decode_hex, encode_hex, ascii_chr
from ethereum.utils import decode_hex, encode_hex, ascii_chr
from ethereum import utils
from ethereum import trie
from ethereum import bloom
Expand Down
2 changes: 1 addition & 1 deletion ethereum/pow/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ethereum.common import update_block_env_variables
from ethereum.messages import apply_transaction
import rlp
from rlp.utils import encode_hex
from ethereum.utils import encode_hex
from ethereum.exceptions import InvalidNonce, InsufficientStartGas, UnsignedTransaction, \
BlockGasLimitReached, InsufficientBalance, InvalidTransaction, VerificationFailed
from ethereum.slogging import get_logger, configure_logging
Expand Down
2 changes: 1 addition & 1 deletion ethereum/pow/ethash_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def sha3_512(x): return keccak.new(digest_bits=512, data=x)
def sha3_256(x): return _sha3.sha3_256(x).digest()

def sha3_512(x): return _sha3.sha3_512(x).digest()
from rlp.utils import decode_hex
from ethereum.utils import decode_hex
from ethereum.utils import encode_hex
import sys

Expand Down
2 changes: 1 addition & 1 deletion ethereum/specials.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf8 -*-
from py_ecc.secp256k1 import privtopub, ecdsa_raw_recover, N as secp256k1n
import hashlib
from rlp.utils import ascii_chr
from ethereum.utils import ascii_chr

from ethereum import utils, opcodes
from ethereum.utils import safe_ord, decode_hex, encode_int32
Expand Down
2 changes: 1 addition & 1 deletion ethereum/tests/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ethereum.config import Env
from ethereum.genesis_helpers import state_from_genesis_declaration, initialize_genesis_keys
import rlp
from rlp.utils import decode_hex, encode_hex, str_to_bytes
from ethereum.utils import decode_hex, encode_hex, str_to_bytes
from rlp import DecodingError, DeserializationError
import os
import sys
Expand Down
2 changes: 1 addition & 1 deletion ethereum/tests/test_bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ethereum.tools.testutils as testutils
import ethereum.bloom as bloom
import os
from rlp.utils import decode_hex, str_to_bytes
from ethereum.utils import decode_hex, str_to_bytes
from ethereum.utils import encode_hex


Expand Down
2 changes: 1 addition & 1 deletion ethereum/tests/test_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ethereum.meta as meta
from ethereum.transaction_queue import TransactionQueue
import rlp
from rlp.utils import decode_hex, encode_hex
from ethereum.utils import decode_hex, encode_hex
import ethereum.pow.ethpow as ethpow
import ethereum.utils as utils
from ethereum.pow.chain import Chain
Expand Down
2 changes: 1 addition & 1 deletion ethereum/tests/test_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import bitcoin
import pytest
import serpent
from rlp.utils import decode_hex
from ethereum.utils import decode_hex

from ethereum import utils, abi
from ethereum.tools import tester
Expand Down
2 changes: 1 addition & 1 deletion ethereum/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random
import pytest
from ethereum.db import _EphemDB
from rlp.utils import ascii_chr
from ethereum.utils import ascii_chr

random.seed(0)

Expand Down
2 changes: 1 addition & 1 deletion ethereum/tests/test_transactions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ethereum.transactions as transactions
import ethereum.utils as utils
import rlp
from rlp.utils import decode_hex, encode_hex, str_to_bytes
from ethereum.utils import decode_hex, encode_hex, str_to_bytes
from ethereum.tools import testutils
from ethereum.messages import config_fork_specific_validation, null_address
import ethereum.config as config
Expand Down
2 changes: 1 addition & 1 deletion ethereum/tests/test_trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ethereum.db as db
import itertools
from ethereum.slogging import get_logger
from rlp.utils import decode_hex
from ethereum.utils import decode_hex
from ethereum.utils import encode_hex, to_string
from ethereum.abi import is_string
logger = get_logger()
Expand Down
2 changes: 1 addition & 1 deletion ethereum/tools/_solidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import yaml

from rlp.utils import decode_hex
from ethereum.utils import decode_hex
from ethereum import utils

BINARY = 'solc'
Expand Down
2 changes: 1 addition & 1 deletion ethereum/tools/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
import pbkdf2

from rlp.utils import decode_hex
from ethereum.utils import decode_hex
from ethereum.utils import encode_hex

try:
Expand Down
4 changes: 2 additions & 2 deletions ethereum/transactions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
import rlp
from rlp.sedes import big_endian_int, binary
from rlp.utils import str_to_bytes, ascii_chr
from ethereum.utils import encode_hex
from ethereum.utils import str_to_bytes
from ethereum.utils import encode_hex, ascii_chr

from ethereum.exceptions import InvalidTransaction
from ethereum import bloom
Expand Down
2 changes: 1 addition & 1 deletion ethereum/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ethereum.utils import to_string
from ethereum.abi import is_string
import copy
from rlp.utils import decode_hex, ascii_chr, str_to_bytes
from ethereum.utils import decode_hex, ascii_chr, str_to_bytes
from ethereum.utils import encode_hex
from ethereum.fast_rlp import encode_optimized
rlp_encode = encode_optimized
Expand Down
31 changes: 22 additions & 9 deletions ethereum/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ def sha3_256(x): return _sha3.keccak_256(x).digest()
import sys
import rlp
from rlp.sedes import big_endian_int, BigEndianInt, Binary
from rlp.utils import decode_hex, encode_hex, ascii_chr, str_to_bytes
from eth_utils import encode_hex as encode_hex_0x
from eth_utils import decode_hex, int_to_big_endian, big_endian_to_int
from rlp.utils import ALL_BYTES
import random


try:
import coincurve
except ImportError:
Expand All @@ -30,13 +31,6 @@ def __call__(self, *args):
self.memo[args] = self.fn(*args)
return self.memo[args]

def big_endian_to_int(x): return big_endian_int.deserialize(
str_to_bytes(x).lstrip(b'\x00'))


def int_to_big_endian(x): return big_endian_int.serialize(x)


TT256 = 2 ** 256
TT256M1 = 2 ** 256 - 1
TT255 = 2 ** 255
Expand Down Expand Up @@ -68,6 +62,13 @@ def encode_int32(v):
def bytes_to_int(value):
return big_endian_to_int(bytes(''.join(chr(c) for c in value)))

def str_to_bytes(value):
if isinstance(value, (bytes, bytearray)):
return bytes(value)
elif isinstance(value, unicode):
return codecs.encode(value, 'utf8')
else:
raise TypeError("Value must be text, bytes, or bytearray")
else:
def is_numeric(x): return isinstance(x, int)

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

def str_to_bytes(value):
if isinstance(value, bytearray):
value = bytes(value)
if isinstance(value, bytes):
return value
return bytes(value, 'utf-8')

def ascii_chr(n):
return ALL_BYTES[n]

def encode_hex(n):
return encode_hex_0x(n)[2:]

def ecrecover_to_pub(rawhash, v, r, s):
if coincurve and hasattr(coincurve, "PublicKey"):
Expand Down
2 changes: 1 addition & 1 deletion ethereum/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import copy

from rlp.utils import encode_hex, ascii_chr
from ethereum.utils import encode_hex, ascii_chr
from ethereum import utils
from ethereum.abi import is_numeric
from ethereum import opcodes
Expand Down
2 changes: 1 addition & 1 deletion tools/random_vm_test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
u = pyethereum.utils
import sys
import random
from rlp.utils import encode_hex, ascii_chr
from ethereum.utils import encode_hex, ascii_chr


def mkrndgen(seed):
Expand Down
2 changes: 1 addition & 1 deletion tools/vm_test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pb = pyethereum.processblock
import serpent
import sys
from rlp.utils import encode_hex, ascii_chr
from ethereum.utils import encode_hex, ascii_chr


# Code: serpent code
Expand Down

0 comments on commit c8b6205

Please sign in to comment.