@@ -255,8 +255,8 @@ def decint(n, signed=False):
255
255
n = utils .to_string (n )
256
256
257
257
if is_numeric (n ):
258
- min , max = (- TT255 ,TT255 - 1 ) if signed else (0 ,TT256 - 1 )
259
- if n > max or n < min :
258
+ min_ , max_ = (- TT255 , TT255 - 1 ) if signed else (0 , TT256 - 1 )
259
+ if n > max_ or n < min_ :
260
260
raise EncodingError ("Number out of range: %r" % n )
261
261
return n
262
262
elif is_string (n ):
@@ -274,6 +274,7 @@ def decint(n, signed=False):
274
274
else :
275
275
raise EncodingError ("Cannot encode integer: %r" % n )
276
276
277
+
277
278
# Encodes a base datum
278
279
def encode_single (typ , arg ):
279
280
base , sub , _ = typ
@@ -282,7 +283,7 @@ def encode_single(typ, arg):
282
283
sub = int (sub )
283
284
i = decint (arg , False )
284
285
285
- if not 0 <= i < 2 ** sub :
286
+ if not 0 <= i < 2 ** sub :
286
287
raise ValueOutOfBounds (repr (arg ))
287
288
return zpad (encode_int (i ), 32 )
288
289
# bool: int<sz>
@@ -293,22 +294,22 @@ def encode_single(typ, arg):
293
294
elif base == 'int' :
294
295
sub = int (sub )
295
296
i = decint (arg , True )
296
- if not - 2 ** (sub - 1 ) <= i < 2 ** (sub - 1 ):
297
+ if not - 2 ** (sub - 1 ) <= i < 2 ** (sub - 1 ):
297
298
raise ValueOutOfBounds (repr (arg ))
298
- return zpad (encode_int (i % 2 ** sub ), 32 )
299
+ return zpad (encode_int (i % 2 ** sub ), 32 )
299
300
# Unsigned reals: ureal<high>x<low>
300
301
elif base == 'ureal' :
301
302
high , low = [int (x ) for x in sub .split ('x' )]
302
- if not 0 <= arg < 2 ** high :
303
+ if not 0 <= arg < 2 ** high :
303
304
raise ValueOutOfBounds (repr (arg ))
304
- return zpad (encode_int (int (arg * 2 ** low )), 32 )
305
+ return zpad (encode_int (int (arg * 2 ** low )), 32 )
305
306
# Signed reals: real<high>x<low>
306
307
elif base == 'real' :
307
308
high , low = [int (x ) for x in sub .split ('x' )]
308
- if not - 2 ** (high - 1 ) <= arg < 2 ** (high - 1 ):
309
+ if not - 2 ** (high - 1 ) <= arg < 2 ** (high - 1 ):
309
310
raise ValueOutOfBounds (repr (arg ))
310
- i = int (arg * 2 ** low )
311
- return zpad (encode_int (i % 2 ** (high + low )), 32 )
311
+ i = int (arg * 2 ** low )
312
+ return zpad (encode_int (i % 2 ** (high + low )), 32 )
312
313
# Strings
313
314
elif base == 'string' or base == 'bytes' :
314
315
if not is_string (arg ):
@@ -480,7 +481,7 @@ def decode_single(typ, data):
480
481
if base == 'address' :
481
482
return encode_hex (data [12 :])
482
483
elif base == 'hash' :
483
- return data [32 - int (sub ):]
484
+ return data [32 - int (sub ):]
484
485
elif base == 'string' or base == 'bytes' :
485
486
if len (sub ):
486
487
return data [:int (sub )]
@@ -491,15 +492,15 @@ def decode_single(typ, data):
491
492
return big_endian_to_int (data )
492
493
elif base == 'int' :
493
494
o = big_endian_to_int (data )
494
- return (o - 2 ** int (sub )) if o >= 2 ** (int (sub ) - 1 ) else o
495
+ return (o - 2 ** int (sub )) if o >= 2 ** (int (sub ) - 1 ) else o
495
496
elif base == 'ureal' :
496
497
high , low = [int (x ) for x in sub .split ('x' )]
497
- return big_endian_to_int (data ) * 1.0 // 2 ** low
498
+ return big_endian_to_int (data ) * 1.0 // 2 ** low
498
499
elif base == 'real' :
499
500
high , low = [int (x ) for x in sub .split ('x' )]
500
501
o = big_endian_to_int (data )
501
- i = (o - 2 ** (high + low )) if o >= 2 ** (high + low - 1 ) else o
502
- return (i * 1.0 // 2 ** low )
502
+ i = (o - 2 ** (high + low )) if o >= 2 ** (high + low - 1 ) else o
503
+ return (i * 1.0 // 2 ** low )
503
504
elif base == 'bool' :
504
505
return bool (int (encode_hex (data ), 16 ))
505
506
0 commit comments