Skip to content

Commit

Permalink
Search also by destination in get sends by addresse
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Jan 4, 2025
1 parent 7d48ba5 commit b9cde34
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions counterparty-core/counterpartycore/lib/api/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ def select_rows(
query = f"{query} OFFSET ?"
bindings.append(offset)

print(query, bindings)
with start_sentry_span(op="db.sql.execute", description=query) as sql_span:
sql_span.set_tag("db.system", "sqlite3")
cursor.execute(query, bindings)
Expand Down Expand Up @@ -1178,13 +1179,21 @@ def prepare_sends_where(send_type: SendType, other_conditions=None):
send_type_list = send_type.split(",")
for type_send in send_type_list:
if type_send == "all":
where = [other_conditions] if other_conditions else []
if isinstance(other_conditions, dict):
where = [other_conditions]
elif isinstance(other_conditions, list):
where = other_conditions
break
if type_send in typing.get_args(SendType):
where_send = {"send_type": type_send}
if other_conditions:
where_send.update(other_conditions)
if where_send:
if isinstance(other_conditions, dict):
where_send.update(other_conditions)
where.append(where_send)
elif isinstance(other_conditions, list):
for other_condition in other_conditions:
where.append(other_condition | where_send)
else:
where.append(where_send)
return where

Expand Down Expand Up @@ -2101,7 +2110,7 @@ def get_sends_by_address(
return select_rows(
ledger_db,
"sends",
where=prepare_sends_where(send_type, {"source": address}),
where=prepare_sends_where(send_type, [{"source": address}, {"destination": address}]),
last_cursor=cursor,
limit=limit,
offset=offset,
Expand Down Expand Up @@ -2129,7 +2138,13 @@ def get_sends_by_address_and_asset(
return select_rows(
ledger_db,
"sends",
where=prepare_sends_where(send_type, {"source": address, "asset": asset.upper()}),
where=prepare_sends_where(
send_type,
[
{"source": address, "asset": asset.upper()},
{"destination": address, "asset": asset.upper()},
],
),
last_cursor=cursor,
limit=limit,
offset=offset,
Expand Down

0 comments on commit b9cde34

Please sign in to comment.