diff --git a/counterparty-core/counterpartycore/cli.py b/counterparty-core/counterpartycore/cli.py index 1beb2c07e..0327954cc 100755 --- a/counterparty-core/counterpartycore/cli.py +++ b/counterparty-core/counterpartycore/cli.py @@ -363,7 +363,7 @@ def float_range_checker(arg): [ ("--electrs-url",), { - "help": "the URL of the Electrs server", + "help": "the complete URL of the Electrs API, possibly including a specific port, for example: `https://mempool.space/api`", }, ], [ diff --git a/counterparty-core/counterpartycore/lib/backend/electrs.py b/counterparty-core/counterpartycore/lib/backend/electrs.py index 69be0698b..b9072a760 100644 --- a/counterparty-core/counterpartycore/lib/backend/electrs.py +++ b/counterparty-core/counterpartycore/lib/backend/electrs.py @@ -1,15 +1,20 @@ import binascii +import logging import requests from counterpartycore.lib import config, exceptions, script, util +logger = logging.getLogger(config.LOGGER_NAME) + def electr_query(url): if config.ELECTRS_URL is None: raise exceptions.ElectrsError("Electrs server not configured") try: - return requests.get(f"{config.ELECTRS_URL}/{url}", timeout=10).json() + full_url = f"{config.ELECTRS_URL}/{url}" + logger.debug(f"Querying Electrs: {full_url}") + return requests.get(full_url, timeout=10).json() except requests.exceptions.RequestException as e: raise exceptions.ElectrsError(f"Electrs error: {e}") from e diff --git a/counterparty-core/counterpartycore/lib/composer.py b/counterparty-core/counterpartycore/lib/composer.py index d6201f926..e4314781b 100644 --- a/counterparty-core/counterpartycore/lib/composer.py +++ b/counterparty-core/counterpartycore/lib/composer.py @@ -587,7 +587,6 @@ def get_dummy_witness(script_pub_key): elif output_type == "P2TR": witness = [DUMMY_SCHNORR_SIG] if witness is not None: - print("WITNESS", witness) return TxWitnessInput(witness) return None diff --git a/counterparty-core/counterpartycore/lib/config.py b/counterparty-core/counterpartycore/lib/config.py index e58a79940..2d6688d23 100644 --- a/counterparty-core/counterpartycore/lib/config.py +++ b/counterparty-core/counterpartycore/lib/config.py @@ -13,8 +13,8 @@ VERSION_REVISION = int(version[2]) VERSION_PRE_RELEASE = "-".join(VERSION_STRING.split("-")[1:]) -DEFAULT_ELECTRS_URL_MAINNET = "https://api.counterparty.io:3000" -DEFAULT_ELECTRS_URL_TESTNET = "https://api.counterparty.io:13000" +DEFAULT_ELECTRS_URL_MAINNET = "https://blockstream.info/api" +DEFAULT_ELECTRS_URL_TESTNET = "https://blockstream.info/testnet/api" # When updating to a new verion, we are making a rollback if major version changes. # If minor version changes and if needed, we are making a reparse from a given block. diff --git a/counterparty-core/counterpartycore/lib/util.py b/counterparty-core/counterpartycore/lib/util.py index 768536e04..16d700a75 100644 --- a/counterparty-core/counterpartycore/lib/util.py +++ b/counterparty-core/counterpartycore/lib/util.py @@ -12,6 +12,7 @@ import threading import time from operator import itemgetter +from urllib.parse import urlparse import requests from counterparty_rs import utils as pycoin_rs_utils @@ -708,3 +709,11 @@ def get_outputs_count_from_utxos_info(utxos_info): def get_op_return_output_from_utxos_info(utxos_info): _sources, _destination, _outputs_count, op_return_output = parse_utxos_info(utxos_info) return op_return_output + + +def is_url(url): + try: + result = urlparse(url) + return all([result.scheme, result.netloc]) + except ValueError: + return False diff --git a/counterparty-core/counterpartycore/server.py b/counterparty-core/counterpartycore/server.py index 98cbc730e..43ff3430b 100755 --- a/counterparty-core/counterpartycore/server.py +++ b/counterparty-core/counterpartycore/server.py @@ -586,6 +586,8 @@ def initialise_config( config.GUNICORN_WORKERS = gunicorn_workers if electrs_url: + if not util.is_url(electrs_url): + raise ConfigurationError("Invalid Electrs URL") config.ELECTRS_URL = electrs_url else: if config.NETWORK_NAME == "testnet": diff --git a/release-notes/release-notes-v10.9.0.md b/release-notes/release-notes-v10.9.0.md index 028aca54e..13a1f36ea 100644 --- a/release-notes/release-notes-v10.9.0.md +++ b/release-notes/release-notes-v10.9.0.md @@ -62,12 +62,14 @@ - Use `satoshirate_normalized` and `give_quantity_normalized` to calculate `price_normalized` - Add a parameter `utxo_value` to the `attach.compose()` and `move.compose()` functions - Add `source_address` and `destination_address` in `sends` table +- Use by default Blockstream for Electrs API ## CLI - Add `--cache-dir` flag - Add `severity` field to JSON logs for compatibility - Add `--refresh-state-db` and `--rebuild-state-db` flags for `start` command +- Check if `--electrs-url` is a valid url # Credits