From 084dc1ace4ef18f11e7688a9b02b2e84cb221e64 Mon Sep 17 00:00:00 2001 From: Omer Akram Date: Tue, 25 Aug 2020 15:40:17 +0500 Subject: [PATCH] add eth address helpers (#1413) --- autobahn/xbr/__init__.py | 4 +++- autobahn/xbr/_util.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/autobahn/xbr/__init__.py b/autobahn/xbr/__init__.py index bc6499498..9114b9866 100644 --- a/autobahn/xbr/__init__.py +++ b/autobahn/xbr/__init__.py @@ -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 @@ -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', diff --git a/autobahn/xbr/_util.py b/autobahn/xbr/_util.py index 2cc5ae801..3273385c6 100644 --- a/autobahn/xbr/_util.py +++ b/autobahn/xbr/_util.py @@ -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