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

Commit 237df71

Browse files
vubvub
authored andcommitted
Added support for decimal ABI encoding
1 parent f0a1bd1 commit 237df71

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ethereum/abi.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ def encode_single(typ, arg):
309309
raise ValueOutOfBounds(repr(arg))
310310
i = int(arg * 2**low)
311311
return zpad(encode_int(i % 2**(high+low)), 32)
312+
# Decimals
313+
elif base == 'decimal':
314+
val_to_encode = int(arg * 10**int(sub))
315+
return zpad(encode_int(val_to_encode % 2**256), 32)
312316
# Strings
313317
elif base == 'string' or base == 'bytes':
314318
if not is_string(arg):
@@ -500,8 +504,14 @@ def decode_single(typ, data):
500504
o = big_endian_to_int(data)
501505
i = (o - 2**(high+low)) if o >= 2**(high+low-1) else o
502506
return (i * 1.0 // 2**low)
507+
elif base == 'decimal':
508+
o = big_endian_to_int(data)
509+
i = (o - 2**256 if o > 2**255 else o)
510+
return i / 10**int(sub)
503511
elif base == 'bool':
504512
return bool(int(encode_hex(data), 16))
513+
else:
514+
raise EncodingError("Unhandled type: %r %r" % (base, sub))
505515

506516

507517
# Decodes multiple arguments using the head/tail mechanism

0 commit comments

Comments
 (0)