mirror of https://github.com/crytic/slither
parent
036f7d62f4
commit
ce801942ab
@ -1,38 +1,35 @@ |
|||||||
from fractions import Fraction |
from fractions import Fraction |
||||||
|
|
||||||
from slither.exceptions import SlitherException |
from slither.exceptions import SlitherException |
||||||
|
from slither.utils.integer_conversion import convert_string_to_int |
||||||
|
|
||||||
# pylint: disable=too-many-branches |
# pylint: disable=too-many-branches |
||||||
def convert_subdenomination( |
def convert_subdenomination( |
||||||
value: str, sub: str |
value: str, sub: str |
||||||
) -> int: # pylint: disable=too-many-return-statements |
) -> int: # pylint: disable=too-many-return-statements |
||||||
|
|
||||||
# to allow 0.1 ether conversion |
decimal_value = convert_string_to_int(value) |
||||||
if value[0:2] == "0x": |
|
||||||
decimal_value = Fraction(int(value, 16)) |
|
||||||
else: |
|
||||||
decimal_value = Fraction(value) |
|
||||||
if sub == "wei": |
if sub == "wei": |
||||||
return int(decimal_value) |
return decimal_value |
||||||
if sub == "gwei": |
if sub == "gwei": |
||||||
return int(decimal_value * int(1e9)) |
return decimal_value * 1e9 |
||||||
if sub == "szabo": |
if sub == "szabo": |
||||||
return int(decimal_value * int(1e12)) |
return decimal_value * 1e12 |
||||||
if sub == "finney": |
if sub == "finney": |
||||||
return int(decimal_value * int(1e15)) |
return decimal_value * 1e15 |
||||||
if sub == "ether": |
if sub == "ether": |
||||||
return int(decimal_value * int(1e18)) |
return decimal_value * 1e18 |
||||||
if sub == "seconds": |
if sub == "seconds": |
||||||
return int(decimal_value) |
return decimal_value |
||||||
if sub == "minutes": |
if sub == "minutes": |
||||||
return int(decimal_value * 60) |
return decimal_value * 60 |
||||||
if sub == "hours": |
if sub == "hours": |
||||||
return int(decimal_value * 60 * 60) |
return decimal_value * 60 * 60 |
||||||
if sub == "days": |
if sub == "days": |
||||||
return int(decimal_value * 60 * 60 * 24) |
return decimal_value * 60 * 60 * 24 |
||||||
if sub == "weeks": |
if sub == "weeks": |
||||||
return int(decimal_value * 60 * 60 * 24 * 7) |
return decimal_value * 60 * 60 * 24 * 7 |
||||||
if sub == "years": |
if sub == "years": |
||||||
return int(decimal_value * 60 * 60 * 24 * 7 * 365) |
return decimal_value * 60 * 60 * 24 * 7 * 365 |
||||||
|
|
||||||
raise SlitherException(f"Subdemonination conversion impossible {decimal_value} {sub}") |
raise SlitherException(f"Subdemonination conversion impossible {decimal_value} {sub}") |
||||||
|
Loading…
Reference in new issue