Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_address_details_before(self):
address_details = get_address_details(
address='1HLoD9E4SDFFPDiYfNYnkBLQ85Y51J3Zb1',
coin_symbol='btc',
txn_limit=None,
api_key=BC_API_KEY,
show_confidence=False, # don't return confidence info
# This way the test result never changes:
before_bh=4,
)
# first TX
assert len(address_details['txrefs']) == 1
assert address_details['txrefs'][0]['tx_hash'] == '9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5'
assert address_details['txrefs'][0]['block_height'] == 2
assert address_details['txrefs'][0]['confirmed'] is not None
assert address_details['txrefs'][0]['tx_input_n'] == -1
assert address_details['txrefs'][0]['tx_output_n'] == 0
def test_fetching_unspents(self):
# This address I previously sent funds to but threw out the private key
address_details = get_address_details(
address='C3B3dU12vpCVh2jfmGFdqLe5KWxtZfXW8j',
coin_symbol='bcy',
txn_limit=None,
api_key=BC_API_KEY,
unspent_only=True,
show_confidence=False, # don't return confidence info
# This way the test result never changes:
before_bh=592822,
include_script=True,
)
assert len(address_details['txrefs']) == 1
assert address_details['txrefs'][0]['tx_hash'] == 'b12c4b0ab466c9bbd05da88b3be1a13229c85a6edd2869e01e6a557c8a5cca2b'
assert address_details['txrefs'][0]['block_height'] == 592821
assert address_details['txrefs'][0]['tx_input_n'] == -1
assert address_details['txrefs'][0]['tx_output_n'] == 0
assert address_details['txrefs'][0]['value'] == 1000000
def test_get_address_details_after(self):
address_details = get_address_details(
address='1HLoD9E4SDFFPDiYfNYnkBLQ85Y51J3Zb1',
coin_symbol='btc',
api_key=BC_API_KEY,
show_confidence=False, # don't return confidence info
# Exclude first result
after_bh=4,
txn_limit=1,
)
assert len(address_details['txrefs']) == 1
assert address_details['txrefs'][0]['tx_hash'] != '9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5'
assert address_details['txrefs'][0]['block_height'] != 2
def get_balance_from_blockcypher(address):
""" Check if BTC key being used has enough balance on unspents
"""
data = get_address_details(address, api_key=BLOCKCYPHER_TOKEN)
if 'final_balance' not in data:
return None
btc_amount = satoshis_to_btc(data['final_balance'])
btc_amount = float(btc_amount)
return btc_amount
def dontuseAddress(address):
""" Check if an address should not be used because of:
a) it has unconfirmed TX
b) it has more than maximum registered names (blockstack-server restriction)
"""
if UTXO_PROVIDER == 'blockcypher':
try:
data = get_address_details(address)
except:
return True
try:
unconfirmed_n_tx = data['unconfirmed_n_tx']
except:
return True
if int(unconfirmed_n_tx) == 0:
return False
else:
return True
else:
try:
unspents = get_utxos(address)
except Exception as e: