Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Blockstream by default; check --electrs-url validity #2902

Merged
merged 3 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion counterparty-core/counterpartycore/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`",
},
],
[
Expand Down
7 changes: 6 additions & 1 deletion counterparty-core/counterpartycore/lib/backend/electrs.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 0 additions & 1 deletion counterparty-core/counterpartycore/lib/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions counterparty-core/counterpartycore/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions counterparty-core/counterpartycore/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions counterparty-core/counterpartycore/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
2 changes: 2 additions & 0 deletions release-notes/release-notes-v10.9.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading