Skip to content

Commit

Permalink
Revert another portion of pasta from 49f9620
Browse files Browse the repository at this point in the history
  • Loading branch information
g1itch committed Aug 17, 2021
1 parent 3bd3f8e commit 519bdfe
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions src/addresses.py
@@ -1,8 +1,7 @@
"""
Operations with addresses
"""
# pylint: disable=redefined-outer-name,inconsistent-return-statements
import sys
# pylint: disable=inconsistent-return-statements
import hashlib
import logging
from binascii import hexlify, unhexlify
Expand Down Expand Up @@ -151,30 +150,18 @@ def encodeAddress(version, stream, ripe):
' a given ripe hash was not 20.'
)

if isinstance(ripe, str):
if ripe[:2] == '\x00\x00':
ripe = ripe[2:]
elif ripe[:1] == '\x00':
ripe = ripe[1:]
else:
if ripe[:2] == b'\x00\x00':
ripe = ripe[2:]
elif ripe[:1] == b'\x00':
ripe = ripe[1:]
if ripe[:2] == b'\x00\x00':
ripe = ripe[2:]
elif ripe[:1] == b'\x00':
ripe = ripe[1:]
elif version == 4:
if len(ripe) != 20:
raise Exception(
'Programming error in encodeAddress: The length of'
' a given ripe hash was not 20.')
ripe = ripe.lstrip('\x00')
ripe = ripe.lstrip(b'\x00')

if sys.version_info[0] == 3:
if isinstance(ripe, str):
storedBinaryData = encodeVarint(version) + encodeVarint(stream) + ripe.encode('utf-8')
else:
storedBinaryData = encodeVarint(version) + encodeVarint(stream) + ripe
else:
storedBinaryData = encodeVarint(version) + encodeVarint(stream) + ripe
storedBinaryData = encodeVarint(version) + encodeVarint(stream) + ripe

# Generate the checksum
sha = hashlib.new('sha512')
Expand All @@ -184,7 +171,10 @@ def encodeAddress(version, stream, ripe):
sha.update(currentHash)
checksum = sha.digest()[0:4]

# FIXME: encodeBase58 should take binary data, to reduce conversions
# encodeBase58(storedBinaryData + checksum)
asInt = int(hexlify(storedBinaryData) + hexlify(checksum), 16)
# should it be str? If yes, it should be everywhere in the code
return 'BM-' + encodeBase58(asInt)


Expand Down

0 comments on commit 519bdfe

Please sign in to comment.