Skip to content

Commit

Permalink
add eth address helpers (#1413)
Browse files Browse the repository at this point in the history
  • Loading branch information
om26er committed Aug 25, 2020
1 parent d75be09 commit 084dc1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit 084dc1a

Please sign in to comment.