diff --git a/counterparty-core/counterpartycore/lib/api/queries.py b/counterparty-core/counterpartycore/lib/api/queries.py index 0a6390311..05af2cb7f 100644 --- a/counterparty-core/counterpartycore/lib/api/queries.py +++ b/counterparty-core/counterpartycore/lib/api/queries.py @@ -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) @@ -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 @@ -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, @@ -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,