Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from ethereum import utils
- def checksum_encode(addr): # Takes a 20-byte binary address as input
- o = ''
- v = utils.big_endian_to_int(utils.sha3(addr.hex()))
- for i, c in enumerate(addr.hex()):
- if c in '0123456789':
- o += c
- else:
- o += c.upper() if (v & (2**(255 - 4*i))) else c.lower()
- return '0x'+o
- def test(addrstr):
- assert(addrstr == checksum_encode(bytes.fromhex(addrstr[2:])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement