diff --git a/bcwallet/bc_utils.py b/bcwallet/bc_utils.py index 72d447c..2ab0cfd 100644 --- a/bcwallet/bc_utils.py +++ b/bcwallet/bc_utils.py @@ -20,7 +20,7 @@ def guess_network_from_mkey(mkey): - cs = coin_symbol_from_mkey(mkey) + cs = next(iter(coin_symbol_from_mkey(mkey))) return COIN_SYMBOL_TO_BMERCHANT_NETWORK.get(cs) diff --git a/bcwallet/bcwallet.py b/bcwallet/bcwallet.py index f8b78b2..7737da0 100644 --- a/bcwallet/bcwallet.py +++ b/bcwallet/bcwallet.py @@ -107,7 +107,7 @@ def display_balance_info(wallet_obj, verbose=False): verbose_print('Wallet Name: %s' % wallet_name) verbose_print('API Key: %s' % BLOCKCYPHER_API_KEY) - coin_symbol = coin_symbol_from_mkey(mpub) + coin_symbol = next(iter(coin_symbol_from_mkey(mpub))) wallet_details = get_wallet_balance( wallet_name=wallet_name, @@ -175,7 +175,7 @@ def get_addresses_on_both_chains(wallet_obj, used=None, zero_balance=None): is_hd_wallet=True, used=used, zero_balance=zero_balance, - coin_symbol=coin_symbol_from_mkey(mpub), + coin_symbol=next(iter(coin_symbol_from_mkey(mpub))), ) verbose_print('wallet_addresses:') verbose_print(wallet_addresses) @@ -223,7 +223,7 @@ def register_unused_addresses(wallet_obj, subchain_index, num_addrs=1): assert num_addrs > 0 mpub = wallet_obj.serialize_b58(private=False) - coin_symbol = coin_symbol_from_mkey(mpub) + coin_symbol = next(iter(coin_symbol_from_mkey(mpub))) wallet_name = get_blockcypher_walletname_from_mpub( mpub=mpub, subchain_indices=[0, 1], @@ -341,7 +341,7 @@ def display_recent_txs(wallet_obj): wallet_details = get_wallet_transactions( wallet_name=wallet_name, api_key=BLOCKCYPHER_API_KEY, - coin_symbol=coin_symbol_from_mkey(mpub), + coin_symbol=next(iter(coin_symbol_from_mkey(mpub))), ) verbose_print(wallet_details) @@ -374,7 +374,7 @@ def display_recent_txs(wallet_obj): input_quantity=net_satoshis_tx, input_type='satoshi', output_type=UNIT_CHOICE, - coin_symbol=coin_symbol_from_mkey(mpub), + coin_symbol=next(iter(coin_symbol_from_mkey(mpub))), print_cs=True, ), 'received' if net_satoshis_tx > 0 else 'sent', @@ -926,7 +926,7 @@ def dump_all_keys_or_addrs(wallet_obj): address=child_wallet.to_address(), path=path, wif=wif_to_use, - coin_symbol=coin_symbol_from_mkey(mpub), + coin_symbol=next(iter(coin_symbol_from_mkey(mpub))), ) puts(colored.blue('\nYou can compare this output to bip32.org')) @@ -943,7 +943,6 @@ def dump_selected_keys_or_addrs(wallet_obj, used=None, zero_balance=None): if not USER_ONLINE: puts(colored.red('\nInternet connection required, would you like to dump *all* %s instead?' % ( - content_str, content_str, ))) if confirm(user_prompt=DEFAULT_PROMPT, default=True): @@ -982,7 +981,7 @@ def dump_selected_keys_or_addrs(wallet_obj, used=None, zero_balance=None): address=address_obj['pub_address'], wif=address_obj.get('wif'), path=address_obj['path'], - coin_symbol=coin_symbol_from_mkey(mpub), + coin_symbol=next(iter(coin_symbol_from_mkey(mpub))), ) addr_cnt += 1 @@ -1099,7 +1098,7 @@ def wallet_home(wallet_obj): else: print_bcwallet_basic_pub_opening(mpub=mpub) - coin_symbol = coin_symbol_from_mkey(mpub) + coin_symbol = next(iter(coin_symbol_from_mkey(mpub))) if USER_ONLINE: wallet_name = get_blockcypher_walletname_from_mpub( mpub=mpub, @@ -1121,7 +1120,6 @@ def wallet_home(wallet_obj): # Go to home screen while True: puts('-' * 70 + '\n') - if coin_symbol in ('bcy', 'btc-testnet'): display_shortname = COIN_SYMBOL_MAPPINGS[coin_symbol]['display_shortname'] if coin_symbol == 'bcy': @@ -1313,16 +1311,6 @@ def cli(): def invoke_cli(): - if sys.version_info[0] != 2 or sys.version_info[1] != 7: - puts(colored.red('Sorry, this app must be run with python 2.7')) - puts(colored.red('Your version: %s' % sys.version)) - if sys.version_info[0] == 3: - puts(colored.red('Please uninstall bcwallet and reinstall like this:\n')) - with indent(4): - puts(colored.magenta('$ pip2 install bcwallet\n')) - - sys.exit() - # Check if blockcypher is up (basically if the user's machine is online) global USER_ONLINE if is_connected_to_blockcypher(): @@ -1377,6 +1365,7 @@ def invoke_cli(): print_keys_not_saved() sys.exit() + if __name__ == '__main__': ''' For invocation like this (not tested): diff --git a/bcwallet/cl_utils.py b/bcwallet/cl_utils.py index 16f5ee2..b502a70 100644 --- a/bcwallet/cl_utils.py +++ b/bcwallet/cl_utils.py @@ -14,6 +14,7 @@ from bitmerchant.wallet.keys import PrivateKey +from builtins import input from datetime import datetime import json @@ -62,7 +63,7 @@ def choice_prompt(user_prompt=DEFAULT_PROMPT, acceptable_responses=[], else: prompt_to_use = '%s: ' % user_prompt - user_input = raw_input(prompt_to_use).strip().strip('"') + user_input = input(prompt_to_use).strip().strip('"') if not user_input and default_input in acceptable_responses: return default_input @@ -96,7 +97,7 @@ def get_crypto_qty(max_num, input_type, user_prompt=DEFAULT_PROMPT, else: prompt_to_use = '%s: ' % user_prompt - user_input = raw_input(prompt_to_use).strip().strip('"') + user_input = input(prompt_to_use).strip().strip('"') if default_input and not user_input: return int(default_input) @@ -159,7 +160,7 @@ def get_int(max_int, min_int=1, user_prompt=DEFAULT_PROMPT, default_input=None, else: prompt_to_use = '%s: ' % user_prompt - user_input = raw_input(prompt_to_use).strip().strip('"') + user_input = input(prompt_to_use).strip().strip('"') if default_input and not user_input: return int(default_input) @@ -205,7 +206,7 @@ def get_int(max_int, min_int=1, user_prompt=DEFAULT_PROMPT, default_input=None, def get_crypto_address(coin_symbol, user_prompt=DEFAULT_PROMPT, quit_ok=False): display_shortname = COIN_SYMBOL_MAPPINGS[coin_symbol]['display_shortname'] - destination_address = raw_input('%s: ' % user_prompt).strip().strip('"') + destination_address = input('%s: ' % user_prompt).strip().strip('"') if not destination_address: err_str = 'No entry, please enter something' @@ -235,7 +236,7 @@ def get_crypto_address(coin_symbol, user_prompt=DEFAULT_PROMPT, quit_ok=False): def get_wif_obj(network, user_prompt=DEFAULT_PROMPT, quit_ok=False): - user_input = raw_input('%s: ' % user_prompt).strip().strip('"') + user_input = input('%s: ' % user_prompt).strip().strip('"') if quit_ok and user_input in ['q', 'Q', 'b', 'B']: return False @@ -306,7 +307,7 @@ def confirm(user_prompt=DEFAULT_PROMPT, default=None): prompt_to_use = user_prompt + ': ' else: raise Exception('Bad Default Value: %s' % default) - user_input = raw_input(prompt_to_use).strip() + user_input = input(prompt_to_use).strip() if not user_input: return default elif user_input.lower() == 'y': @@ -321,14 +322,14 @@ def confirm(user_prompt=DEFAULT_PROMPT, default=None): def get_public_wallet_url(mpub): # subchain indices set at 0 * 1 return 'https://live.blockcypher.com/%s/xpub/%s/?subchain-indices=0-1' % ( - coin_symbol_from_mkey(mpub), + next(iter(coin_symbol_from_mkey(mpub))), mpub, ) # TODO: move to blockcypher python library def first4mprv_from_mpub(mpub): - coin_symbol = coin_symbol_from_mkey(mkey=mpub) + coin_symbol = next(iter(coin_symbol_from_mkey(mpub))) return COIN_SYMBOL_MAPPINGS[coin_symbol]['first4_mprv'] @@ -362,9 +363,9 @@ def print_bcwallet_piped_priv_cat_opening(): def print_childprivkey_warning(): - puts("\nNOTE:") - puts("Do not reveal your private keys to anyone!") - puts("One quirk of HD wallets is that if an attacker learns any of your non-hardened child private keys as well as your master public key then the attacker can derive all of your private keys and steal all of your funds.""") + puts("\nNOTE:") + puts("Do not reveal your private keys to anyone!") + puts("One quirk of HD wallets is that if an attacker learns any of your non-hardened child private keys as well as your master public key then the attacker can derive all of your private keys and steal all of your funds.""") def print_traversal_warning(): diff --git a/bcwallet/version_checker.py b/bcwallet/version_checker.py index 4288a67..c7b72b8 100644 --- a/bcwallet/version_checker.py +++ b/bcwallet/version_checker.py @@ -9,6 +9,6 @@ def get_latest_bcwallet_version(): r = requests.get(VERSION_URL) assert r.status_code == 200, 'Could Not Connect to GitHub (status code %s)' % r.status_code - matches = re.findall("version='(.*?)\'", r.content) + matches = re.findall("version='(.*?)\'", r.content.decode('utf-8')) assert matches, 'bcwallet version not found on github' return matches[0] diff --git a/setup.py b/setup.py index b433d3e..adc941b 100644 --- a/setup.py +++ b/setup.py @@ -10,10 +10,11 @@ author_email='mflaxman+blockcypher@gmail.com', url='https://github.com/blockcypher/bcwallet/', py_modules=['bcwallet'], + use_2to3=True, install_requires=[ - 'python>=2.7,<3', 'clint==0.4.1', - 'blockcypher==1.0.69', + 'future==0.18.2', + 'blockcypher==1.0.81', 'bitmerchant==0.1.8', 'tzlocal==1.2', ],