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

Commit 85e2725

Browse files
author
Jan Xie
committed
Merge branch 'develop_with_state_revamp' into develop
2 parents 010e6b2 + c37a462 commit 85e2725

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+145252
-5364
lines changed

.release_notify.sh

100755100644
File mode changed.

ethereum/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# -*- coding: utf-8 -*-
22
# ############# version ##################
3-
from pkg_resources import get_distribution, DistributionNotFound
3+
try:
4+
from pkg_resources import get_distribution, DistributionNotFound
5+
except:
6+
DistributionNotFound = Exception
47
import os.path
58
import subprocess
69
import re

ethereum/abi.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
from ethereum import utils
1313
from ethereum.utils import (
1414
big_endian_to_int, ceil32, int_to_big_endian, encode_int, is_numeric, is_string,
15-
rzpad, TT255, TT256, zpad,
15+
rzpad, zpad, str_to_bytes
1616
)
17+
from ethereum.utils import TT256, TT255
1718

1819
# The number of bytes is encoded as a uint256
1920
# Type used to encode a string/bytes length
@@ -259,7 +260,7 @@ def encode_single(typ, arg): # pylint: disable=too-many-return-statements,too-m
259260
if not -2 ** bits <= i < 2 ** bits:
260261
raise ValueOutOfBounds(repr(arg))
261262

262-
value = i % 2 ** sub # convert negative to "equivalent" positive
263+
value = i % 2 ** 256 # convert negative to "equivalent" positive
263264
value_encoded = int_to_big_endian(value)
264265
return zpad(value_encoded, 32)
265266

@@ -309,6 +310,11 @@ def encode_single(typ, arg): # pylint: disable=too-many-return-statements,too-m
309310
value = fixed_point % 2 ** 256
310311
return zpad(int_to_big_endian(value), 32)
311312

313+
# Decimals
314+
if base == 'decimal':
315+
val_to_encode = int(arg * 10**int(sub))
316+
return zpad(encode_int(val_to_encode % 2**256), 32)
317+
312318
if base == 'string':
313319
if isinstance(arg, utils.unicode):
314320
arg = arg.encode('utf8')
@@ -412,24 +418,25 @@ def __init__(self, contract_interface):
412418
if entry_type != 'fallback' and 'inputs' in description:
413419
encode_types = [
414420
element['type']
415-
for element in description.get('inputs')
421+
for element in description.get('inputs', [])
416422
]
417423

418424
signature = [
419425
(element['type'], element['name'])
420-
for element in description.get('inputs')
426+
for element in description.get('inputs', [])
421427
]
422428

423429
if entry_type == 'function':
424430
normalized_name = normalize_name(description['name'])
431+
prefix = method_id(normalized_name, encode_types)
425432

426433
decode_types = [
427434
element['type']
428-
for element in description['outputs']
435+
for element in description.get('outputs', [])
429436
]
430437

431438
self.function_data[normalized_name] = {
432-
'prefix': method_id(normalized_name, encode_types),
439+
'prefix': prefix,
433440
'encode_types': encode_types,
434441
'decode_types': decode_types,
435442
'is_constant': description.get('constant', False),
@@ -724,7 +731,7 @@ def encode_abi(types, args):
724731
def decode_single(typ, data):
725732
base, sub, _ = typ
726733
if base == 'address':
727-
return encode_hex(data[12:])
734+
return '0x' + encode_hex(data[12:])
728735
elif base == 'hash':
729736
return data[32 - int(sub):]
730737
elif base == 'string' or base == 'bytes':
@@ -746,8 +753,14 @@ def decode_single(typ, data):
746753
o = big_endian_to_int(data)
747754
i = (o - 2 ** (high + low)) if o >= 2 ** (high + low - 1) else o
748755
return (i * 1.0 // 2 ** low)
756+
elif base == 'decimal':
757+
o = big_endian_to_int(data)
758+
i = (o - 2 ** 256 if o > 2 ** 255 else o)
759+
return i / 10 ** int(sub)
749760
elif base == 'bool':
750761
return bool(int(encode_hex(data), 16))
762+
else:
763+
raise EncodingError("Unhandled type: %r %r" % (base, sub))
751764

752765

753766
# Decodes multiple arguments using the head/tail mechanism
@@ -799,7 +812,7 @@ def dec(typ, arg):
799812
# Dynamic-sized strings are encoded as <len(str)> + <str>
800813
if base in ('string', 'bytes') and not sub:
801814
L = big_endian_to_int(arg[:32])
802-
assert len(arg[32:]) == ceil32(L), "Wrong data size for string/bytes object"
815+
assert len(arg[32:]) == ceil32(L), "Wrong data size for string/bytes object: expected %d actual %d" % (ceil32(L), len(arg[32:]))
803816
return arg[32:][:L]
804817
# Dynamic-sized arrays
805818
elif sz is None:

ethereum/block_creation.py

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

0 commit comments

Comments
 (0)