SHARE
TWEET

Untitled

a guest Jul 19th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from ethereum import utils
  2.  
  3. def checksum_encode(addr): # Takes a 20-byte binary address as input
  4.     o = ''
  5.     v = utils.big_endian_to_int(utils.sha3(addr.hex()))
  6.     for i, c in enumerate(addr.hex()):
  7.         if c in '0123456789':
  8.             o += c
  9.         else:
  10.             o += c.upper() if (v & (2**(255 - 4*i))) else c.lower()
  11.     return '0x'+o
  12.  
  13. def test(addrstr):
  14.     assert(addrstr == checksum_encode(bytes.fromhex(addrstr[2:])))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top