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

[v10.4.3] Fixes #2292

Merged
merged 8 commits into from
Oct 3, 2024
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
5,544 changes: 2,959 additions & 2,585 deletions apiary.apib

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion counterparty-core/counterpartycore/lib/api/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def api_root():
"backend_height": BACKEND_HEIGHT,
"counterparty_height": counterparty_height,
"documentation": "https://counterpartycore.docs.apiary.io/",
"blueprint": f"{request.url_root}v2/blueprint",
"routes": f"{request.url_root}v2/routes",
"blueprint": "https://raw.githubusercontent.com/CounterpartyXCP/counterparty-core/refs/heads/master/apiary.apib",
}


Expand Down
2 changes: 2 additions & 0 deletions counterparty-core/counterpartycore/lib/api/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,8 @@ def unpack(db, datahex: str, block_index: int = None):
:param block_index: Block index of the transaction containing this data
"""
data = binascii.unhexlify(datahex)
if data[: len(config.PREFIX)] == config.PREFIX:
data = data[len(config.PREFIX) :]
message_type_id, message = message_type.unpack(data)
block_index = block_index or util.CURRENT_BLOCK_INDEX

Expand Down
83 changes: 79 additions & 4 deletions counterparty-core/counterpartycore/lib/api/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,18 +700,35 @@


def get_all_mempool_events(
db, event_name: str = None, cursor: str = None, limit: int = 100, offset: int = None
db,
event_name: str = None,
addresses: str = None,
cursor: str = None,
limit: int = 100,
offset: int = None,
):
"""
Returns all mempool events
:param str event_name: Comma separated list of events to return
:param str addresses: Comma separated list of addresses to return
:param str cursor: The last event index to return
:param int limit: The maximum number of events to return (e.g. 5)
:param int offset: The number of lines to skip before returning results (overrides the `cursor` parameter)
"""
where = None
where = []
if event_name:
where = [{"event": event} for event in event_name.split(",")]
if addresses:
for address in addresses.split(","):
where = [
{"event": event, "addresses__like": f"%{address}%"}
for event in event_name.split(",")
]
else:
where = [{"event": event} for event in event_name.split(",")]
elif addresses:
for address in addresses.split(","):
where.append({"addresses__like": f"%{address}%"})

select = "tx_hash, event, bindings AS params, timestamp"
return select_rows(
db, "mempool", where=where, last_cursor=cursor, limit=limit, offset=offset, select=select
Expand Down Expand Up @@ -1939,7 +1956,7 @@
db, address: str, named: bool = None, cursor: str = None, limit: int = 100, offset: int = None
):
"""
Returns the valid assets of an issuer
Returns the valid assets issued by an address
:param str address: The issuer to return (e.g. $ADDRESS_1)
:param bool named: Whether to return only named assets (e.g. true)
:param str cursor: The last index of the assets to return
Expand All @@ -1963,6 +1980,64 @@
)


def get_valid_assets_by_owner(

Check warning

Code scanning / pylint

Too many positional arguments (6/5). Warning

Too many positional arguments (6/5).
db, address: str, named: bool = None, cursor: str = None, limit: int = 100, offset: int = None
):
"""
Returns the valid assets owned by an address
:param str address: The owner to return (e.g. $ADDRESS_1)
:param bool named: Whether to return only named assets (e.g. true)
:param str cursor: The last index of the assets to return
:param int limit: The maximum number of assets to return (e.g. 5)
:param int offset: The number of lines to skip before returning results (overrides the `cursor` parameter)
"""
where = {"owner": address}
if named is not None:
if named:
where["asset__notlike"] = "A%"
else:
where["asset__like"] = "A%"

return select_rows(
db,
"assets_info",
where=where,
last_cursor=cursor,
limit=limit,
offset=offset,
)


def get_valid_assets_by_issuer_or_owner(

Check warning

Code scanning / pylint

Too many positional arguments (6/5). Warning

Too many positional arguments (6/5).
db, address: str, named: bool = None, cursor: str = None, limit: int = 100, offset: int = None
):
"""
Returns the valid assets issued or owned by an address
:param str address: The issuer or owner to return (e.g. $ADDRESS_1)
:param bool named: Whether to return only named assets (e.g. true)
:param str cursor: The last index of the assets to return
:param int limit: The maximum number of assets to return (e.g. 5)
:param int offset: The number of lines to skip before returning results (overrides the `cursor` parameter)
"""
where = [{"issuer": address}, {"owner": address}]
if named is not None:
if named:
for p in where:
p["asset__notlike"] = "A%"
else:
for p in where:
p["asset__like"] = "A%"

return select_rows(
db,
"assets_info",
where=where,
last_cursor=cursor,
limit=limit,
offset=offset,
)


def get_dividends(db, cursor: str = None, limit: int = 100, offset: int = None):
"""
Returns all the dividends
Expand Down
4 changes: 3 additions & 1 deletion counterparty-core/counterpartycore/lib/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def get_routes():
"/v2/addresses/<address>/dispenses/receives/<asset>": queries.get_dispenses_by_destination_and_asset,
"/v2/addresses/<address>/sweeps": queries.get_sweeps_by_address,
"/v2/addresses/<address>/issuances": queries.get_issuances_by_address,
"/v2/addresses/<address>/assets": queries.get_valid_assets_by_issuer,
"/v2/addresses/<address>/assets": queries.get_valid_assets_by_issuer_or_owner,
"/v2/addresses/<address>/assets/issued": queries.get_valid_assets_by_issuer,
"/v2/addresses/<address>/assets/owned": queries.get_valid_assets_by_owner,
"/v2/addresses/<address>/transactions": queries.get_transactions_by_address,
"/v2/addresses/<address>/dividends": queries.get_dividends_distributed_by_address,
"/v2/addresses/<address>/orders": queries.get_orders_by_address,
Expand Down
8 changes: 7 additions & 1 deletion counterparty-core/counterpartycore/lib/messages/sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,13 @@ def parse(db, tx, message):
"asset_longname": last_issuance["asset_longname"],
"reset": False,
}
ledger.insert_record(db, "issuances", bindings, "ASSET_TRANSFER")
ledger.insert_record(
db,
"issuances",
bindings,
"ASSET_TRANSFER",
{"asset_events": "transfer"},
)
sweep_pos += 1

bindings = {
Expand Down
Loading
Loading