Skip to content

Commit

Permalink
Switch dependency from bitcoin => cryptos (blockcypher#168)
Browse files Browse the repository at this point in the history
* switch from bitcoin library to cryptos
* update .gitignore to exclude VSCode files
* remove unused imports
* reformat batch imports
* add __all__ to __init__.py
* update version to 1.0.94
* use stdlib binascii module
  • Loading branch information
rdong8 committed Nov 20, 2024
1 parent dac3bc6 commit d494a8e
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 108 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ coverage.xml
*.log
*.pot
.idea/

# IDEs
.vscode/
251 changes: 170 additions & 81 deletions blockcypher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,85 +6,174 @@
"""

# Main methods used
from .api import get_token_info
from .api import get_address_details
from .api import get_addresses_details
from .api import get_address_overview
from .api import get_address_full
from .api import get_transaction_details
from .api import get_transactions_details
from .api import get_block_overview
from .api import get_blocks_overview
from .api import get_block_details
from .api import get_blockchain_overview
from .api import get_blockchain_fee_estimates
from .api import get_blockchain_high_fee
from .api import get_blockchain_medium_fee
from .api import get_blockchain_low_fee
from .api import get_latest_block_height
from .api import get_latest_block_hash
from .api import get_total_balance
from .api import get_unconfirmed_balance
from .api import get_confirmed_balance
from .api import get_num_confirmed_transactions
from .api import get_num_unconfirmed_transactions
from .api import get_total_num_transactions
from .api import generate_new_address
from .api import derive_hd_address
from .api import get_num_confirmations
from .api import get_confidence
from .api import get_miner_preference
from .api import get_receive_count
from .api import get_satoshis_transacted
from .api import get_satoshis_in_fees
from .api import get_merkle_root
from .api import get_bits
from .api import get_nonce
from .api import get_prev_block_hash
from .api import get_block_hash
from .api import get_block_height
from .api import get_broadcast_transactions
from .api import get_broadcast_transaction_hashes
from .api import subscribe_to_address_webhook
from .api import subscribe_to_wallet_webhook
from .api import list_webhooks
from .api import get_webhook_info
from .api import unsubscribe_from_webhook
from .api import pushtx
from .api import decodetx
from .api import get_forwarding_address
from .api import create_forwarding_address
from .api import create_forwarding_address_with_details
from .api import get_forwarding_address_details
from .api import list_forwarding_addresses
from .api import delete_forwarding_address
from .api import send_faucet_coins
from .api import list_wallet_names
from .api import create_wallet_from_address
from .api import create_hd_wallet
from .api import get_wallet_addresses
from .api import get_wallet_balance
from .api import get_wallet_transactions
from .api import get_latest_paths_from_hd_wallet_addresses
from .api import add_address_to_wallet
from .api import remove_address_from_wallet
from .api import delete_wallet
from .api import generate_multisig_address
from .api import create_unsigned_tx
from .api import verify_unsigned_tx
from .api import get_input_addresses
from .api import make_tx_signatures
from .api import broadcast_signed_transaction
from .api import simple_spend
from .api import simple_spend_p2sh
from .api import embed_data
from .api import get_metadata
from .api import put_metadata
from .api import delete_metadata
from .api import (
get_token_info,
get_address_details,
get_addresses_details,
get_address_overview,
get_address_full,
get_transaction_details,
get_transactions_details,
get_block_overview,
get_blocks_overview,
get_block_details,
get_blockchain_overview,
get_blockchain_fee_estimates,
get_blockchain_high_fee,
get_blockchain_medium_fee,
get_blockchain_low_fee,
get_latest_block_height,
get_latest_block_hash,
get_total_balance,
get_unconfirmed_balance,
get_confirmed_balance,
get_num_confirmed_transactions,
get_num_unconfirmed_transactions,
get_total_num_transactions,
generate_new_address,
derive_hd_address,
get_num_confirmations,
get_confidence,
get_miner_preference,
get_receive_count,
get_satoshis_transacted,
get_satoshis_in_fees,
get_merkle_root,
get_bits,
get_nonce,
get_prev_block_hash,
get_block_hash,
get_block_height,
get_broadcast_transactions,
get_broadcast_transaction_hashes,
subscribe_to_address_webhook,
subscribe_to_wallet_webhook,
list_webhooks,
get_webhook_info,
unsubscribe_from_webhook,
pushtx,
decodetx,
get_forwarding_address,
create_forwarding_address,
create_forwarding_address_with_details,
get_forwarding_address_details,
list_forwarding_addresses,
delete_forwarding_address,
send_faucet_coins,
list_wallet_names,
create_wallet_from_address,
create_hd_wallet,
get_wallet_addresses,
get_wallet_balance,
get_wallet_transactions,
get_latest_paths_from_hd_wallet_addresses,
add_address_to_wallet,
remove_address_from_wallet,
delete_wallet,
generate_multisig_address,
create_unsigned_tx,
verify_unsigned_tx,
get_input_addresses,
make_tx_signatures,
broadcast_signed_transaction,
simple_spend,
simple_spend_p2sh,
embed_data,
get_metadata,
put_metadata,
delete_metadata,
)

from .utils import from_base_unit
from .utils import satoshis_to_btc
from .utils import wei_to_ether
from .utils import is_valid_hash
from .utils import is_valid_address
from .utils import is_valid_eth_address
from .utils import (
from_base_unit,
satoshis_to_btc,
wei_to_ether,
is_valid_hash,
is_valid_address,
is_valid_eth_address,
)


__all__ = [
"get_token_info",
"get_address_details",
"get_addresses_details",
"get_address_overview",
"get_address_full",
"get_transaction_details",
"get_transactions_details",
"get_block_overview",
"get_blocks_overview",
"get_block_details",
"get_blockchain_overview",
"get_blockchain_fee_estimates",
"get_blockchain_high_fee",
"get_blockchain_medium_fee",
"get_blockchain_low_fee",
"get_latest_block_height",
"get_latest_block_hash",
"get_total_balance",
"get_unconfirmed_balance",
"get_confirmed_balance",
"get_num_confirmed_transactions",
"get_num_unconfirmed_transactions",
"get_total_num_transactions",
"generate_new_address",
"derive_hd_address",
"get_num_confirmations",
"get_confidence",
"get_miner_preference",
"get_receive_count",
"get_satoshis_transacted",
"get_satoshis_in_fees",
"get_merkle_root",
"get_bits",
"get_nonce",
"get_prev_block_hash",
"get_block_hash",
"get_block_height",
"get_broadcast_transactions",
"get_broadcast_transaction_hashes",
"subscribe_to_address_webhook",
"subscribe_to_wallet_webhook",
"list_webhooks",
"get_webhook_info",
"unsubscribe_from_webhook",
"pushtx",
"decodetx",
"get_forwarding_address",
"create_forwarding_address",
"create_forwarding_address_with_details",
"get_forwarding_address_details",
"list_forwarding_addresses",
"delete_forwarding_address",
"send_faucet_coins",
"list_wallet_names",
"create_wallet_from_address",
"create_hd_wallet",
"get_wallet_addresses",
"get_wallet_balance",
"get_wallet_transactions",
"get_latest_paths_from_hd_wallet_addresses",
"add_address_to_wallet",
"remove_address_from_wallet",
"delete_wallet",
"generate_multisig_address",
"create_unsigned_tx",
"verify_unsigned_tx",
"get_input_addresses",
"make_tx_signatures",
"broadcast_signed_transaction",
"simple_spend",
"simple_spend_p2sh",
"embed_data",
"get_metadata",
"put_metadata",
"delete_metadata",
"from_base_unit",
"satoshis_to_btc",
"wei_to_ether",
"is_valid_hash",
"is_valid_address",
"is_valid_eth_address",
]
43 changes: 22 additions & 21 deletions blockcypher/api.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import os

from bitcoin import ecdsa_raw_sign
from bitcoin import ecdsa_raw_verify
from bitcoin import der_decode_sig
from bitcoin import compress
from bitcoin import privkey_to_pubkey
from bitcoin import pubkey_to_address
from bitcoin import der_encode_sig

from .utils import is_valid_hash
from .utils import is_valid_block_representation
from .utils import is_valid_coin_symbol
from .utils import is_valid_wallet_name
from .utils import is_valid_address_for_coinsymbol
from .utils import coin_symbol_from_mkey
from .utils import double_sha256
from .utils import compress_txn_outputs
from .utils import get_txn_outputs_dict
from .utils import uses_only_hash_chars
from .utils import delegate_task
from cryptos import (
ecdsa_raw_sign,
ecdsa_raw_verify,
der_decode_sig,
compress,
privkey_to_pubkey,
pubkey_to_address,
der_encode_sig,
)

from .utils import (
is_valid_hash,
is_valid_block_representation,
is_valid_coin_symbol,
is_valid_wallet_name,
is_valid_address_for_coinsymbol,
coin_symbol_from_mkey,
double_sha256,
compress_txn_outputs,
get_txn_outputs_dict,
uses_only_hash_chars,
)

from .constants import COIN_SYMBOL_MAPPINGS

Expand Down
4 changes: 3 additions & 1 deletion blockcypher/crypto.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from bitcoin import encode, changebase, binascii, bin_to_b58check
import binascii

from cryptos import bin_to_b58check

import re

Expand Down
5 changes: 2 additions & 3 deletions blockcypher/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import re
from concurrent.futures.thread import ThreadPoolExecutor
from functools import partial
from typing import Callable, Sequence, Tuple, List
from typing import Callable, Tuple, List

from .constants import SHA_COINS, SCRYPT_COINS, ETHASH_COINS, COIN_SYMBOL_SET, COIN_SYMBOL_MAPPINGS, FIRST4_MKEY_CS_MAPPINGS_UPPER, UNIT_CHOICES, UNIT_MAPPINGS
from .crypto import script_to_address

from bitcoin import safe_from_hex, deserialize
from cryptos import safe_from_hex, deserialize

from collections import OrderedDict
from hashlib import sha256
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
setup(name='blockcypher',
long_description=long_description,
long_description_content_type='text/markdown',
version='1.0.93',
version='1.0.94',
description='BlockCypher Python Library',
author='Michael Flaxman',
author_email='[email protected]',
url='https://github.com/blockcypher/blockcypher-python/',
install_requires=[
'requests<3.0.0',
'python-dateutil<3.0.0',
'bitcoin==1.1.39',
'cryptos<3.0.0'
],
packages=['blockcypher'],
include_package_data=True,
Expand Down

0 comments on commit d494a8e

Please sign in to comment.