Add support for subdenomination

pull/87/head^2
Josselin 6 years ago
parent 2acd6d0289
commit 33a8cf4224
  1. 38
      slither/solc_parsing/expressions/expression_parsing.py

@ -237,6 +237,34 @@ def filter_name(value):
value = value[:idx+1] value = value[:idx+1]
return value return value
def convert_subdenomination(value, sub):
if sub is None:
return value
value = int(value)
if sub == 'wei':
return value
if sub == 'szabo':
return value * int(1e12)
if sub == 'finney':
return value * int(1e15)
if sub == 'ether':
return value * int(1e18)
if sub == 'seconds':
return value
if sub == 'minutes':
return value * 60
if sub == 'hours':
return value * 60 * 60
if sub == 'days':
return value * 60 * 60 * 24
if sub == 'weeks':
return value * 60 * 60 * 24 * 7
if sub == 'years':
return value * 60 * 60 * 24 * 7 * 365
logger.error('Subdemoniation not found {}'.format(sub))
return value
def parse_expression(expression, caller_context): def parse_expression(expression, caller_context):
""" """
@ -380,11 +408,17 @@ def parse_expression(expression, caller_context):
if is_compact_ast: if is_compact_ast:
value = expression['value'] value = expression['value']
if not value and value != "": if value:
if 'subdenomination' in expression and expression['subdenomination']:
value = str(convert_subdenomination(value, expression['subdenomination']))
elif not value and value != "":
value = '0x'+expression['hexValue'] value = '0x'+expression['hexValue']
else: else:
value = expression['attributes']['value'] value = expression['attributes']['value']
if value is None: if value:
if 'subdenomination' in expression['attributes'] and expression['attributes']['subdenomination']:
value = str(convert_subdenomination(value, expression['attributes']['subdenomination']))
elif value is None:
# for literal declared as hex # for literal declared as hex
# see https://solidity.readthedocs.io/en/v0.4.25/types.html?highlight=hex#hexadecimal-literals # see https://solidity.readthedocs.io/en/v0.4.25/types.html?highlight=hex#hexadecimal-literals
assert 'hexvalue' in expression['attributes'] assert 'hexvalue' in expression['attributes']

Loading…
Cancel
Save