1
- import sys , re , json
2
- from pyethereum import utils
1
+ import sys
2
+ import re
3
+ import json
4
+ from ethereum import utils
3
5
from rlp .utils import decode_hex , encode_hex
4
- from pyethereum .utils import encode_int , zpad , big_endian_to_int , is_numeric , is_string
6
+ from ethereum .utils import encode_int , zpad , big_endian_to_int , is_numeric , is_string
5
7
6
8
if sys .version_info .major == 2 :
7
9
def json_decode (x ):
@@ -73,7 +75,7 @@ def encode(self, name, args):
73
75
def decode (self , name , data ):
74
76
fdata = self .function_data [name ]
75
77
if fdata ['is_unknown_type' ]:
76
- o = [utils .to_signed (utils .big_endian_to_int (data [i :i + 32 ]))
78
+ o = [utils .to_signed (utils .big_endian_to_int (data [i :i + 32 ]))
77
79
for i in range (0 , len (data ), 32 )]
78
80
return [0 if not o else o [0 ] if len (o ) == 1 else o ]
79
81
return decode_abi (fdata ['decode_types' ], data )
@@ -106,6 +108,8 @@ def listen(self, log):
106
108
return o
107
109
108
110
# Decode an integer
111
+
112
+
109
113
def decint (n ):
110
114
if is_numeric (n ) and n < 2 ** 256 and n > - 2 ** 255 :
111
115
return n
@@ -138,7 +142,7 @@ def encode_single(arg, base, sub):
138
142
elif base == 'int' :
139
143
sub = int (sub )
140
144
i = decint (arg )
141
- assert - 2 ** (sub - 1 ) <= i < 2 ** sub , "Value out of bounds: %r" % arg
145
+ assert - 2 ** (sub - 1 ) <= i < 2 ** sub , "Value out of bounds: %r" % arg
142
146
normal_args = zpad (encode_int (i % 2 ** sub ), 32 )
143
147
# Unsigned reals: ureal<high>x<low>
144
148
elif base == 'ureal' :
@@ -148,7 +152,7 @@ def encode_single(arg, base, sub):
148
152
# Signed reals: real<high>x<low>
149
153
elif base == 'real' :
150
154
high , low = [int (x ) for x in sub .split ('x' )]
151
- assert - 2 ** (high - 1 ) <= arg < 2 ** (high - 1 ), \
155
+ assert - 2 ** (high - 1 ) <= arg < 2 ** (high - 1 ), \
152
156
"Value out of bounds: %r" % arg
153
157
normal_args = zpad (encode_int ((arg % 2 ** high ) * 2 ** low ), 32 )
154
158
# Strings
@@ -304,7 +308,7 @@ def decode_single(data, base, sub):
304
308
return big_endian_to_int (data )
305
309
elif base == 'int' :
306
310
o = big_endian_to_int (data )
307
- return (o - 2 ** int (sub )) if o >= 2 ** (int (sub )- 1 ) else o
311
+ return (o - 2 ** int (sub )) if o >= 2 ** (int (sub ) - 1 ) else o
308
312
elif base == 'ureal' :
309
313
high , low = [int (x ) for x in sub .split ('x' )]
310
314
return big_endian_to_int (data ) * 1.0 / 2 ** low
@@ -319,7 +323,7 @@ def decode_any(data, base, sub, arrlist):
319
323
sz = getlen (base , sub , arrlist [:- 1 ])
320
324
o = []
321
325
for i in range (0 , len (data ), sz ):
322
- o .append (decode_any (data [i : i + sz ], base , sub , arrlist [:- 1 ]))
326
+ o .append (decode_any (data [i : i + sz ], base , sub , arrlist [:- 1 ]))
323
327
return o
324
328
325
329
0 commit comments