Skip to content

Commit

Permalink
Use Blockstream by default; check --electrs-url validity
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Jan 5, 2025
1 parent ec1fddf commit 6fb7efb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
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 API to get address UTXOs and history

## 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 `--electr-urls` is a valid url

# Credits

Expand Down

0 comments on commit 6fb7efb

Please sign in to comment.