Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 670cdaa

Browse files
vubvub
authored andcommitted
Added normalize address feature
1 parent d740d59 commit 670cdaa

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

ethereum/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ def check_and_strip_checksum(x):
128128
return x[:20]
129129

130130

131+
def normalize_address(x):
132+
if len(x) in (42, 50) and x[:2] == '0x':
133+
x = x[2:]
134+
if len(x) in (40, 48):
135+
x = decode_hex(x)
136+
if len(x) == 24:
137+
assert len(x) == 24 and sha3(x[:20])[:4] == x[-4:]
138+
x = x[:20]
139+
if len(x) != 20:
140+
raise Exception("Invalid address format!")
141+
return x
142+
143+
131144
def zpad(x, l):
132145
return b'\x00' * max(0, l - len(x)) + x
133146

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ def run_tests(self):
5151
install_requires=install_requires,
5252
tests_require=tests_require,
5353
entry_points=dict(console_scripts=console_scripts),
54-
version='1.0.1',
54+
version='1.0.2',
5555
cmdclass=cmdclass
5656
)

0 commit comments

Comments
 (0)