chainlib/chainlib/eth/runnable/checksum.py

34 lines
627 B
Python
Raw Normal View History

2021-02-08 10:39:42 +01:00
# standard imports
import sys
import select
2021-02-08 10:39:42 +01:00
2021-04-14 14:45:37 +02:00
# external imports
from hexathon import strip_0x
2021-02-08 10:39:42 +01:00
# local imports
2021-04-08 17:39:32 +02:00
from chainlib.eth.address import to_checksum_address
2021-02-08 10:39:42 +01:00
v = None
if len(sys.argv) > 1:
v = sys.argv[1]
else:
h = select.select([sys.stdin], [], [], 0)
if len(h[0]) > 0:
v = h[0][0].read()
v = v.rstrip()
if v == None:
sys.stderr.write('input missing\n')
sys.exit(1)
2021-04-14 14:45:37 +02:00
def main():
try:
print(to_checksum_address(strip_0x(v)))
except ValueError as e:
sys.stderr.write('invalid input: {}\n'.format(e))
sys.exit(1)
2021-04-14 14:45:37 +02:00
2021-02-08 10:39:42 +01:00
2021-04-14 14:45:37 +02:00
if __name__ == '__main__':
main()