checksum.py (694B)
1 # standard imports 2 import sys 3 import select 4 5 # external imports 6 from hexathon import strip_0x 7 8 # local imports 9 from chainlib.eth.address import to_checksum_address 10 from chainlib.eth.cli.arg import stdin_arg 11 12 v = None 13 if len(sys.argv) > 1: 14 v = sys.argv[1] 15 else: 16 #h = select.select([sys.stdin], [], [], 0) 17 #if len(h[0]) > 0: 18 # v = h[0][0].read() 19 # v = v.rstrip() 20 v = stdin_arg() 21 22 if v == None: 23 sys.stderr.write('input missing\n') 24 sys.exit(1) 25 26 def main(): 27 try: 28 print(to_checksum_address(strip_0x(v))) 29 except ValueError as e: 30 sys.stderr.write('invalid input: {}\n'.format(e)) 31 sys.exit(1) 32 33 34 if __name__ == '__main__': 35 main()