Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def display_recent_txs(wallet_obj):
if not USER_ONLINE:
puts(colored.red('BlockCypher connection needed to find transactions related to your addresses.'))
puts(colored.red('You may dump all your addresses while offline by selecting option 0.'))
return
local_tz = get_localzone()
# Show overall balance info
display_balance_info(wallet_obj=wallet_obj)
mpub = wallet_obj.serialize_b58(private=False)
wallet_name = get_blockcypher_walletname_from_mpub(
mpub=mpub,
subchain_indices=[0, 1],
)
wallet_details = get_wallet_transactions(
wallet_name=wallet_name,
api_key=BLOCKCYPHER_API_KEY,
coin_symbol=coin_symbol_from_mkey(mpub),
)
verbose_print(wallet_details)
# TODO: pagination for lots of transactions
txs = wallet_details.get('unconfirmed_txrefs', []) + wallet_details.get('txrefs', [])
if txs:
def display_balance_info(wallet_obj, verbose=False):
if not USER_ONLINE:
return
mpub = wallet_obj.serialize_b58(private=False)
wallet_name = get_blockcypher_walletname_from_mpub(
mpub=mpub,
subchain_indices=[0, 1],
)
verbose_print('Wallet Name: %s' % wallet_name)
verbose_print('API Key: %s' % BLOCKCYPHER_API_KEY)
coin_symbol = coin_symbol_from_mkey(mpub)
wallet_details = get_wallet_balance(
wallet_name=wallet_name,
api_key=BLOCKCYPHER_API_KEY,
coin_symbol=coin_symbol,
)
verbose_print(wallet_details)
def display_balance_info(wallet_obj, verbose=False):
if not USER_ONLINE:
return
mpub = wallet_obj.serialize_b58(private=False)
wallet_name = get_blockcypher_walletname_from_mpub(
mpub=mpub,
subchain_indices=[0, 1],
)
verbose_print('Wallet Name: %s' % wallet_name)
verbose_print('API Key: %s' % BLOCKCYPHER_API_KEY)
coin_symbol = coin_symbol_from_mkey(mpub)
wallet_details = get_wallet_balance(
wallet_name=wallet_name,
api_key=BLOCKCYPHER_API_KEY,
coin_symbol=coin_symbol,
)
verbose_print(wallet_details)
# TODO: confirm it's a pubkey and not a privkey
TXNS_PER_PAGE = 100
# 1 indexed page
current_page = request.GET.get('page')
if current_page:
current_page = int(current_page)
else:
current_page = 1
# transaction pagination: 0-indexed and inclusive
tx_start_num = (current_page - 1) * TXNS_PER_PAGE
tx_end_num = current_page * TXNS_PER_PAGE - 1
wallet_name = get_blockcypher_walletname_from_mpub(mpub=pubkey,
subchain_indices=subchain_indices)
# TODO: could store in DB whether created or not
create_hd_wallet(
wallet_name=wallet_name,
xpubkey=pubkey,
api_key=BLOCKCYPHER_API_KEY,
subchain_indices=subchain_indices,
coin_symbol=coin_symbol,
)
wallet_details = get_wallet_transactions(
wallet_name=wallet_name,
api_key=BLOCKCYPHER_API_KEY,
coin_symbol=coin_symbol,
txn_limit=TXNS_PER_PAGE,
def get_addresses_on_both_chains(wallet_obj, used=None, zero_balance=None):
'''
Get addresses across both subchains based on the filter criteria passed in
Returns a list of dicts of the following form:
[
{'address': '1abc123...', 'path': 'm/0/9', 'pubkeyhex': '0123456...'},
...,
]
Dicts may also contain WIF and privkeyhex if wallet_obj has private key
'''
mpub = wallet_obj.serialize_b58(private=False)
wallet_name = get_blockcypher_walletname_from_mpub(
mpub=mpub,
subchain_indices=[0, 1],
)
wallet_addresses = get_wallet_addresses(
wallet_name=wallet_name,
api_key=BLOCKCYPHER_API_KEY,
used=used,
zero_balance=zero_balance,
coin_symbol=coin_symbol_from_mkey(mpub),
)
verbose_print('wallet_addresses:')
verbose_print(wallet_addresses)
if wallet_obj.private_key:
master_key = wallet_obj.serialize_b58(private=True)
...,
]
'''
verbose_print('register_unused_addresses called on subchain %s for %s addrs' % (
subchain_index,
num_addrs,
))
assert type(subchain_index) is int, subchain_index
assert type(num_addrs) is int, num_addrs
assert num_addrs > 0
mpub = wallet_obj.serialize_b58(private=False)
coin_symbol = coin_symbol_from_mkey(mpub)
wallet_name = get_blockcypher_walletname_from_mpub(
mpub=mpub,
subchain_indices=[0, 1],
)
network = guess_network_from_mkey(mpub)
# register new address(es)
derivation_response = derive_hd_address(
api_key=BLOCKCYPHER_API_KEY,
wallet_name=wallet_name,
num_addresses=num_addrs,
subchain_index=subchain_index,
coin_symbol=coin_symbol,
)
verbose_print('derivation_response:')
verbose_print(derivation_response)
def send_funds(wallet_obj, change_address=None, destination_address=None, dest_satoshis=None, tx_preference=None):
if not USER_ONLINE:
puts(colored.red('BlockCypher connection needed to fetch unspents and broadcast signed transaction.'))
puts(colored.red('You may dump all your addresses and private keys while offline by selecting option 0 on the home screen.'))
return
mpub = wallet_obj.serialize_b58(private=False)
if not wallet_obj.private_key:
print_pubwallet_notice(mpub=mpub)
return
coin_symbol = str(coin_symbol_from_mkey(mpub))
verbose_print(coin_symbol)
wallet_name = get_blockcypher_walletname_from_mpub(
mpub=mpub,
subchain_indices=[0, 1],
)
wallet_details = get_wallet_transactions(
wallet_name=wallet_name,
api_key=BLOCKCYPHER_API_KEY,
coin_symbol=coin_symbol,
)
verbose_print(wallet_details)
if wallet_details['final_balance'] == 0:
puts(colored.red("0 balance. You can't send funds if you don't have them available!"))
return
mpriv = wallet_obj.serialize_b58(private=True)