Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add eth address helpers #1413

Merged
merged 1 commit into from Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion autobahn/xbr/__init__.py
Expand Up @@ -37,7 +37,7 @@
from autobahn.xbr._abi import XBR_DEBUG_TOKEN_ADDR, XBR_DEBUG_NETWORK_ADDR, XBR_DEBUG_MARKET_ADDR, XBR_DEBUG_CATALOG_ADDR, XBR_DEBUG_CHANNEL_ADDR # noqa
from autobahn.xbr._abi import XBR_DEBUG_TOKEN_ADDR_SRC, XBR_DEBUG_NETWORK_ADDR_SRC, XBR_DEBUG_MARKET_ADDR_SRC, XBR_DEBUG_CATALOG_ADDR_SRC, XBR_DEBUG_CHANNEL_ADDR_SRC # noqa
from autobahn.xbr._interfaces import IMarketMaker, IProvider, IConsumer, ISeller, IBuyer # noqa
from autobahn.xbr._util import make_w3, pack_uint256, unpack_uint256 # noqa
from autobahn.xbr._util import make_w3, pack_uint256, unpack_uint256, with_0x, without_0x # noqa

from autobahn.xbr._eip712_member_register import sign_eip712_member_register, recover_eip712_member_register # noqa
from autobahn.xbr._eip712_member_login import sign_eip712_member_login, recover_eip712_member_login # noqa
Expand Down Expand Up @@ -277,6 +277,8 @@ def account_from_seedphrase(seephrase, index=0):
'make_w3',
'pack_uint256',
'unpack_uint256',
'with_0x',
'without_0x',
'generate_seedphrase',
'check_seedphrase',
'account_from_seedphrase',
Expand Down
12 changes: 12 additions & 0 deletions autobahn/xbr/_util.py
Expand Up @@ -148,3 +148,15 @@ def hlcontract(oid):
if not isinstance(oid, str):
oid = '{}'.format(oid)
return hl('<{}>'.format(oid), color='magenta', bold=True)


def with_0x(address):
if address and not address.startswith('0x'):
return '0x{address}'.format(address=address)
return address


def without_0x(address):
if address and address.startswith('0x'):
return address[2:]
return address